Loading patches/006-recovery-email-changes.patch +29 −28 Original line number Diff line number Diff line --- ./core/Controller/LostController.php 2023-02-01 18:49:00.652101897 +0530 +++ ./core/Controller/LostController-new.php 2023-02-01 18:53:01.231516084 +0530 @@ -168,8 +168,23 @@ --- ./core/Controller/LostController.php 2023-05-05 18:38:07.080445742 +0530 +++ ./core/Controller/LostController-new.php 2023-05-05 18:48:27.385043088 +0530 @@ -172,8 +172,23 @@ */ protected function checkPasswordResetToken(string $token, string $userId): void { try { + $domain = $this->config->getSystemValue('mail_domain', ''); + $domainSuffix = !empty($domain) ? '@' . $domain : ''; + $altDomain = $this->config->getSystemValue('alt_mail_domain', ''); + $altDomainSuffix = !empty($altDomain) ? '@' . $altDomain : ''; + if(stristr($userId, $domainSuffix) !== FALSE) { + $userId = str_replace($domainSuffix, '', $userId); + $legacyDomain = $this->config->getSystemValue('legacy_domain', ''); + $legacyDomainSuffix = !empty($legacyDomain) ? '@' . $legacyDomain : ''; + $mainDomain = $this->config->getSystemValue('main_domain', ''); + $mainDomainSuffix = !empty($mainDomain) ? '@' . $mainDomain : ''; + if(str_ends_with($userId, $legacyDomainSuffix)) { + $userId = str_replace($legacyDomainSuffix, '', $userId); + } + if(stristr($userId, $altDomainSuffix) !== FALSE) { + $userId = str_replace($altDomainSuffix, '', $userId); + if(str_ends_with($userId, $mainDomainSuffix)) { + $userId = str_replace($mainDomainSuffix, '', $userId); + } + + if(!$this->userManager->userExists($userId)) { + $userId = $userId . $domainSuffix; + $userId = $userId . $legacyDomainSuffix; + } $user = $this->userManager->get($userId); - $this->verificationToken->check($token, $user, 'lostpassword', $user ? $user->getEMailAddress() : '', true); + $recoveryEmail = $this->config->getUserValue($userId, 'email-recovery', 'recovery-email'); + $mailAddress = is_null($recoveryEmail) ? '' : $recoveryEmail; + $this->verificationToken->check($token, $user, 'lostpassword', $mailAddress, true); + $recoveryEmail = $this->config->getUserValue($userId, 'email-recovery', 'recovery-email', ''); + $this->verificationToken->check($token, $user, 'lostpassword', $user ? $recoveryEmail : '', true); } catch (InvalidTokenException $e) { $error = $e->getCode() === InvalidTokenException::TOKEN_EXPIRED ? $this->l10n->t('Could not reset password because the token is expired') @@ -269,8 +284,21 @@ @@ -273,9 +288,22 @@ * @throws \OCP\PreConditionNotMetException */ protected function sendEmail(string $input): void { + $domain = $this->config->getSystemValue('mail_domain', ''); + $domainSuffix = !empty($domain) ? '@' . $domain : ''; + $altDomain = $this->config->getSystemValue('alt_mail_domain', ''); + $altDomainSuffix = !empty($altDomain) ? '@' . $altDomain : ''; + if (stristr($input, $domainSuffix) !== FALSE) { + $input = str_replace($domainSuffix, '', $input); + $legacyDomain = $this->config->getSystemValue('legacy_domain', ''); + $legacyDomainSuffix = !empty($legacyDomain) ? '@' . $legacyDomain : ''; + $mainDomain = $this->config->getSystemValue('main_domain', ''); + $mainDomainSuffix = !empty($mainDomain) ? '@' . $mainDomain : ''; + if (str_ends_with($input, $legacyDomainSuffix)) { + $input = str_replace($legacyDomainSuffix, '', $input); + } + if(stristr($input, $altDomainSuffix) !== FALSE) { + $input = str_replace($altDomainSuffix, '', $input); + if(str_ends_with($input, $mainDomainSuffix)) { + $input = str_replace($mainDomainSuffix, '', $input); + } + if(!$this->userManager->userExists($input) ) { + $input = $input . $domainSuffix; + $input = $input . $legacyDomainSuffix; + } $user = $this->findUserByIdOrMail($input); - $email = $user->getEMailAddress(); + $email = $this->config->getUserValue($user->getUID(), 'email-recovery', 'recovery-email'); $email = $user->getEMailAddress(); - + $email = $this->config->getUserValue($user->getUID(), 'email-recovery', 'recovery-email', ''); if (empty($email)) { throw new ResetPasswordException('Could not send reset e-mail since there is no email for username ' . $input); } patches/025-optimize-get-by-email.patch +16 −16 Original line number Diff line number Diff line Loading @@ -2,43 +2,43 @@ From: Akhil <akhil@e.email> Date: Tue, 10 Mar 2023 10:00 +0530 Subject: [PATCH] To optimize getByEmail as we have boundary conditions that email is unique per-user and can only match one of the two domains --- ./lib/private/User/Manager.php 2023-03-10 10:01:44.729561986 +0530 +++ ./lib/private/User/Manager-new.php 2023-03-10 10:05:18.767230727 +0530 @@ -706,11 +706,33 @@ --- ./lib/private/User/Manager.php 2023-05-05 18:29:34.818568291 +0530 +++ ./lib/private/User/Manager-new.php 2023-05-05 18:33:49.872682118 +0530 @@ -693,12 +693,33 @@ */ public function getByEmail($email) { // looking for 'email' only (and not primary_mail) is intentional - $userIds = $this->config->getUsersForUserValueCaseInsensitive('settings', 'email', $email); + $mailDomain = $this->config->getSystemValue('mail_domain', ''); + $altMailDomain = $this->config->getSystemValue('alt_mail_domain', ''); + $legacyDomain = $this->config->getSystemValue('legacy_domain', ''); + $mainDomain = $this->config->getSystemValue('main_domain', ''); + $users = []; + + if(empty($mailDomain) && empty($altMailDomain)) { + $userIds = $this->config->getUsersForUserValueCaseInsensitive('settings', 'email', $email); - $users = array_map(function ($uid) { - return $this->get($uid); - }, $userIds); + if(empty($mailDomain) && empty($altMailDomain)) { + $userIds = $this->config->getUsersForUserValueCaseInsensitive('settings', 'email', $email); + $users = array_map(function ($uid) { + return $this->get($uid); + }, $userIds); + } else { + $uid = ''; + $mailDomainSuffix = empty($mailDomain) ? '' : '@' . $mailDomain; + $altMailDomainSuffix = empty($altMailDomain) ? '' : '@' . $altMailDomain; + $legacyDomainSuffix = empty($legacyDomain) ? '' : '@' . $legacyDomain; + $mainDomainSuffix = empty($mainDomain) ? '' : '@' . $mainDomain; + + if (!empty($mailDomainSuffix) && stristr($email, $mailDomainSuffix) !== FALSE) { + // In case of mail_domain, username is email + if (!empty($legacyDomainSuffix) && str_ends_with($email, $legacyDomainSuffix)) { + // In case of legacy_domain, username is email + $uid = $email; + } else if (!empty($altMailDomainSuffix) && stristr($email, $altMailDomainSuffix) !== FALSE) { + // In case of alt_mail_domain, username is email without domain suffix + $uid = str_replace($altMailDomainSuffix, '', $email); + } else if (!empty($mainDomainSuffix) && str_ends_with($email, $mainDomainSuffix)) { + // In case of main_domain, username is email without domain suffix + $uid = str_replace($mainDomainSuffix, '', $email); + } + // If no match of domain, no user + if(!empty($uid)) { + $users = [$this->get($uid)]; + } + } return array_values(array_filter($users, function ($u) { return ($u instanceof IUser); })); Loading
patches/006-recovery-email-changes.patch +29 −28 Original line number Diff line number Diff line --- ./core/Controller/LostController.php 2023-02-01 18:49:00.652101897 +0530 +++ ./core/Controller/LostController-new.php 2023-02-01 18:53:01.231516084 +0530 @@ -168,8 +168,23 @@ --- ./core/Controller/LostController.php 2023-05-05 18:38:07.080445742 +0530 +++ ./core/Controller/LostController-new.php 2023-05-05 18:48:27.385043088 +0530 @@ -172,8 +172,23 @@ */ protected function checkPasswordResetToken(string $token, string $userId): void { try { + $domain = $this->config->getSystemValue('mail_domain', ''); + $domainSuffix = !empty($domain) ? '@' . $domain : ''; + $altDomain = $this->config->getSystemValue('alt_mail_domain', ''); + $altDomainSuffix = !empty($altDomain) ? '@' . $altDomain : ''; + if(stristr($userId, $domainSuffix) !== FALSE) { + $userId = str_replace($domainSuffix, '', $userId); + $legacyDomain = $this->config->getSystemValue('legacy_domain', ''); + $legacyDomainSuffix = !empty($legacyDomain) ? '@' . $legacyDomain : ''; + $mainDomain = $this->config->getSystemValue('main_domain', ''); + $mainDomainSuffix = !empty($mainDomain) ? '@' . $mainDomain : ''; + if(str_ends_with($userId, $legacyDomainSuffix)) { + $userId = str_replace($legacyDomainSuffix, '', $userId); + } + if(stristr($userId, $altDomainSuffix) !== FALSE) { + $userId = str_replace($altDomainSuffix, '', $userId); + if(str_ends_with($userId, $mainDomainSuffix)) { + $userId = str_replace($mainDomainSuffix, '', $userId); + } + + if(!$this->userManager->userExists($userId)) { + $userId = $userId . $domainSuffix; + $userId = $userId . $legacyDomainSuffix; + } $user = $this->userManager->get($userId); - $this->verificationToken->check($token, $user, 'lostpassword', $user ? $user->getEMailAddress() : '', true); + $recoveryEmail = $this->config->getUserValue($userId, 'email-recovery', 'recovery-email'); + $mailAddress = is_null($recoveryEmail) ? '' : $recoveryEmail; + $this->verificationToken->check($token, $user, 'lostpassword', $mailAddress, true); + $recoveryEmail = $this->config->getUserValue($userId, 'email-recovery', 'recovery-email', ''); + $this->verificationToken->check($token, $user, 'lostpassword', $user ? $recoveryEmail : '', true); } catch (InvalidTokenException $e) { $error = $e->getCode() === InvalidTokenException::TOKEN_EXPIRED ? $this->l10n->t('Could not reset password because the token is expired') @@ -269,8 +284,21 @@ @@ -273,9 +288,22 @@ * @throws \OCP\PreConditionNotMetException */ protected function sendEmail(string $input): void { + $domain = $this->config->getSystemValue('mail_domain', ''); + $domainSuffix = !empty($domain) ? '@' . $domain : ''; + $altDomain = $this->config->getSystemValue('alt_mail_domain', ''); + $altDomainSuffix = !empty($altDomain) ? '@' . $altDomain : ''; + if (stristr($input, $domainSuffix) !== FALSE) { + $input = str_replace($domainSuffix, '', $input); + $legacyDomain = $this->config->getSystemValue('legacy_domain', ''); + $legacyDomainSuffix = !empty($legacyDomain) ? '@' . $legacyDomain : ''; + $mainDomain = $this->config->getSystemValue('main_domain', ''); + $mainDomainSuffix = !empty($mainDomain) ? '@' . $mainDomain : ''; + if (str_ends_with($input, $legacyDomainSuffix)) { + $input = str_replace($legacyDomainSuffix, '', $input); + } + if(stristr($input, $altDomainSuffix) !== FALSE) { + $input = str_replace($altDomainSuffix, '', $input); + if(str_ends_with($input, $mainDomainSuffix)) { + $input = str_replace($mainDomainSuffix, '', $input); + } + if(!$this->userManager->userExists($input) ) { + $input = $input . $domainSuffix; + $input = $input . $legacyDomainSuffix; + } $user = $this->findUserByIdOrMail($input); - $email = $user->getEMailAddress(); + $email = $this->config->getUserValue($user->getUID(), 'email-recovery', 'recovery-email'); $email = $user->getEMailAddress(); - + $email = $this->config->getUserValue($user->getUID(), 'email-recovery', 'recovery-email', ''); if (empty($email)) { throw new ResetPasswordException('Could not send reset e-mail since there is no email for username ' . $input); }
patches/025-optimize-get-by-email.patch +16 −16 Original line number Diff line number Diff line Loading @@ -2,43 +2,43 @@ From: Akhil <akhil@e.email> Date: Tue, 10 Mar 2023 10:00 +0530 Subject: [PATCH] To optimize getByEmail as we have boundary conditions that email is unique per-user and can only match one of the two domains --- ./lib/private/User/Manager.php 2023-03-10 10:01:44.729561986 +0530 +++ ./lib/private/User/Manager-new.php 2023-03-10 10:05:18.767230727 +0530 @@ -706,11 +706,33 @@ --- ./lib/private/User/Manager.php 2023-05-05 18:29:34.818568291 +0530 +++ ./lib/private/User/Manager-new.php 2023-05-05 18:33:49.872682118 +0530 @@ -693,12 +693,33 @@ */ public function getByEmail($email) { // looking for 'email' only (and not primary_mail) is intentional - $userIds = $this->config->getUsersForUserValueCaseInsensitive('settings', 'email', $email); + $mailDomain = $this->config->getSystemValue('mail_domain', ''); + $altMailDomain = $this->config->getSystemValue('alt_mail_domain', ''); + $legacyDomain = $this->config->getSystemValue('legacy_domain', ''); + $mainDomain = $this->config->getSystemValue('main_domain', ''); + $users = []; + + if(empty($mailDomain) && empty($altMailDomain)) { + $userIds = $this->config->getUsersForUserValueCaseInsensitive('settings', 'email', $email); - $users = array_map(function ($uid) { - return $this->get($uid); - }, $userIds); + if(empty($mailDomain) && empty($altMailDomain)) { + $userIds = $this->config->getUsersForUserValueCaseInsensitive('settings', 'email', $email); + $users = array_map(function ($uid) { + return $this->get($uid); + }, $userIds); + } else { + $uid = ''; + $mailDomainSuffix = empty($mailDomain) ? '' : '@' . $mailDomain; + $altMailDomainSuffix = empty($altMailDomain) ? '' : '@' . $altMailDomain; + $legacyDomainSuffix = empty($legacyDomain) ? '' : '@' . $legacyDomain; + $mainDomainSuffix = empty($mainDomain) ? '' : '@' . $mainDomain; + + if (!empty($mailDomainSuffix) && stristr($email, $mailDomainSuffix) !== FALSE) { + // In case of mail_domain, username is email + if (!empty($legacyDomainSuffix) && str_ends_with($email, $legacyDomainSuffix)) { + // In case of legacy_domain, username is email + $uid = $email; + } else if (!empty($altMailDomainSuffix) && stristr($email, $altMailDomainSuffix) !== FALSE) { + // In case of alt_mail_domain, username is email without domain suffix + $uid = str_replace($altMailDomainSuffix, '', $email); + } else if (!empty($mainDomainSuffix) && str_ends_with($email, $mainDomainSuffix)) { + // In case of main_domain, username is email without domain suffix + $uid = str_replace($mainDomainSuffix, '', $email); + } + // If no match of domain, no user + if(!empty($uid)) { + $users = [$this->get($uid)]; + } + } return array_values(array_filter($users, function ($u) { return ($u instanceof IUser); }));