diff --git a/accounts/__init__.py b/accounts/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/accounts/admin.py b/accounts/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/accounts/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/accounts/apps.py b/accounts/apps.py new file mode 100644 index 0000000..3e3c765 --- /dev/null +++ b/accounts/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class AccountsConfig(AppConfig): + default_auto_field = 'django.db.models.BigAutoField' + name = 'accounts' diff --git a/accounts/migrations/__init__.py b/accounts/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/accounts/models.py b/accounts/models.py new file mode 100644 index 0000000..71a8362 --- /dev/null +++ b/accounts/models.py @@ -0,0 +1,3 @@ +from django.db import models + +# Create your models here. diff --git a/accounts/tests.py b/accounts/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/accounts/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/accounts/urls.py b/accounts/urls.py new file mode 100644 index 0000000..b129cbd --- /dev/null +++ b/accounts/urls.py @@ -0,0 +1,8 @@ + from django.urls import path +from .views import UserRegistrationView, UserLoginView, UserLogoutView + +urlpatterns = [ + path('api/login/', UserLoginView.as_view(), name='login'), + path('api/logout/', UserLogoutView.as_view(), name='logout'), + path('api/register/', UserRegistrationView.as_view(), name='welcome'), +] \ No newline at end of file diff --git a/accounts/views.py b/accounts/views.py new file mode 100644 index 0000000..e0c219e --- /dev/null +++ b/accounts/views.py @@ -0,0 +1,31 @@ +# main/views.py +from django.shortcuts import render, redirect, get_object_or_404 +from django.contrib.auth import authenticate, login, logout +from rest_framework import status +from rest_framework.views import APIView +from rest_framework.response import Response + + +class UserRegistrationView(APIView): + def post(self, request): + serializer = UserRegistrationSerializer(data=request.data) + if serializer.is_valid(): + user = serializer.save() + return Response({"id": user.id, "username": user.username}, status=status.HTTP_201_CREATED) + return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) + +class UserLoginView(APIView): + def post(self, request): + username = request.data.get('username') + password = request.data.get('password') + user = authenticate(request, username=username, password=password) + if user is not None: + login(request, user) + return Response({"message": "Login successful"}, status=status.HTTP_200_OK) + return Response({error: "Invalid credentials"}, status=status.HTTP_401_UNAUTHORIZED) + +class UserLogoutView(APIView): + def post(self, request): + logout(request) + return Response({"message": "Logout successful"}, status=status.HTTP_200_OK) + diff --git a/main/urls.py b/main/urls.py index 3ad739d..c72fccc 100644 --- a/main/urls.py +++ b/main/urls.py @@ -10,9 +10,6 @@ router.register(r'tasks', TaskViewSet) urlpatterns = [ path('api/', include(router.urls)), - path('login/', UserLoginView.as_view(), name='login'), - path('logout/', UserLogoutView.as_view(), name='logout'), - path('register/', UserRegistrationView.as_view(), name='welcome'), path('projects/create/', create_project, name='create_project'), path('projects//', project_dashboard, name='project_dashboard'), path('projects//tasks/create/', create_task, name='create_task'), diff --git a/main/views.py b/main/views.py index 44fc2e5..c9988c3 100644 --- a/main/views.py +++ b/main/views.py @@ -1,36 +1,10 @@ # main/views.py from django.shortcuts import render, redirect, get_object_or_404 -from django.contrib.auth import authenticate, login, logout from django.contrib.auth.decorators import login_required from .models import Project, Task, RegisteredUser from .forms import ProjectForm, TaskForm -from rest_framework import status -from rest_framework.views import APIView -from rest_framework.response import Response -class UserRegistrationView(APIView): - def post(self, request): - serializer = UserRegistrationSerializer(data=request.data) - if serializer.is_valid(): - user = serializer.save() - return Response({"id": user.id, "username": user.username}, status=status.HTTP_201_CREATED) - return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) - -class UserLoginView(APIView): - def post(self, request): - username = request.data.get('username') - password = request.data.get('password') - user = authenticate(request, username=username, password=password) - if user is not None: - login(request, user) - return Response({"message": "Login successful"}, status=status.HTTP_200_OK) - return Response({error: "Invalid credentials"}, status=status.HTTP_401_UNAUTHORIZED) - -class UserLogoutView(APIView): - def post(self, request): - logout(request) - return Response({"message": "Logout successful"}, status=status.HTTP_200_OK) # create project @login_required diff --git a/project_management/settings.py b/project_management/settings.py index 45afdf0..a8ad052 100644 --- a/project_management/settings.py +++ b/project_management/settings.py @@ -40,6 +40,7 @@ INSTALLED_APPS = [ 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', + 'accounts', 'main', ]