Skip to content

Commit b9128ea

Browse files
committed
Update last login when "remember_me" is used
1 parent 4c23d3e commit b9128ea

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

src/Auth.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -684,6 +684,7 @@ public function getAlternateAuthSystemsUserLogin($authtype = 0)
684684

685685
if (self::checkPassword($cookie_token, $hash)) {
686686
$this->user->fields['name'] = $user->fields['name'];
687+
$user->update(['id' => $user->getID(), 'last_login' => $_SESSION["glpi_currenttime"]]);
687688
return true;
688689
} else {
689690
$this->addToError(__("Invalid cookie data"));

tests/functional/AuthTest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,4 +309,24 @@ public function testPasswordCostUpdate(): void
309309
preg_match('/\$2y\$(\d+)\$.+/', $user->fields['password'], $new_cost);
310310
$this->assertGreaterThan(5, (int) $new_cost[1]);
311311
}
312+
313+
public function testRememberMeLastLogin(): void
314+
{
315+
$_SESSION["glpi_currenttime"] = date('Y-m-d H:i:s');
316+
$user = getItemByTypeName(User::class, 'post-only');
317+
$token = $user->getAuthToken('cookie_token', true);
318+
$this->assertnull($user->fields['last_login']);
319+
320+
$_COOKIE[session_name() . '_rememberme'] = json_encode([
321+
$user->getID(),
322+
$token,
323+
]);
324+
325+
//login using remember_me cookie just set
326+
$this->assertTrue((new \Auth())->login('', ''));
327+
328+
//check if last_login is now set
329+
$this->assertTrue($user->getFromDB($user->getID()));
330+
$this->assertSame($_SESSION["glpi_currenttime"], $user->fields['last_login']);
331+
}
312332
}

0 commit comments

Comments
 (0)