Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#1161 Added event 'userSession.onBeforeAuthenticate' #2296

Merged
merged 1 commit into from
Jan 11, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 30 additions & 3 deletions src/services/UserSessionService.php
Original file line number Diff line number Diff line change
Expand Up @@ -498,10 +498,25 @@ public function login($username, $password, $rememberMe = false)
{
$this->_identity = new UserIdentity($username, $password);

// Did we authenticate?
if ($this->_identity->authenticate())
// Fire an 'onBeforeAuthenticate' event
$event = new Event($this, array(
'identity' => $this->_identity,
'rememberMe' => $rememberMe,
));

$this->onBeforeAuthenticate($event);

// Should we continue authenticating?
if ($event->performAction)
{
return $this->loginByUserId($this->_identity->getUserModel()->id, $rememberMe, true);
// Did we authenticate?
if ($this->_identity->authenticate())
{
// In the case we have got a new value for the 'rememberMe'
$rememberMe = $event->params['rememberMe'];

return $this->loginByUserId($this->_identity->getUserModel()->id, $rememberMe, true);
}
}
}

Expand Down Expand Up @@ -1198,6 +1213,18 @@ public function startElevatedSession($password)
// Events
// -------------------------------------------------------------------------

/**
* Fires an 'onBeforeAuthenticate' event.
*
* @param Event $event
*
* @return null
*/
public function onBeforeAuthenticate(Event $event)
{
$this->raiseEvent('onBeforeAuthenticate', $event);
}

/**
* Fires an 'onBeforeLogin' event.
*
Expand Down