Skip to content

Commit

Permalink
Merge pull request #66 from juvenn/v0.2
Browse files Browse the repository at this point in the history
Feat: log-in with mobile phone and password
  • Loading branch information
juvenn committed Feb 1, 2016
2 parents c9fe189 + 88a9b4e commit b5ad612
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
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
12 changes: 12 additions & 0 deletions tests/LeanUserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,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

0 comments on commit b5ad612

Please sign in to comment.