Skip to content

Commit

Permalink
add more events into login component (before login, after login failure)
Browse files Browse the repository at this point in the history
  • Loading branch information
skie committed Aug 10, 2022
1 parent 2c3f4ce commit 2cab61d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/Controller/Component/LoginComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ public function handleLogin($errorOnlyPost, $redirectFailure)
if (!$service) {
throw new \UnexpectedValueException('Authentication service not found in this request');
}
$eventBefore = $this->getController()->dispatchEvent(Plugin::EVENT_BEFORE_LOGIN, []);
if (is_array($eventBefore->getResult())) {
return $this->getController()->redirect($eventBefore->getResult());
}

$result = $service->getResult();
if ($result->isValid()) {
$user = $request->getAttribute('identity')->getOriginalData();
Expand All @@ -72,6 +77,7 @@ public function handleLogin($errorOnlyPost, $redirectFailure)
return $this->afterIdentifyUser($user);
}
if ($request->is('post') || $errorOnlyPost === false) {
$this->getController()->dispatchEvent(Plugin::EVENT_AFTER_LOGIN_FAILURE, ['result' => $result]);
return $this->handleFailure($redirectFailure);
}

Expand Down
2 changes: 2 additions & 0 deletions src/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ class Plugin extends BasePlugin implements AuthenticationServiceProviderInterfac
* @var string
*/
protected $name = 'CakeDC/Users';
public const EVENT_BEFORE_LOGIN = 'Users.Authentication.beforeLogin';
public const EVENT_AFTER_LOGIN = 'Users.Authentication.afterLogin';
public const EVENT_AFTER_LOGIN_FAILURE = 'Users.Authentication.afterLoginFailure';
public const EVENT_BEFORE_LOGOUT = 'Users.Authentication.beforeLogout';
public const EVENT_AFTER_LOGOUT = 'Users.Authentication.afterLogout';

Expand Down

0 comments on commit 2cab61d

Please sign in to comment.