From 7d57c90342728600bae451b3f053222bf30cad0d Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 14 Oct 2024 17:28:50 +0000 Subject: [PATCH] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- .../FaceRecoginitionProject/asgi.py | 3 +- .../FaceRecoginitionProject/settings.py | 7 ++- .../FaceRecoginitionProject/urls.py | 7 ++- .../FaceRecoginitionProject/wsgi.py | 3 +- FaceRecoginitionProject/manage.py | 3 +- user_authentication/forms.py | 4 +- user_authentication/models.py | 8 ++-- user_authentication/urls.py | 9 ++-- user_authentication/views.py | 45 +++++++++++-------- 9 files changed, 51 insertions(+), 38 deletions(-) diff --git a/FaceRecoginitionProject/FaceRecoginitionProject/asgi.py b/FaceRecoginitionProject/FaceRecoginitionProject/asgi.py index 080aaf1..083e633 100644 --- a/FaceRecoginitionProject/FaceRecoginitionProject/asgi.py +++ b/FaceRecoginitionProject/FaceRecoginitionProject/asgi.py @@ -11,6 +11,7 @@ from django.core.asgi import get_asgi_application -os.environ.setdefault("DJANGO_SETTINGS_MODULE", "FaceRecoginitionProject.settings") +os.environ.setdefault("DJANGO_SETTINGS_MODULE", + "FaceRecoginitionProject.settings") application = get_asgi_application() diff --git a/FaceRecoginitionProject/FaceRecoginitionProject/settings.py b/FaceRecoginitionProject/FaceRecoginitionProject/settings.py index b5f1c6b..e0de0de 100644 --- a/FaceRecoginitionProject/FaceRecoginitionProject/settings.py +++ b/FaceRecoginitionProject/FaceRecoginitionProject/settings.py @@ -10,15 +10,14 @@ https://docs.djangoproject.com/en/5.1/ref/settings/ """ +from pathlib import Path INSTALLED_APPS = [ # other apps - 'authentication', + "authentication", ] -AUTH_USER_MODEL = 'authentication.CustomUser' - +AUTH_USER_MODEL = "authentication.CustomUser" -from pathlib import Path # Build paths inside the project like this: BASE_DIR / 'subdir'. BASE_DIR = Path(__file__).resolve().parent.parent diff --git a/FaceRecoginitionProject/FaceRecoginitionProject/urls.py b/FaceRecoginitionProject/FaceRecoginitionProject/urls.py index 961df3a..83f9b7b 100644 --- a/FaceRecoginitionProject/FaceRecoginitionProject/urls.py +++ b/FaceRecoginitionProject/FaceRecoginitionProject/urls.py @@ -15,6 +15,7 @@ 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) """ +from django.urls import include, path from django.contrib import admin from django.urls import path @@ -22,10 +23,8 @@ path("admin/", admin.site.urls), ] -from django.urls import path, include urlpatterns = [ - path('authentication/', include('authentication.urls')), - path('', home_view, name='home'), + path("authentication/", include("authentication.urls")), + path("", home_view, name="home"), ] - diff --git a/FaceRecoginitionProject/FaceRecoginitionProject/wsgi.py b/FaceRecoginitionProject/FaceRecoginitionProject/wsgi.py index 5a6ac88..11cbf0c 100644 --- a/FaceRecoginitionProject/FaceRecoginitionProject/wsgi.py +++ b/FaceRecoginitionProject/FaceRecoginitionProject/wsgi.py @@ -11,6 +11,7 @@ from django.core.wsgi import get_wsgi_application -os.environ.setdefault("DJANGO_SETTINGS_MODULE", "FaceRecoginitionProject.settings") +os.environ.setdefault("DJANGO_SETTINGS_MODULE", + "FaceRecoginitionProject.settings") application = get_wsgi_application() diff --git a/FaceRecoginitionProject/manage.py b/FaceRecoginitionProject/manage.py index 7436055..a02a0a0 100755 --- a/FaceRecoginitionProject/manage.py +++ b/FaceRecoginitionProject/manage.py @@ -6,7 +6,8 @@ def main(): """Run administrative tasks.""" - os.environ.setdefault("DJANGO_SETTINGS_MODULE", "FaceRecoginitionProject.settings") + os.environ.setdefault("DJANGO_SETTINGS_MODULE", + "FaceRecoginitionProject.settings") try: from django.core.management import execute_from_command_line except ImportError as exc: diff --git a/user_authentication/forms.py b/user_authentication/forms.py index 44c3c13..3e94218 100644 --- a/user_authentication/forms.py +++ b/user_authentication/forms.py @@ -1,9 +1,11 @@ from django import forms from django.contrib.auth.forms import UserCreationForm + from .models import CustomUser + # Form for user registration class CustomUserCreationForm(UserCreationForm): class Meta(UserCreationForm.Meta): model = CustomUser - fields = UserCreationForm.Meta.fields + ('role',) # Add role field + fields = UserCreationForm.Meta.fields + ("role",) # Add role field diff --git a/user_authentication/models.py b/user_authentication/models.py index 13a5076..a615845 100644 --- a/user_authentication/models.py +++ b/user_authentication/models.py @@ -3,13 +3,15 @@ # Choices for roles ROLE_CHOICES = ( - ('admin', 'Admin'), - ('user', 'User'), + ("admin", "Admin"), + ("user", "User"), ) + # Custom user model with roles class CustomUser(AbstractUser): - role = models.CharField(max_length=10, choices=ROLE_CHOICES, default='user') + role = models.CharField( + max_length=10, choices=ROLE_CHOICES, default="user") def __str__(self): return self.username diff --git a/user_authentication/urls.py b/user_authentication/urls.py index 074933c..a0435ef 100644 --- a/user_authentication/urls.py +++ b/user_authentication/urls.py @@ -1,8 +1,9 @@ from django.urls import path -from .views import register, user_login, profile + +from .views import profile, register, user_login urlpatterns = [ - path('register/', register, name='register'), - path('login/', user_login, name='login'), - path('profile/', profile, name='profile'), + path("register/", register, name="register"), + path("login/", user_login, name="login"), + path("profile/", profile, name="profile"), ] diff --git a/user_authentication/views.py b/user_authentication/views.py index 3b2968a..85836f2 100644 --- a/user_authentication/views.py +++ b/user_authentication/views.py @@ -1,45 +1,52 @@ +from .forms import CustomUserCreationForm, LoginForm +from django.shortcuts import redirect, render +from django.contrib.auth.decorators import login_required +from django.contrib.auth import authenticate, login, logout from django.contrib.auth.decorators import user_passes_test -def is_admin(user): - return user.role == 'admin' -@user_passes_test(is_admin) -def admin_dashboard(request): - return render(request, 'authentication/admin_dashboard.html') +def is_admin(user): + return user.role == "admin" -from django.shortcuts import render, redirect -from django.contrib.auth import login, authenticate, logout -from django.contrib.auth.decorators import login_required -from .forms import CustomUserCreationForm, LoginForm +@user_passes_test(is_admin) +def admin_dashboard(request): + return render(request, "authentication/admin_dashboard.html") + def register(request): - if request.method == 'POST': + if request.method == "POST": form = CustomUserCreationForm(request.POST) if form.is_valid(): user = form.save() login(request, user) - return redirect('home') + return redirect("home") else: form = CustomUserCreationForm() - return render(request, 'authentication/register.html', {'form': form}) + return render(request, "authentication/register.html", {"form": form}) + def user_login(request): - if request.method == 'POST': + if request.method == "POST": form = LoginForm(request.POST) if form.is_valid(): - username = form.cleaned_data.get('username') - password = form.cleaned_data.get('password') + username = form.cleaned_data.get("username") + password = form.cleaned_data.get("password") user = authenticate(request, username=username, password=password) if user is not None: login(request, user) - return redirect('home') + return redirect("home") else: - return render(request, 'authentication/login.html', {'error': 'Invalid credentials'}) + return render( + request, + "authentication/login.html", + {"error": "Invalid credentials"}, + ) else: form = LoginForm() - return render(request, 'authentication/login.html', {'form': form}) + return render(request, "authentication/login.html", {"form": form}) + @login_required def profile(request): - return render(request, 'authentication/profile.html', {'user': request.user}) + return render(request, "authentication/profile.html", {"user": request.user})