Skip to content

Commit

Permalink
Merge pull request #187 from juvenn/feat/signup-sms
Browse files Browse the repository at this point in the history
支持手机验证码注册或登录
  • Loading branch information
juvenn authored Jun 24, 2019
2 parents e269ef0 + cc82134 commit 8a091d2
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ php:
- 7.2

env:
- LEANCLOUD_API_SERVER="https://us-api.leancloud.cn" LEANCLOUD_APP_ID=wnDg0lPt0wcYGJSiHRwHBhD4 LEANCLOUD_APP_KEY=u9ekx9HFSFFBErWwyWHFmPDy LEANCLOUD_REGION=US LEANCLOUD_APP_HOST="127.0.0.1" LEANCLOUD_APP_PORT=8081 LEANCLOUD_WILDCARD_DOMAIN="lncldglobal.com"
- LEANCLOUD_API_SERVER="https://us.avoscloud.com" LEANCLOUD_APP_ID=wnDg0lPt0wcYGJSiHRwHBhD4 LEANCLOUD_APP_KEY=u9ekx9HFSFFBErWwyWHFmPDy LEANCLOUD_REGION=US LEANCLOUD_APP_HOST="127.0.0.1" LEANCLOUD_APP_PORT=8081 LEANCLOUD_WILDCARD_DOMAIN="lncldglobal.com"

install:
- composer install
Expand Down
6 changes: 6 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@

0.10.0 发布日期:2019-06-24
----

- 添加 `User::signUpOrLoginByMobilePhone` 支持手机注册或登录

0.9.0 发布日期:2019-05-23
----

Expand Down
2 changes: 1 addition & 1 deletion src/LeanCloud/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class Client {
/**
* Client version
*/
const VERSION = '0.9.0';
const VERSION = '0.10.0';

/**
* API Version string
Expand Down
16 changes: 15 additions & 1 deletion src/LeanCloud/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,21 @@ public static function verifyMobilePhone($smsCode) {
Client::post("/verifyMobilePhone/{$smsCode}", null);
}


/**
* Sign up user by mobile phone and SMS code
*
* @param string $phoneNumber
* @param string $smsCode
*/
public static function signUpOrLoginByMobilePhone($phoneNumber, $smsCode) {
$resp = Client::post("/usersByMobilePhone", array(
"mobilePhoneNumber" => $phoneNumber,
"smsCode" => $smsCode
));
$user = new static();
$user->mergeAfterFetch($data);
User::saveCurrentUser($user);
}

/*
* Link and unlink with 3rd party auth provider
Expand Down
6 changes: 6 additions & 0 deletions test/UserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,12 @@ public function testVerifyMobilePhone() {
User::verifyMobilePhone("000000");
}

public function testSignUpOrLoginByMobilePhone() {
// Ensure the post format is correct
$this->setExpectedException("LeanCloud\CloudException", null, 603);
User::signUpOrLoginByMobilePhone("18612340000", "000000");
}

public function testLogInWithLinkedService() {
$user = User::logIn("alice", "blabla");

Expand Down

0 comments on commit 8a091d2

Please sign in to comment.