new apps.lyric.authenticate model PasswordlessAuthenticationBackend and authenticate() function help determine Token authenticity, login to existing accounts, or create new ones; associated .tests.test_authentication class asserts this functionality; apps.lyric.models & .tests.models now handles token uid instead of id, completing the transition away from email-as-pk

This commit is contained in:
Disco DeDisco
2026-01-30 19:10:17 -05:00
parent 2d61506a6d
commit 41f4ff1725
4 changed files with 66 additions and 4 deletions

View File

@@ -0,0 +1,16 @@
from django.core.exceptions import ValidationError
from .models import Token, User
class PasswordlessAuthenticationBackend:
def authenticate(self, request, uid=None):
if uid is None:
return None
try:
token = Token.objects.get(uid=uid)
except (Token.DoesNotExist, ValidationError):
return None
try:
return User.objects.get(email=token.email)
except User.DoesNotExist:
return User.objects.create(email=token.email)