Skip to content

Commit

Permalink
Merge pull request #1071 from arodu/feature/flash-on-login-cake5
Browse files Browse the repository at this point in the history
feat:flash message on login, on cake5
  • Loading branch information
rochamarcelo authored Feb 7, 2024
2 parents c5e2c0f + 37c9e8c commit c1fa7ea
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions config/users.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
'validate' => true,
],
'Login' => [
'flashMessage' => false, // bool
'updateLastLogin' => true,
'lastLoginField' => 'last_login',
],
Expand Down
16 changes: 16 additions & 0 deletions src/Controller/Component/LoginComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ public function handleLogin($errorOnlyPost, $redirectFailure)
$user = $request->getAttribute('identity')->getOriginalData();
$this->handlePasswordRehash($service, $user, $request);
$this->updateLastLogin($user);
$this->addFlashMessage($user);

return $this->afterIdentifyUser($user);
}
Expand Down Expand Up @@ -245,4 +246,19 @@ protected function updateLastLogin($user)
['id' => $user->id]
);
}

/**
* Add a flash message informing user is logged in
*
* @param array $user user data
* @return void
*/
protected function addFlashMessage($user)
{
if (!Configure::read('Users.Login.flashMessage')) {
return;
}

$this->getController()->Flash->success(__d('cake_d_c/users', 'Welcome, {0}', $user['username']));
}
}

0 comments on commit c1fa7ea

Please sign in to comment.