Skip to content

Commit

Permalink
Merge branch '12.next-cake5' into feature/flash-on-login-cake5
Browse files Browse the repository at this point in the history
  • Loading branch information
arodu committed Feb 7, 2024
2 parents 88f457c + c5e2c0f commit 37c9e8c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 2 additions & 0 deletions config/users.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@
],
'Login' => [
'flashMessage' => false, // bool
'updateLastLogin' => true,
'lastLoginField' => 'last_login',
],
'Registration' => [
// determines if the register is enabled
Expand Down
8 changes: 6 additions & 2 deletions src/Controller/Component/LoginComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -235,10 +235,14 @@ protected function checkSafeHost(?string $queryRedirect = null): bool
*/
protected function updateLastLogin($user)
{
if (!Configure::read('Users.Login.updateLastLogin', true)) {
return;
}
$field = Configure::read('Users.Login.lastLoginField', 'last_login');
$now = \Cake\I18n\DateTime::now();
$user->set('last_login', $now);
$user->set($field, $now);
$this->getController()->getUsersTable()->updateAll(
['last_login' => $now],
[$field => $now->format('Y-m-d H:i:s')],
['id' => $user->id]
);
}
Expand Down

0 comments on commit 37c9e8c

Please sign in to comment.