Skip to content

Commit 2cab61d

Browse files
committed
add more events into login component (before login, after login failure)
1 parent 2c3f4ce commit 2cab61d

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

src/Controller/Component/LoginComponent.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,11 @@ public function handleLogin($errorOnlyPost, $redirectFailure)
6464
if (!$service) {
6565
throw new \UnexpectedValueException('Authentication service not found in this request');
6666
}
67+
$eventBefore = $this->getController()->dispatchEvent(Plugin::EVENT_BEFORE_LOGIN, []);
68+
if (is_array($eventBefore->getResult())) {
69+
return $this->getController()->redirect($eventBefore->getResult());
70+
}
71+
6772
$result = $service->getResult();
6873
if ($result->isValid()) {
6974
$user = $request->getAttribute('identity')->getOriginalData();
@@ -72,6 +77,7 @@ public function handleLogin($errorOnlyPost, $redirectFailure)
7277
return $this->afterIdentifyUser($user);
7378
}
7479
if ($request->is('post') || $errorOnlyPost === false) {
80+
$this->getController()->dispatchEvent(Plugin::EVENT_AFTER_LOGIN_FAILURE, ['result' => $result]);
7581
return $this->handleFailure($redirectFailure);
7682
}
7783

src/Plugin.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ class Plugin extends BasePlugin implements AuthenticationServiceProviderInterfac
3030
* @var string
3131
*/
3232
protected $name = 'CakeDC/Users';
33+
public const EVENT_BEFORE_LOGIN = 'Users.Authentication.beforeLogin';
3334
public const EVENT_AFTER_LOGIN = 'Users.Authentication.afterLogin';
35+
public const EVENT_AFTER_LOGIN_FAILURE = 'Users.Authentication.afterLoginFailure';
3436
public const EVENT_BEFORE_LOGOUT = 'Users.Authentication.beforeLogout';
3537
public const EVENT_AFTER_LOGOUT = 'Users.Authentication.afterLogout';
3638

0 commit comments

Comments
 (0)