Skip to content

Commit

Permalink
fix: 解决手机号加密导致忘记密码判断总是失败问题
Browse files Browse the repository at this point in the history
  • Loading branch information
O-Jiangweidong authored and BaiJiangJie committed Jan 8, 2024
1 parent 496b72a commit 630bb56
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions apps/authentication/api/password.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,13 @@ class UserResetPasswordSendCodeApi(CreateAPIView):
serializer_class = ResetPasswordCodeSerializer

@staticmethod
def is_valid_user(**kwargs):
user = get_object_or_none(User, **kwargs)
if not user:
def is_valid_user(username, **attr_query):
user = get_object_or_none(User, username=username)
valid = True
for attr, value in attr_query.items():
if getattr(user, attr, None) != value:
valid = False
if not valid:
err_msg = _('User does not exist: {}').format(_("No user matched"))
return None, err_msg
if not user.is_local:
Expand All @@ -56,7 +60,6 @@ def prepare_code_data(self, user_info, serializer):
target = serializer.validated_data[form_type]
if form_type == 'sms':
query_key = 'phone'
target = target.lstrip('+')
else:
query_key = form_type
user, err = self.is_valid_user(username=username, **{query_key: target})
Expand Down

0 comments on commit 630bb56

Please sign in to comment.