Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions backend/apps/authentication/serializers.py
Original file line number Diff line number Diff line change
@@ -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
6 changes: 6 additions & 0 deletions backend/apps/authentication/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.urls import path
from . import views

urlpatterns = [
path("register/", views.RegisterationView.as_view(), name="register"),
]
8 changes: 8 additions & 0 deletions backend/apps/authentication/views.py
Original file line number Diff line number Diff line change
@@ -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
Binary file removed backend/config/__pycache__/__init__.cpython-312.pyc
Binary file not shown.
Binary file removed backend/config/__pycache__/settings.cpython-312.pyc
Binary file not shown.
7 changes: 2 additions & 5 deletions backend/config/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 = [
Expand Down
10 changes: 5 additions & 5 deletions backend/config/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")),
]
9 changes: 9 additions & 0 deletions backend/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
services:
db:
image: postgres:16
environment:
POSTGRES_DB: fashio
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
ports:
- "5432:5432"
Loading