mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-18 02:26:17 +00:00
Changing AuthComponent::login() so you can provide an array of user data to manually login a user. Leaving $user blank will attempt to identify the user using the request.
This commit is contained in:
parent
f21970c533
commit
7ea914938f
2 changed files with 27 additions and 18 deletions
|
@ -264,13 +264,6 @@ class AuthComponent extends Component {
|
|||
*/
|
||||
public $params = array();
|
||||
|
||||
/**
|
||||
* AclComponent instance if using Acl + Auth
|
||||
*
|
||||
* @var AclComponent
|
||||
*/
|
||||
public $Acl;
|
||||
|
||||
/**
|
||||
* Method list for bound controller
|
||||
*
|
||||
|
@ -576,25 +569,22 @@ class AuthComponent extends Component {
|
|||
}
|
||||
|
||||
/**
|
||||
* Manually log-in a user with the given parameter data. The $data provided can be any data
|
||||
* structure used to identify a user in AuthComponent::identify(). If $data is empty or not
|
||||
* specified, POST data from Controller::$data will be used automatically.
|
||||
* Log a user in. If a $user is provided that data will be stored as the logged in user. If `$user` is empty or not
|
||||
* specified, POST data from the current request will be used to identify a user. If the login was successful,
|
||||
* the user record is written to the session key specified in AuthComponent::$sessionKey.
|
||||
*
|
||||
* After (if) login is successful, the user record is written to the session key specified in
|
||||
* AuthComponent::$sessionKey.
|
||||
*
|
||||
* @param mixed $data User object
|
||||
* @param mixed $user Either an array of user data, or null to identify a user using the current request.
|
||||
* @return boolean True on login success, false on failure
|
||||
* @link http://book.cakephp.org/view/1261/login
|
||||
*/
|
||||
public function login($request = null) {
|
||||
public function login($user = null) {
|
||||
$this->__setDefaults();
|
||||
$this->_loggedIn = false;
|
||||
|
||||
if (empty($request)) {
|
||||
$request = $this->request;
|
||||
if (empty($user)) {
|
||||
$user = $this->identify($this->request);
|
||||
}
|
||||
if ($user = $this->identify($request)) {
|
||||
if ($user) {
|
||||
$this->Session->write($this->sessionKey, $user);
|
||||
$this->_loggedIn = true;
|
||||
}
|
||||
|
|
|
@ -1486,4 +1486,23 @@ class AuthTest extends CakeTestCase {
|
|||
|
||||
$this->Controller->Auth->mapActions(array('create' => array('my_action')));
|
||||
}
|
||||
|
||||
/**
|
||||
* test login() with user data
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function testLoginWithUserData() {
|
||||
$this->assertFalse($this->Controller->Auth->loggedIn());
|
||||
|
||||
$user = array(
|
||||
'username' => 'mariano',
|
||||
'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
|
||||
'created' => '2007-03-17 01:16:23',
|
||||
'updated' => '2007-03-17 01:18:31'
|
||||
);
|
||||
$this->assertTrue($this->Controller->Auth->login($user));
|
||||
$this->assertTrue($this->Controller->Auth->loggedIn());
|
||||
$this->assertEquals($user['username'], $this->Controller->Auth->user('username'));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue