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:
16
src/apps/lyric/authentication.py
Normal file
16
src/apps/lyric/authentication.py
Normal 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)
|
||||
Reference in New Issue
Block a user