Skip to content

Commit

Permalink
Merge pull request #9072 from biesbjerg/ticket-9070
Browse files Browse the repository at this point in the history
Store user data in memory on login for stateless auth adapters
  • Loading branch information
markstory committed Jul 8, 2016
2 parents 6bccfe9 + 1d7a4da commit 0a0ded1
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/Cake/Controller/Component/AuthComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -611,8 +611,12 @@ public function login($user = null) {
$user = $this->identify($this->request, $this->response);
}
if ($user) {
$this->Session->renew();
$this->Session->write(static::$sessionKey, $user);
if (static::$sessionKey) {
$this->Session->renew();
$this->Session->write(static::$sessionKey, $user);
} else {
static::$_user = $user;
}
$event = new CakeEvent('Auth.afterIdentify', $this, array('user' => $user));
$this->_Collection->getController()->getEventManager()->dispatch($event);
}
Expand Down
21 changes: 21 additions & 0 deletions lib/Cake/Test/Case/Controller/Component/AuthComponentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1721,6 +1721,27 @@ public function testStatelessAuthNoRedirect() {
$this->Auth->startup($this->Controller);
}

/**
* testStatelessLoginSetUserNoSessionStart method
*
* @return void
*/
public function testStatelessLoginSetUserNoSessionStart() {
$user = array(
'id' => 1,
'username' => 'mark'
);

AuthComponent::$sessionKey = false;
$result = $this->Auth->login($user);
$this->assertTrue($result);

$this->assertTrue($this->Auth->loggedIn());
$this->assertEquals($user, $this->Auth->user());

$this->assertFalse($this->Auth->Session->started());
}

/**
* testStatelessAuthNoSessionStart method
*
Expand Down

0 comments on commit 0a0ded1

Please sign in to comment.