Skip to content

Commit

Permalink
perf: Use more performant way to obtain and check the email as a logi…
Browse files Browse the repository at this point in the history
…n name with token login

Signed-off-by: Julius Härtl <jus@bitgrid.net>
  • Loading branch information
juliusknorr committed Jan 9, 2024
1 parent 2ef0940 commit 1712df7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
13 changes: 11 additions & 2 deletions lib/private/User/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -456,8 +456,17 @@ public function logClientIn($user,
$this->handleLoginFailed($throttler, $currentDelay, $remoteAddress, $user, $password);
return false;
}
$users = $this->manager->getByEmail($user);
if (!(\count($users) === 1 && $this->login($users[0]->getUID(), $password))) {

if ($isTokenPassword) {
$dbToken = $this->tokenProvider->getToken($password);
$userFromToken = $this->manager->get($dbToken->getUID());
$isValidEmailLogin = $userFromToken->getEMailAddress() === $user;
} else {
$users = $this->manager->getByEmail($user);
$isValidEmailLogin = (\count($users) === 1 && $this->login($users[0]->getUID(), $password));
}

if (!$isValidEmailLogin) {
$this->handleLoginFailed($throttler, $currentDelay, $remoteAddress, $user, $password);
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/lib/User/SessionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1110,7 +1110,7 @@ public function testLogClientInThrottlerEmail() {

$userSession->expects($this->once())
->method('isTokenPassword')
->willReturn(true);
->willReturn(false);
$userSession->expects($this->once())
->method('login')
->with('john@foo.bar', 'I-AM-AN-PASSWORD')
Expand Down

0 comments on commit 1712df7

Please sign in to comment.