From 630bb56601316547998b33476ea4be10389434be Mon Sep 17 00:00:00 2001 From: jiangweidong Date: Mon, 8 Jan 2024 17:16:26 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=A7=A3=E5=86=B3=E6=89=8B=E6=9C=BA?= =?UTF-8?q?=E5=8F=B7=E5=8A=A0=E5=AF=86=E5=AF=BC=E8=87=B4=E5=BF=98=E8=AE=B0?= =?UTF-8?q?=E5=AF=86=E7=A0=81=E5=88=A4=E6=96=AD=E6=80=BB=E6=98=AF=E5=A4=B1?= =?UTF-8?q?=E8=B4=A5=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/authentication/api/password.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/apps/authentication/api/password.py b/apps/authentication/api/password.py index cc1e6aff7..280e088ed 100644 --- a/apps/authentication/api/password.py +++ b/apps/authentication/api/password.py @@ -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: @@ -56,7 +60,6 @@ class UserResetPasswordSendCodeApi(CreateAPIView): 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})