user auth_field instead of gateway
This commit is contained in:
parent
3d90035338
commit
9b4aaec9af
5 changed files with 16 additions and 16 deletions
|
|
@ -151,12 +151,12 @@ class User(AbstractUser):
|
|||
self.save()
|
||||
return result
|
||||
|
||||
def check_auth(self, gateway, value):
|
||||
def check_auth(self, field, value):
|
||||
result = False
|
||||
if gateway == 'otp':
|
||||
if field == 'otp':
|
||||
result = self.check_otp(value)
|
||||
|
||||
elif gateway == 'password':
|
||||
elif field == 'password':
|
||||
result = self.check_password(value)
|
||||
|
||||
if result:
|
||||
|
|
|
|||
|
|
@ -78,5 +78,5 @@ class RequestOTPSerializer(serializers.ModelSerializer):
|
|||
|
||||
class ChangePasswordSerializer(serializers.Serializer):
|
||||
old_password = serializers.CharField(required=True)
|
||||
old_password_gateway = serializers.CharField(default='password')
|
||||
old_password_field = serializers.CharField(default='password')
|
||||
new_password = serializers.CharField(required=True)
|
||||
|
|
|
|||
|
|
@ -64,10 +64,10 @@ class ChangePasswordView(generics.UpdateAPIView):
|
|||
serializer = self.get_serializer(data=request.data)
|
||||
|
||||
if serializer.is_valid():
|
||||
gateway = serializer.data.get("old_password_gateway")
|
||||
pass_field = serializer.data.get("old_password_field")
|
||||
old_password = serializer.data.get("old_password")
|
||||
new_password = serializer.data.get("new_password")
|
||||
if not self.object.check_auth(gateway, old_password):
|
||||
if not self.object.check_auth(pass_field, old_password):
|
||||
return Response({"old_password": ["Wrong password/otp."]}, status=status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
self.object.set_password(new_password)
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ class ApiClient():
|
|||
"username": phone_number,
|
||||
"password": password,
|
||||
"scope": 'read write groups introspection',
|
||||
"auth_gateway": 'phone_number:otp'
|
||||
"auth_fields": 'phone_number:otp'
|
||||
}
|
||||
auth = (OAUTH_CLIENT_ID, OAUTH_CLIENT_SECRET)
|
||||
|
||||
|
|
@ -101,11 +101,11 @@ class ApiClient():
|
|||
result = self._request(path=path, data=data, method='put', files=files, encode=encode)
|
||||
return result
|
||||
|
||||
def change_password(self, old_password, new_password, old_password_gateway='otp'):
|
||||
def change_password(self, old_password, new_password, old_password_field='otp'):
|
||||
path = 'change_password/'
|
||||
data = {'old_password': old_password,
|
||||
'new_password': new_password,
|
||||
'old_password_gateway': old_password_gateway
|
||||
'old_password_field': old_password_field
|
||||
}
|
||||
|
||||
result = self._request(path=path, data=data, method='put')
|
||||
|
|
|
|||
|
|
@ -14,22 +14,22 @@ class MultiGatewayOAuth2Validator(OAuth2Validator): # pylint: disable=w0223
|
|||
# otp = request.otp
|
||||
# mobile = request.mobile
|
||||
# user = AppropriateModel.objects.get(otp=otp, mobile=mobile)
|
||||
auth_gateway = getattr(request, 'auth_gateway', 'username:password').split(':')
|
||||
user_gateway = auth_gateway[0]
|
||||
pass_gateway = auth_gateway[1]
|
||||
auth_fields = getattr(request, 'auth_fields', 'username:password').split(':')
|
||||
user_field = auth_fields[0]
|
||||
pass_field = auth_fields[1]
|
||||
|
||||
user = None
|
||||
if user_gateway == 'phone_number':
|
||||
if user_field == 'phone_number':
|
||||
user = USER_MODEL.objects.get(
|
||||
phone_number=username
|
||||
)
|
||||
|
||||
elif auth_gateway == 'username':
|
||||
elif user_field == 'username':
|
||||
user = USER_MODEL.objects.get(
|
||||
username=username
|
||||
)
|
||||
|
||||
elif user_gateway == 'email':
|
||||
elif user_field == 'email':
|
||||
user = USER_MODEL.objects.get(
|
||||
email=username
|
||||
)
|
||||
|
|
@ -37,7 +37,7 @@ class MultiGatewayOAuth2Validator(OAuth2Validator): # pylint: disable=w0223
|
|||
if user is None:
|
||||
return False
|
||||
|
||||
if not user.check_auth(pass_gateway, password):
|
||||
if not user.check_auth(pass_field, password):
|
||||
return False
|
||||
|
||||
if user.is_active:
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue