This commit is contained in:
jar3b 2018-07-06 19:07:40 +03:00
parent 9463ef75e9
commit bb69819278

View File

@ -1,4 +1,5 @@
from django.contrib.auth import get_user_model from django.contrib.auth import get_user_model
from django.core.exceptions import FieldError, ValidationError
from rest_framework import exceptions from rest_framework import exceptions
from rest_framework.authentication import BaseAuthentication from rest_framework.authentication import BaseAuthentication
@ -20,9 +21,13 @@ class UuidAuthentication(BaseAuthentication):
User = get_user_model() User = get_user_model()
try: try:
user = User.object.get(uuid=payload) user = User.objects.get(uid=payload)
except User.DoesNotExist: except User.DoesNotExist:
raise exceptions.AuthenticationFailed("Invalid user id") raise exceptions.AuthenticationFailed("Invalid user id")
except FieldError:
raise exceptions.AuthenticationFailed("Incorrect user model")
except ValidationError:
raise exceptions.AuthenticationFailed("Incorrect user id")
if not user.is_active: if not user.is_active:
raise exceptions.AuthenticationFailed("User isn't active") raise exceptions.AuthenticationFailed("User isn't active")