Skip to content

Commit

Permalink
Rename AuthComponent::login() to AuthComponent::setUser().
Browse files Browse the repository at this point in the history
The new name better conveys what the method does and prevents the possibility
of someone misunderstanding that it actually authenticates the user.
  • Loading branch information
ADmad committed Jun 18, 2014
1 parent 8e5b2c7 commit ffcb438
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 15 deletions.
9 changes: 4 additions & 5 deletions src/Controller/Component/AuthComponent.php
Expand Up @@ -582,17 +582,16 @@ public function mapActions(array $map = array()) {
}

/**
* Log a user in.
* Set provided user info to session as logged in user.
*
* The provided user data will be stored as the logged in user. The user record
* is written to the session key specified in AuthComponent::$sessionKey. Logging
* in will also change the session id in order to help mitigate session replays.
* The user recordis written to the session key specified in AuthComponent::$sessionKey.
* Thehe session id will also be changed in order to help mitigate session replays.
*
* @param array $user Array of user data.
* @return void
* @link http://book.cakephp.org/2.0/en/core-libraries/components/authentication.html#identifying-users-and-logging-them-in
*/
public function login(array $user) {
public function setUser(array $user) {
$this->_setDefaults();

$this->session->renew();
Expand Down
20 changes: 10 additions & 10 deletions tests/TestCase/Controller/Component/AuthComponentTest.php
Expand Up @@ -722,7 +722,7 @@ public function testDefaultToLoginRedirect() {
$Request->env('HTTP_REFERER', false);
$this->Auth->request->addParams(Router::parse($url));
$this->Auth->config('authorize', ['Controller']);
$this->Auth->login(array('username' => 'mariano', 'password' => 'cake'));
$this->Auth->setUser(array('username' => 'mariano', 'password' => 'cake'));
$this->Auth->config('loginRedirect', [
'controller' => 'something', 'action' => 'else'
]);
Expand Down Expand Up @@ -759,7 +759,7 @@ public function testRedirectToUnauthorizedRedirect() {
]);
$this->Auth->request->addParams(Router::parse($url));
$this->Auth->config('authorize', ['Controller']);
$this->Auth->login(array('username' => 'admad', 'password' => 'cake'));
$this->Auth->setUser(array('username' => 'admad', 'password' => 'cake'));

$expected = ['controller' => 'no_can_do', 'action' => 'jack'];
$this->Auth->config('unauthorizedRedirect', $expected);
Expand Down Expand Up @@ -796,7 +796,7 @@ public function testRedirectToUnauthorizedRedirectSuppressedAuthError() {
$this->Auth->request = $Request = new Request($url);
$this->Auth->request->addParams(Router::parse($url));
$this->Auth->config('authorize', ['Controller']);
$this->Auth->login(array('username' => 'admad', 'password' => 'cake'));
$this->Auth->setUser(array('username' => 'admad', 'password' => 'cake'));
$expected = ['controller' => 'no_can_do', 'action' => 'jack'];
$this->Auth->config('unauthorizedRedirect', $expected);
$this->Auth->config('authError', false);
Expand Down Expand Up @@ -833,7 +833,7 @@ public function testForbiddenException() {
'authorize' => ['Controller'],
'unauthorizedRedirect' => false
]);
$this->Auth->login(array('username' => 'baker', 'password' => 'cake'));
$this->Auth->setUser(array('username' => 'baker', 'password' => 'cake'));

$response = new Response();
$Controller = $this->getMock(
Expand Down Expand Up @@ -1093,11 +1093,11 @@ public function testMapActionsDelegation() {
}

/**
* test logging in.
* test setting user info to session.
*
* @return void
*/
public function testLogin() {
public function testSetUser() {
$this->Auth->session = $this->getMock(
'Cake\Network\Session',
array('renew', 'write')
Expand All @@ -1112,15 +1112,15 @@ public function testLogin() {
->method('write')
->with($this->Auth->sessionKey, $user);

$this->Auth->login($user);
$this->Auth->setUser($user);
}

/**
* testGettingUserAfterLogin
* testGettingUserAfterSetUser
*
* @return void
*/
public function testGettingUserAfterLogin() {
public function testGettingUserAfterSetUser() {
$this->assertFalse((bool)$this->Auth->user());

$user = array(
Expand All @@ -1129,7 +1129,7 @@ public function testGettingUserAfterLogin() {
'created' => new \DateTime('2007-03-17 01:16:23'),
'updated' => new \DateTime('2007-03-17 01:18:31')
);
$this->Auth->login($user);
$this->Auth->setUser($user);
$this->assertTrue((bool)$this->Auth->user());
$this->assertEquals($user['username'], $this->Auth->user('username'));
}
Expand Down

0 comments on commit ffcb438

Please sign in to comment.