From 4e2d0e29e6cd899973c03b9f5336bbfc0f467c1e Mon Sep 17 00:00:00 2001 From: Juvenn Woo Date: Thu, 28 Jan 2016 13:54:24 +0800 Subject: [PATCH 1/2] 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 2/2] 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()); }