Skip to content

Commit 21e5f6e

Browse files
come-ncAndyScherzinger
authored andcommitted
fix: Avoid internal error when logging in with the wrong account to verify email address
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
1 parent 1ad2d41 commit 21e5f6e

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

apps/provisioning_api/lib/Controller/VerificationController.php

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,18 @@ public function __construct(
5151
#[NoAdminRequired]
5252
#[NoCSRFRequired]
5353
public function showVerifyMail(string $token, string $userId, string $key): TemplateResponse {
54-
if ($this->userSession->getUser()->getUID() !== $userId) {
55-
// not a public page, hence getUser() must return an IUser
56-
throw new InvalidArgumentException('Logged in account is not mail address owner');
54+
try {
55+
if ($this->userSession->getUser()?->getUID() !== $userId) {
56+
// not a public page, hence getUser() must return an IUser
57+
throw new InvalidArgumentException($this->l10n->t('Logged in account is not mail address owner'));
58+
}
59+
$email = $this->crypto->decrypt($key);
60+
} catch (\Exception $e) {
61+
return new TemplateResponse(
62+
'core', 'error', [
63+
'errors' => [['error' => $e->getMessage()]]
64+
], TemplateResponse::RENDER_AS_GUEST);
5765
}
58-
$email = $this->crypto->decrypt($key);
5966

6067
return new TemplateResponse(
6168
'core', 'confirmation', [
@@ -73,8 +80,8 @@ public function showVerifyMail(string $token, string $userId, string $key): Temp
7380
public function verifyMail(string $token, string $userId, string $key): TemplateResponse {
7481
$throttle = false;
7582
try {
76-
if ($this->userSession->getUser()->getUID() !== $userId) {
77-
throw new InvalidArgumentException('Logged in account is not mail address owner');
83+
if ($this->userSession->getUser()?->getUID() !== $userId) {
84+
throw new InvalidArgumentException($this->l10n->t('Logged in account is not mail address owner'));
7885
}
7986
$email = $this->crypto->decrypt($key);
8087
$ref = \substr(hash('sha256', $email), 0, 8);

0 commit comments

Comments
 (0)