bugfix error 500 in user not exist
This commit is contained in:
parent
3ee2f1936a
commit
e586183ac7
1 changed files with 14 additions and 23 deletions
|
|
@ -9,35 +9,26 @@ USER_MODEL = get_user_model()
|
||||||
|
|
||||||
|
|
||||||
class MultiGatewayOAuth2Validator(OAuth2Validator): # pylint: disable=w0223
|
class MultiGatewayOAuth2Validator(OAuth2Validator): # pylint: disable=w0223
|
||||||
""" Primarily extend the functionality of token generation """
|
|
||||||
|
|
||||||
def validate_user(self, username, password, client, request, *args, **kwargs):
|
def validate_user(self, username, password, client, request, *args, **kwargs):
|
||||||
""" Here, you would be able to access the MOBILE/ OTP fields
|
|
||||||
which you will be sending in the request.post body. """
|
|
||||||
# otp = request.otp
|
|
||||||
# mobile = request.mobile
|
|
||||||
# user = AppropriateModel.objects.get(otp=otp, mobile=mobile)
|
|
||||||
auth_fields = getattr(request, 'auth_fields', 'username:password').split(':')
|
auth_fields = getattr(request, 'auth_fields', 'username:password').split(':')
|
||||||
user_field = auth_fields[0]
|
|
||||||
pass_field = auth_fields[1]
|
|
||||||
|
|
||||||
user = None
|
if len(auth_fields) != 2:
|
||||||
if user_field == 'phone_number':
|
return False
|
||||||
user = USER_MODEL.objects.get(
|
|
||||||
phone_number=username
|
|
||||||
)
|
|
||||||
|
|
||||||
elif user_field == 'username':
|
user_field, pass_field = auth_fields
|
||||||
user = USER_MODEL.objects.get(
|
|
||||||
username=username
|
|
||||||
)
|
|
||||||
|
|
||||||
elif user_field == 'email':
|
if user_field not in ['phone_number', 'username', 'email']:
|
||||||
user = USER_MODEL.objects.get(
|
return False
|
||||||
email=username
|
|
||||||
)
|
|
||||||
|
|
||||||
if user is None:
|
if pass_field not in ['password', 'otp']:
|
||||||
|
return False
|
||||||
|
|
||||||
|
if not username or not password:
|
||||||
|
return False
|
||||||
|
|
||||||
|
user = USER_MODEL.objects.filter(**{user_field:username}).first()
|
||||||
|
|
||||||
|
if not user:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if not user.check_auth(pass_field, password):
|
if not user.check_auth(pass_field, password):
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue