Files
python-tdd/src/apps/lyric/authentication.py

17 lines
519 B
Python
Raw Normal View History

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)