Skip to content

Commit

Permalink
Merge branch 'v0.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
juvenn committed Feb 1, 2016
2 parents 16f3681 + 4b64b8c commit c19424d
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 1 deletion.
5 changes: 5 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@

0.2.5 发布日期:2016-02-01
----
* 支持手机号码和密码登录
* 修复查询 `_User` 未传递 sessionToken 导致查询失败

0.2.4 发布日期:2016-01-26
----

Expand Down
7 changes: 6 additions & 1 deletion src/LeanCloud/LeanClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use LeanCloud\LeanObject;
use LeanCloud\LeanACL;
use LeanCloud\LeanFile;
use LeanCloud\LeanUser;
use LeanCloud\Operation\IOperation;
use LeanCloud\Storage\IStorage;
use LeanCloud\Storage\SessionStorage;
Expand All @@ -22,7 +23,7 @@ class LeanClient {
/**
* Client version
*/
const VERSION = '0.2.4';
const VERSION = '0.2.5';

/**
* API Endpoints for Regions
Expand Down Expand Up @@ -227,6 +228,10 @@ public static function buildHeaders($sessionToken, $useMasterKey) {
$h['X-LC-Sign'] .= ",master";
}

if (!$sessionToken) {
$sessionToken = LeanUser::getCurrentSessionToken();
}

if ($sessionToken) {
$h['X-LC-Session'] = $sessionToken;
}
Expand Down
17 changes: 17 additions & 0 deletions src/LeanCloud/LeanUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,23 @@ public static function logOut() {
}
}

/**
* Log-in user by mobile phone and password
*
* @param string $phoneNumber
* @param string $password
* @return LeanUser
*/
public static function logInWithMobilePhoneNumber($phoneNumber, $password) {
$params = array("mobilePhoneNumber" => $phoneNumber,
"password" => $password);
$resp = LeanClient::post("/login", $params);
$user = new static();
$user->mergeAfterFetch($resp);
static::saveCurrentUser($user);
return $user;
}

/**
* Log-in user by mobile phone and SMS code.
*
Expand Down
26 changes: 26 additions & 0 deletions tests/LeanUserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use LeanCloud\LeanClient;
use LeanCloud\LeanUser;
use LeanCloud\LeanFile;
use LeanCloud\LeanQuery;
use LeanCloud\CloudException;
use LeanCloud\Storage\SessionStorage;

Expand Down Expand Up @@ -101,6 +102,18 @@ public function testUserLogIn() {
$this->assertEquals($user, LeanUser::getCurrentUser());
}

public function testLoginWithMobilePhoneNumber() {
$user = LeanUser::logIn("alice", "blabla");
$user->setMobilePhoneNumber("18612340000");
$user->save();
$user->logOut();
$this->assertNull(LeanUser::getCurrentUser());

LeanUser::logInWithMobilePhoneNumber("18612340000", "blabla");
$user2 = LeanUser::getCurrentUser();
$this->assertEquals("alice", $user2->getUsername());
}

public function testBecome() {
$user = LeanUser::logIn("alice", "blabla");

Expand Down Expand Up @@ -199,5 +212,18 @@ public function testCircularGetCurrentUser() {
$this->assertEquals($user2->getUsername(), "alice");
}

/*
* To test this case, it is necessary to set "find" permission
* to be session user, i.e. allow current logged in user to query only.
*
* @link https://github.com/leancloud/php-sdk/issues/62
*/
public function testFindUserWithSession() {
$user = LeanUser::logIn("alice", "blabla");
$query = new LeanQuery("_User");
// it should not raise: 1 Forbidden to find by class permission.
$query->first();
}

}

0 comments on commit c19424d

Please sign in to comment.