-
Notifications
You must be signed in to change notification settings - Fork 0
update user model and registration url #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| FROM python:3.7-stretch | ||
| RUN apt-get update | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| RUN apt-get upgrade -y | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's better not to upgrade distribution |
||
| COPY ./ / | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider adding ENV DEBIAN_FRONTEND=noninteractive
# Keeps Python from generating .pyc files in the container
ENV PYTHONDONTWRITEBYTECODE 1
# Prevents Python from buffering stdout and stderr
ENV PYTHONUNBUFFERED 1 |
||
| WORKDIR ./ | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Specify workdir explicitly |
||
| RUN pip3 install --no-cache-dir -r requirements.txt && \ | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use specific pip version |
||
| rm -v requirements.txt | ||
| EXPOSE 8000 | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider adding: COPY scripts/entrypoint.sh /app/scripts/entrypoint.sh
ENTRYPOINT ["./scripts/entrypoint.sh"] |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,8 @@ | ||
|
|
||
| up: | ||
| @docker-compose -f docker/docker-compose.yml up -d | ||
| @docker-compose build | ||
| @docker-compose up -d | ||
| @docker ps | ||
|
|
||
| down: | ||
| @docker-compose -f docker/docker-compose.yml down | ||
| @docker-compose down |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,14 @@ | ||
| version: "3" | ||
| services: | ||
| app: | ||
| container_name: app | ||
| build: . | ||
| command: bash -c "python manage.py makemigrations && python manage.py migrate && python manage.py runserver 0.0.0.0:8000" | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you have more than 1 command it's better to have them in |
||
| ports: | ||
| - "8552:8000" | ||
| depends_on: | ||
| - db | ||
|
|
||
| db: | ||
| image: "postgres:12" | ||
| environment: | ||
|
|
@@ -11,6 +20,5 @@ services: | |
| ports: | ||
| - "5432:5432" | ||
|
|
||
|
|
||
| volumes: | ||
| redit_volume: | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1 @@ | ||
| from django.contrib import admin | ||
|
|
||
| # Register your models here. |
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,9 @@ | ||
| from django.db import models | ||
| from users.models import User | ||
|
|
||
|
|
||
| class Post(models.Model): | ||
| text = models.TextField() | ||
| created_at = models.DateTimeField(auto_now_add=True) | ||
| approved = models.BooleanField(default=False) | ||
| user = models.ForeignKey(User, on_delete=models.CASCADE) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -45,6 +45,7 @@ | |
|
|
||
| APPS = [ | ||
| 'posts', | ||
| 'users', | ||
| ] | ||
|
|
||
| INSTALLED_APPS = CORE_APPS + THIRD_PARTY_APPS + APPS | ||
|
|
@@ -91,7 +92,7 @@ | |
| 'NAME': 'redit_db', | ||
| 'USER': 'user', | ||
| 'PASSWORD': 'password', | ||
| 'HOST': '127.0.0.1', | ||
| 'HOST': 'db', | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This all should be read from env vars |
||
| 'PORT': '5432', | ||
| } | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| from django.contrib import admin |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| from django.apps import AppConfig | ||
|
|
||
|
|
||
| class UsersConfig(AppConfig): | ||
| name = 'users' |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| from django.db import models | ||
| from django.core import validators | ||
| from django.contrib.auth.models import AbstractBaseUser, UserManager | ||
|
|
||
|
|
||
| class User(AbstractBaseUser): | ||
|
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no need in empty line here. Consider adding linting and type checking configs in |
||
| username = models.CharField(db_index=True, max_length=255, unique=True) | ||
| email = models.EmailField(validators=[validators.validate_email], unique=True, blank=False) | ||
| is_staff = models.BooleanField(default=False) # a admin user; non super-user | ||
| is_superuser = models.BooleanField(default=False) # a superuser | ||
| USERNAME_FIELD = 'email' | ||
| REQUIRED_FIELDS = ('username',) | ||
|
|
||
| objects = UserManager() | ||
|
|
||
| def __str__(self): | ||
| return self.username | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. consider adding more unique fields to identify user. Are you sure this works? I guess it should be smth like |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| from rest_framework import serializers | ||
| from .models import User | ||
|
|
||
|
|
||
| class RegistrationSerializer(serializers.ModelSerializer): | ||
|
|
||
| password = serializers.CharField( | ||
| max_length=128, | ||
| min_length=8, | ||
| write_only=True, | ||
| ) | ||
|
|
||
| class Meta: | ||
| model = User | ||
| fields = ('email', 'username', 'password') | ||
|
|
||
| def create(self, validated_data): | ||
| return User.objects.create_user(**validated_data) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| from django.urls import re_path | ||
|
|
||
| from .views import RegistrationAPIView | ||
| # from .views import LoginAPIView | ||
| from django.urls import path | ||
|
|
||
| urlpatterns = [ | ||
| path("registration", RegistrationAPIView.as_view(), name='user_registration'), | ||
| ] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| from rest_framework import status | ||
| # from rest_framework.permissions import AllowAny | ||
| from rest_framework.response import Response | ||
| from rest_framework.views import APIView | ||
|
|
||
| # from .models import User | ||
| # from .serializers import LoginSerializer | ||
| from .serializers import RegistrationSerializer | ||
|
|
||
|
|
||
| class RegistrationAPIView(APIView): | ||
|
|
||
| serializer_class = RegistrationSerializer | ||
|
|
||
| def post(self, request): | ||
|
|
||
| serializer = self.serializer_class(data=request.data) | ||
| serializer.is_valid(raise_exception=True) | ||
| serializer.save() | ||
|
|
||
| return Response( | ||
| status=status.HTTP_201_CREATED, | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. consider responding with user_id and maybe even all her data |
||
| ) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
consider using more fresh python