feat: initial commit - Band Management application

This commit is contained in:
2026-01-06 03:11:46 +01:00
commit 34e12e00b3
24543 changed files with 3991790 additions and 0 deletions

View File

@@ -0,0 +1,50 @@
from django.shortcuts import redirect
from django.contrib.auth import authenticate, login
from django.contrib.auth.models import User
from django.contrib import messages
from auth.views import AuthView
class LoginView(AuthView):
def get(self, request):
if request.user.is_authenticated:
# If the user is already logged in, redirect them to the home page or another appropriate page.
return redirect("index") # Replace 'index' with the actual URL name for the home page
# Render the login page for users who are not logged in.
return super().get(request)
def post(self, request):
if request.method == "POST":
username = request.POST.get("email-username")
password = request.POST.get("password")
if not (username and password):
messages.error(request, "Please enter your username and password.")
return redirect("login")
if "@" in username:
user_email = User.objects.filter(email=username).first()
if user_email is None:
messages.error(request, "Please enter a valid email.")
return redirect("login")
username = user_email.username
user_email = User.objects.filter(username=username).first()
if user_email is None:
messages.error(request, "Please enter a valid username.")
return redirect("login")
authenticated_user = authenticate(request, username=username, password=password)
if authenticated_user is not None:
# Login the user if authentication is successful
login(request, authenticated_user)
# Redirect to the page the user was trying to access before logging in
if "next" in request.POST:
return redirect(request.POST["next"])
else: # Redirect to the home page or another appropriate page
return redirect("index")
else:
messages.error(request, "Please enter a valid username.")
return redirect("login")