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

feat:flash message on login, on cake4 #1070

Merged
merged 3 commits into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
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
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 @@ -76,6 +76,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 @@ -247,4 +248,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']));
}
}
Loading