From 0ff7dc8515a53696e2f5b46af989092b25719b54 Mon Sep 17 00:00:00 2001 From: Juvenn Woo Date: Wed, 27 Jan 2016 15:33:27 +0800 Subject: [PATCH 1/4] Fix: pass current session token as defalut in request Close #62. There was not default session token in request, which fails request that requires session, for example a query over _User table. --- src/LeanCloud/LeanClient.php | 5 +++++ tests/LeanUserTest.php | 14 ++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/src/LeanCloud/LeanClient.php b/src/LeanCloud/LeanClient.php index d04ce36..7343de4 100644 --- a/src/LeanCloud/LeanClient.php +++ b/src/LeanCloud/LeanClient.php @@ -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; @@ -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; } diff --git a/tests/LeanUserTest.php b/tests/LeanUserTest.php index a0afa05..a387ca3 100644 --- a/tests/LeanUserTest.php +++ b/tests/LeanUserTest.php @@ -3,6 +3,7 @@ use LeanCloud\LeanClient; use LeanCloud\LeanUser; use LeanCloud\LeanFile; +use LeanCloud\LeanQuery; use LeanCloud\CloudException; use LeanCloud\Storage\SessionStorage; @@ -199,5 +200,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(); + } + } From 4e2d0e29e6cd899973c03b9f5336bbfc0f467c1e Mon Sep 17 00:00:00 2001 From: Juvenn Woo Date: Thu, 28 Jan 2016 13:54:24 +0800 Subject: [PATCH 2/4] Feat: log-in with mobile phone and password --- src/LeanCloud/LeanUser.php | 17 +++++++++++++++++ tests/LeanUserTest.php | 12 ++++++++++++ 2 files changed, 29 insertions(+) diff --git a/src/LeanCloud/LeanUser.php b/src/LeanCloud/LeanUser.php index 3d11838..8f33bac 100644 --- a/src/LeanCloud/LeanUser.php +++ b/src/LeanCloud/LeanUser.php @@ -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 logInWithMobilePhone($phoneNumber, $password) { + $params = array("mobilePhoneNumber" => $phoneNumber, + "password" => $password); + $resp = LeanClient::get("/login", $params); + $user = new static(); + $user->mergeAfterFetch($resp); + static::saveCurrentUser($user); + return $user; + } + /** * Log-in user by mobile phone and SMS code. * diff --git a/tests/LeanUserTest.php b/tests/LeanUserTest.php index a387ca3..73d64c3 100644 --- a/tests/LeanUserTest.php +++ b/tests/LeanUserTest.php @@ -102,6 +102,18 @@ public function testUserLogIn() { $this->assertEquals($user, LeanUser::getCurrentUser()); } + public function testLoginWithMobilePhone() { + $user = LeanUser::logIn("alice", "blabla"); + $user->setMobilePhoneNumber("18612340000"); + $user->save(); + $user->logOut(); + $this->assertNull(LeanUser::getCurrentUser()); + + LeanUser::logInWithMobilePhone("18612340000", "blabla"); + $user2 = LeanUser::getCurrentUser(); + $this->assertEquals("alice", $user2->getUsername()); + } + public function testBecome() { $user = LeanUser::logIn("alice", "blabla"); From 88a9b4e24d36dde17b9940a799d5b92622f4e7c9 Mon Sep 17 00:00:00 2001 From: Juvenn Woo Date: Fri, 29 Jan 2016 11:39:38 +0800 Subject: [PATCH 3/4] Feat: Rename method to logInWithMobilePhoneNumber Rename `LeanUser::logInWithMobilePhone` to `LeanUser::logInWithMobilePhoneNumber`, to maintain compatibility with iOS sdk. --- src/LeanCloud/LeanUser.php | 4 ++-- tests/LeanUserTest.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/LeanCloud/LeanUser.php b/src/LeanCloud/LeanUser.php index 8f33bac..a258b59 100644 --- a/src/LeanCloud/LeanUser.php +++ b/src/LeanCloud/LeanUser.php @@ -291,10 +291,10 @@ public static function logOut() { * @param string $password * @return LeanUser */ - public static function logInWithMobilePhone($phoneNumber, $password) { + public static function logInWithMobilePhoneNumber($phoneNumber, $password) { $params = array("mobilePhoneNumber" => $phoneNumber, "password" => $password); - $resp = LeanClient::get("/login", $params); + $resp = LeanClient::post("/login", $params); $user = new static(); $user->mergeAfterFetch($resp); static::saveCurrentUser($user); diff --git a/tests/LeanUserTest.php b/tests/LeanUserTest.php index 73d64c3..652d200 100644 --- a/tests/LeanUserTest.php +++ b/tests/LeanUserTest.php @@ -102,14 +102,14 @@ public function testUserLogIn() { $this->assertEquals($user, LeanUser::getCurrentUser()); } - public function testLoginWithMobilePhone() { + public function testLoginWithMobilePhoneNumber() { $user = LeanUser::logIn("alice", "blabla"); $user->setMobilePhoneNumber("18612340000"); $user->save(); $user->logOut(); $this->assertNull(LeanUser::getCurrentUser()); - LeanUser::logInWithMobilePhone("18612340000", "blabla"); + LeanUser::logInWithMobilePhoneNumber("18612340000", "blabla"); $user2 = LeanUser::getCurrentUser(); $this->assertEquals("alice", $user2->getUsername()); } From 805f01252a424490298f1639ec18b30ea064bcb6 Mon Sep 17 00:00:00 2001 From: Juvenn Woo Date: Mon, 1 Feb 2016 15:32:45 +0800 Subject: [PATCH 4/4] Release v0.2.5 --- Changelog.md | 5 +++++ src/LeanCloud/LeanClient.php | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/Changelog.md b/Changelog.md index 31ded28..be96b31 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,4 +1,9 @@ +0.2.5 发布日期:2016-02-01 +---- +* 支持手机号码和密码登录 +* 修复查询 `_User` 未传递 sessionToken 导致查询失败 + 0.2.4 发布日期:2016-01-26 ---- diff --git a/src/LeanCloud/LeanClient.php b/src/LeanCloud/LeanClient.php index 7343de4..077f334 100644 --- a/src/LeanCloud/LeanClient.php +++ b/src/LeanCloud/LeanClient.php @@ -23,7 +23,7 @@ class LeanClient { /** * Client version */ - const VERSION = '0.2.4'; + const VERSION = '0.2.5'; /** * API Endpoints for Regions