diff options
| author | Bobby <[email protected]> | 2025-08-29 11:18:42 +0530 |
|---|---|---|
| committer | Bobby <[email protected]> | 2025-08-29 11:18:42 +0530 |
| commit | 835f8a3c3d3d83e6b0ad545f58ef2eb62b5366dc (patch) | |
| tree | acd469c952033333be5cf6580ac055039786b980 /authentication | |
| parent | 42cf32ac95205ac8eb8cb14bed72f969b6e12101 (diff) | |
| download | thatcomputerscientist-835f8a3c3d3d83e6b0ad545f58ef2eb62b5366dc.tar.xz thatcomputerscientist-835f8a3c3d3d83e6b0ad545f58ef2eb62b5366dc.zip | |
migrate auth to authentication; fix asgi and settings
Diffstat (limited to 'authentication')
| -rw-r--r-- | authentication/__init__.py | 0 | ||||
| -rw-r--r-- | authentication/admin.py | 3 | ||||
| -rw-r--r-- | authentication/apps.py | 6 | ||||
| -rw-r--r-- | authentication/migrations/__init__.py | 0 | ||||
| -rw-r--r-- | authentication/models.py | 3 | ||||
| -rw-r--r-- | authentication/tests.py | 3 | ||||
| -rw-r--r-- | authentication/urls.py | 8 | ||||
| -rw-r--r-- | authentication/views.py | 34 |
8 files changed, 57 insertions, 0 deletions
diff --git a/authentication/__init__.py b/authentication/__init__.py new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/authentication/__init__.py diff --git a/authentication/admin.py b/authentication/admin.py new file mode 100644 index 00000000..8c38f3f3 --- /dev/null +++ b/authentication/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/authentication/apps.py b/authentication/apps.py new file mode 100644 index 00000000..c65f1d28 --- /dev/null +++ b/authentication/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class AuthenticationConfig(AppConfig): + default_auto_field = "django.db.models.BigAutoField" + name = "authentication" diff --git a/authentication/migrations/__init__.py b/authentication/migrations/__init__.py new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/authentication/migrations/__init__.py diff --git a/authentication/models.py b/authentication/models.py new file mode 100644 index 00000000..71a83623 --- /dev/null +++ b/authentication/models.py @@ -0,0 +1,3 @@ +from django.db import models + +# Create your models here. diff --git a/authentication/tests.py b/authentication/tests.py new file mode 100644 index 00000000..7ce503c2 --- /dev/null +++ b/authentication/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/authentication/urls.py b/authentication/urls.py new file mode 100644 index 00000000..d49f2956 --- /dev/null +++ b/authentication/urls.py @@ -0,0 +1,8 @@ +from django.urls import path +from . import views + +app_name = "authentication" +urlpatterns = [ + path("/login", views.login, name="login"), + path("/logout", views.logout, name="logout"), +] diff --git a/authentication/views.py b/authentication/views.py new file mode 100644 index 00000000..9921b17e --- /dev/null +++ b/authentication/views.py @@ -0,0 +1,34 @@ +from django.contrib import messages +from django.contrib.auth import authenticate, login as auth_login, logout as auth_logout +from django.shortcuts import redirect +from users.functions import email_verified + +def login(request): + next = request.POST.get("next", "core:home").strip() + username = request.POST.get("username") + password = request.POST.get("password") + + print("Next:", next) + print("Username:", username) + print("Password:", password) + if username == "" or password == "" or username is None or password is None: + messages.error(request, "ErrorEmptyFields", extra_tags="LoginError") + return redirect(f"{next}?username={username}" if username else next) + else: + user = authenticate(request, username=username, password=password) + if user is not None: + if email_verified(user): + auth_login(request, user) + return redirect(next) + else: + messages.error(request, "ErrorEmailNotVerified", extra_tags="LoginError") + return redirect(f"{next}?username={username}") + else: + messages.error(request, "ErrorInvalidCredentials", extra_tags="LoginError") + return redirect(f"{next}?username={username}") + + +def logout(request): + auth_logout(request) + referer = request.META.get('HTTP_REFERER', '/') + return redirect(referer) |
