updated apps.lyric.views for simpler login authentication and error messaging; .tests.test_views have new test method to assert either authentication condition has properly occurred

This commit is contained in:
Disco DeDisco
2026-01-30 21:51:06 -05:00
parent ae63861adb
commit 9c102ac0f5
2 changed files with 14 additions and 7 deletions

View File

@@ -1,10 +1,8 @@
from django.contrib import auth, messages
from django.core.exceptions import ValidationError
from django.core.mail import send_mail
from django.shortcuts import redirect
from django.urls import reverse
from .models import Token, User
from ..dashboard.forms import ItemForm
from .models import Token
def send_login_email(request):
email = request.POST["email"]
@@ -27,12 +25,10 @@ def send_login_email(request):
def login(request):
uid = request.GET.get("token")
if not uid:
return redirect("/")
user = auth.authenticate(request, uid=uid)
if user is not None:
user.backend = "apps.lyric.authentication.PasswordlessAuthenticationBackend"
auth.login(request, user)
else:
messages.error(request, "Invalid login link!—please request a new one")
return redirect("/")