Skip to content

Commit

Permalink
Merge pull request #555 from leancloud/fix/verify-sms
Browse files Browse the repository at this point in the history
fix: require phone_number when verify sms code
  • Loading branch information
juvenn authored Apr 7, 2024
2 parents 82f48c5 + 26b302b commit 483e3b3
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 8 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/pythonpackage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jobs:
strategy:
max-parallel: 1
matrix:
python-version: [2.7, 3.5, 3.6, 3.7, 3.8, 3.9]
python-version: [3.6, 3.9]
steps:
- uses: actions/checkout@v2
- name: Set up Python
Expand All @@ -57,7 +57,7 @@ jobs:
pip install -e .'[test]'
- name: Run tests with ${{ matrix.python-version }}
env:
APP_ID: YJRGphy60b8JCBib0vtDDtak-MdYXbMMI
APP_ID: u5xB92MjVH94kH6p3M66DUua-MdYXbMMI
APP_KEY: ${{ secrets.APP_KEY }}
MASTER_KEY: ${{ secrets.MASTER_KEY }}
USE_REGION: US
Expand Down
9 changes: 5 additions & 4 deletions leancloud/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,8 +335,8 @@ def request_password_reset_by_sms_code(cls, phone_number, validate_token=None):
client.post("/requestPasswordResetBySmsCode", params)

@classmethod
def reset_password_by_sms_code(cls, sms_code, new_password):
params = {"password": new_password}
def reset_password_by_sms_code(cls, sms_code, new_password, phone_number):
params = {"password": new_password, "mobilePhoneNumber": phone_number}
client.put("/resetPasswordBySmsCode/" + sms_code, params)

# This should be an instance method.
Expand All @@ -359,8 +359,9 @@ def change_phone_number(cls, sms_code, phone_number):
client.post("/changePhoneNumber", params)

@classmethod
def verify_mobile_phone_number(cls, sms_code):
client.post("/verifyMobilePhone/" + sms_code, {})
def verify_mobile_phone_number(cls, sms_code, phone_number):
params = {"mobilePhoneNumber": phone_number}
client.post("/verifyMobilePhone/" + sms_code, params)

@classmethod
def request_login_sms_code(cls, phone_number, validate_token=None):
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ iso8601>=0.1.14
six>=1.11.0
qiniu>=7.3.1
requests>=2.25.1
urllib3<2
Werkzeug>=0.16.0,<2.0.0
secure-cookie>=0.1.0,<1.0.0
gevent>=22.10.2,<23.0.0
Expand Down
4 changes: 4 additions & 0 deletions tests/test_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,10 @@ def test_request_sms_code(): # type: () -> None
pass
elif e.code == 601 or e.error.startswith("SMS request too fast"): # send sms too frequently
pass
elif "SMS sending exceeds limit" in e.error:
pass
elif "send too frequently" in e.error:
pass
else:
raise e

Expand Down
12 changes: 10 additions & 2 deletions tests/test_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,13 @@ def test_request_change_phone_number(): # type: () -> None
# phone number is from http://www.z-sms.com
User.request_change_phone_number("+8617180655340")
except LeanCloudError as e:
if e.code not in (119, 213, 601, 605):
if e.code in (119, 213, 601, 605):
pass
elif "SMS sending exceeds limit" in e.error:
pass
elif "send too frequently" in e.error:
pass
else:
raise e
finally:
user1.logout()
Expand Down Expand Up @@ -322,7 +328,9 @@ def test_request_password_reset_by_sms_code(): # type: () -> None
def test_reset_password_by_sms_code(): # type: () -> None
try:
User.reset_password_by_sms_code(
str(random.randrange(100000, 999999)), "password"
str(random.randrange(100000, 999999)),
"password",
"1861111" + str(random.randrange(1000, 9999))
)
except LeanCloudError as e:
if e.code != 603:
Expand Down

0 comments on commit 483e3b3

Please sign in to comment.