Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Oct 14, 2024
1 parent b3b24b3 commit 7d57c90
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 38 deletions.
3 changes: 2 additions & 1 deletion FaceRecoginitionProject/FaceRecoginitionProject/asgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
7 changes: 3 additions & 4 deletions FaceRecoginitionProject/FaceRecoginitionProject/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 3 additions & 4 deletions FaceRecoginitionProject/FaceRecoginitionProject/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,16 @@
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

urlpatterns = [
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"),
]

3 changes: 2 additions & 1 deletion FaceRecoginitionProject/FaceRecoginitionProject/wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
3 changes: 2 additions & 1 deletion FaceRecoginitionProject/manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 3 additions & 1 deletion user_authentication/forms.py
Original file line number Diff line number Diff line change
@@ -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
8 changes: 5 additions & 3 deletions user_authentication/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
9 changes: 5 additions & 4 deletions user_authentication/urls.py
Original file line number Diff line number Diff line change
@@ -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"),
]
45 changes: 26 additions & 19 deletions user_authentication/views.py
Original file line number Diff line number Diff line change
@@ -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})

0 comments on commit 7d57c90

Please sign in to comment.