Skip to content

Commit

Permalink
feat:flash message on login
Browse files Browse the repository at this point in the history
  • Loading branch information
arodu committed Feb 6, 2024
1 parent 8952f6c commit ec19864
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
3 changes: 3 additions & 0 deletions config/users.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@
// determines if registration workflow includes email validation
'validate' => true,
],
'Login' => [
'flashMessage' => false, // bool
],
'Registration' => [
// determines if the register is enabled
'active' => true,
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 @@ -242,4 +243,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));
}

Check failure on line 260 in src/Controller/Component/LoginComponent.php

View workflow job for this annotation

GitHub Actions / Coding Standard & Static Analysis

Cannot access property $username on array.
}

0 comments on commit ec19864

Please sign in to comment.