Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: require phone number when verify sms code #556

Closed
wants to merge 13 commits into from
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
Loading