Browse Source

Rename AuthComponent::login() to AuthComponent::setUser().

The new name better conveys what the method does and prevents the possibility
of someone misunderstanding that it actually authenticates the user.
ADmad 11 years ago
parent
commit
ffcb4389cc

+ 4 - 5
src/Controller/Component/AuthComponent.php

@@ -582,17 +582,16 @@ class AuthComponent extends Component {
 	}
 
 /**
- * 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();

+ 10 - 10
tests/TestCase/Controller/Component/AuthComponentTest.php

@@ -722,7 +722,7 @@ class AuthComponentTest extends TestCase {
 		$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'
 		]);
@@ -759,7 +759,7 @@ class AuthComponentTest extends TestCase {
 		]);
 		$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);
@@ -796,7 +796,7 @@ class AuthComponentTest extends TestCase {
 		$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);
@@ -833,7 +833,7 @@ class AuthComponentTest extends TestCase {
 			'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(
@@ -1093,11 +1093,11 @@ class AuthComponentTest extends TestCase {
 	}
 
 /**
- * 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')
@@ -1112,15 +1112,15 @@ class AuthComponentTest extends TestCase {
 			->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(
@@ -1129,7 +1129,7 @@ class AuthComponentTest extends TestCase {
 			'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'));
 	}