diff --git a/backend/apps/authentication/serializers.py b/backend/apps/authentication/serializers.py new file mode 100644 index 0000000..1e05aec --- /dev/null +++ b/backend/apps/authentication/serializers.py @@ -0,0 +1,29 @@ +from rest_framework import serializers +from django.contrib.auth.models import User + + +class RegisterSerializer(serializers.ModelSerializer): + username = serializers.CharField(validators=[]) + password = serializers.CharField(write_only=True) + + class Meta: + model = User + fields = ["username", "email", "password"] + + def validate_username(self, value): + if not all(char.isalnum() or char == "_" for char in value): + raise serializers.ValidationError( + "Username should contain only alpha,numerics and underscore" + ) + + if User.objects.filter(username=value).exists(): + raise serializers.ValidationError("Username already exists") + return value + + def create(self, validated_data): + user = User.objects.create_user( + username=validated_data["username"], + email=validated_data["email"], + password=validated_data["password"], + ) + return user diff --git a/backend/apps/authentication/urls.py b/backend/apps/authentication/urls.py index e69de29..9493e7e 100644 --- a/backend/apps/authentication/urls.py +++ b/backend/apps/authentication/urls.py @@ -0,0 +1,6 @@ +from django.urls import path +from . import views + +urlpatterns = [ + path("register/", views.RegisterationView.as_view(), name="register"), +] diff --git a/backend/apps/authentication/views.py b/backend/apps/authentication/views.py index e69de29..83a9ba8 100644 --- a/backend/apps/authentication/views.py +++ b/backend/apps/authentication/views.py @@ -0,0 +1,8 @@ +from rest_framework import generics +from django.contrib.auth.models import User +from .serializers import RegisterSerializer + + +class RegisterationView(generics.CreateAPIView): + queryset = User.objects.all() + serializer_class = RegisterSerializer diff --git a/backend/config/__pycache__/__init__.cpython-312.pyc b/backend/config/__pycache__/__init__.cpython-312.pyc deleted file mode 100644 index 1153bc8..0000000 Binary files a/backend/config/__pycache__/__init__.cpython-312.pyc and /dev/null differ diff --git a/backend/config/__pycache__/settings.cpython-312.pyc b/backend/config/__pycache__/settings.cpython-312.pyc deleted file mode 100644 index e0e49c1..0000000 Binary files a/backend/config/__pycache__/settings.cpython-312.pyc and /dev/null differ diff --git a/backend/config/settings.py b/backend/config/settings.py index 3a6af5a..d24a4f2 100644 --- a/backend/config/settings.py +++ b/backend/config/settings.py @@ -11,7 +11,7 @@ """ from pathlib import Path -from os import os +import os # Build paths inside the project like this: BASE_DIR / 'subdir'. BASE_DIR = Path(__file__).resolve().parent.parent @@ -38,11 +38,8 @@ "django.contrib.sessions", "django.contrib.messages", "django.contrib.staticfiles", + "rest_framework", "apps.authentication", - "apps.catalog", - "apps.orders", - "apps.profiles", - "apps.sellers", ] MIDDLEWARE = [ diff --git a/backend/config/urls.py b/backend/config/urls.py index 5f2fa71..7222372 100644 --- a/backend/config/urls.py +++ b/backend/config/urls.py @@ -20,9 +20,9 @@ urlpatterns = [ path("admin/", admin.site.urls), - path("authentication/", include("apps.authentication.urls")), - path("catalog/", include("apps.catalog.urls")), - path("order/", include("apps.orders.urls")), - path("profile/", include("apps.profiles.urls")), - path("seller/", include("apps.sellers.urls")), + path("api/auth/", include("apps.authentication.urls")), + # path("catalog/", include("apps.catalog.urls")), + # path("order/", include("apps.orders.urls")), + # path("profile/", include("apps.profiles.urls")), + # path("seller/", include("apps.sellers.urls")), ] diff --git a/backend/docker-compose.yml b/backend/docker-compose.yml new file mode 100644 index 0000000..63a9e82 --- /dev/null +++ b/backend/docker-compose.yml @@ -0,0 +1,9 @@ +services: + db: + image: postgres:16 + environment: + POSTGRES_DB: fashio + POSTGRES_USER: postgres + POSTGRES_PASSWORD: postgres + ports: + - "5432:5432" \ No newline at end of file