Login: use only the username (not email) for login.
We may add support for email in the future.
This commit is contained in:
parent
6051a5ae3a
commit
215a260700
@ -381,13 +381,7 @@ class AuthenticationSignupSerializer(serializers.Serializer):
|
|||||||
|
|
||||||
|
|
||||||
class AuthenticationLoginChallengeSerializer(serializers.Serializer):
|
class AuthenticationLoginChallengeSerializer(serializers.Serializer):
|
||||||
username = serializers.CharField(required=False)
|
username = serializers.CharField(required=True)
|
||||||
email = serializers.EmailField(required=False)
|
|
||||||
|
|
||||||
def validate(self, data):
|
|
||||||
if not data.get('email') and not data.get('username'):
|
|
||||||
raise serializers.ValidationError('Either email or username must be set')
|
|
||||||
return data
|
|
||||||
|
|
||||||
def create(self, validated_data):
|
def create(self, validated_data):
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
@ -579,17 +579,9 @@ class AuthenticationViewSet(viewsets.ViewSet):
|
|||||||
data = self.login_response_data(user)
|
data = self.login_response_data(user)
|
||||||
return Response(data, status=status.HTTP_201_CREATED)
|
return Response(data, status=status.HTTP_201_CREATED)
|
||||||
|
|
||||||
def get_login_user(self, serializer):
|
def get_login_user(self, username):
|
||||||
username = serializer.validated_data.get('username')
|
kwargs = {User.USERNAME_FIELD: username}
|
||||||
email = serializer.validated_data.get('email')
|
return get_object_or_404(self.get_queryset(), **kwargs)
|
||||||
if username:
|
|
||||||
kwargs = {User.USERNAME_FIELD: username}
|
|
||||||
user = get_object_or_404(self.get_queryset(), **kwargs)
|
|
||||||
elif email:
|
|
||||||
kwargs = {User.EMAIL_FIELD: email}
|
|
||||||
user = get_object_or_404(self.get_queryset(), **kwargs)
|
|
||||||
|
|
||||||
return user
|
|
||||||
|
|
||||||
@action_decorator(detail=False, methods=['POST'])
|
@action_decorator(detail=False, methods=['POST'])
|
||||||
def login_challenge(self, request):
|
def login_challenge(self, request):
|
||||||
@ -597,7 +589,8 @@ class AuthenticationViewSet(viewsets.ViewSet):
|
|||||||
|
|
||||||
serializer = AuthenticationLoginChallengeSerializer(data=request.data)
|
serializer = AuthenticationLoginChallengeSerializer(data=request.data)
|
||||||
if serializer.is_valid():
|
if serializer.is_valid():
|
||||||
user = self.get_login_user(serializer)
|
username = serializer.validated_data.get('username')
|
||||||
|
user = self.get_login_user(username)
|
||||||
|
|
||||||
salt = bytes(user.userinfo.salt)
|
salt = bytes(user.userinfo.salt)
|
||||||
enc_key = self.get_encryption_key(salt)
|
enc_key = self.get_encryption_key(salt)
|
||||||
@ -631,7 +624,8 @@ class AuthenticationViewSet(viewsets.ViewSet):
|
|||||||
|
|
||||||
serializer = AuthenticationLoginInnerSerializer(data=response, context={'host': request.get_host()})
|
serializer = AuthenticationLoginInnerSerializer(data=response, context={'host': request.get_host()})
|
||||||
if serializer.is_valid():
|
if serializer.is_valid():
|
||||||
user = self.get_login_user(serializer)
|
username = serializer.validated_data.get('username')
|
||||||
|
user = self.get_login_user(username)
|
||||||
host = serializer.validated_data['host']
|
host = serializer.validated_data['host']
|
||||||
challenge = serializer.validated_data['challenge']
|
challenge = serializer.validated_data['challenge']
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user