Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 40a7cf02 authored by Arnau Vàzquez's avatar Arnau Vàzquez
Browse files

fix patch

parent 0ed48bde
Loading
Loading
Loading
Loading
Loading
+38 −44
Original line number Diff line number Diff line
From: ArnauVP <arnauvp@e.email>
Date: Fri, 27 Mar 2022 00:00:00 +0000
Subject: [PATCH] Makes password reset links use recovery email set through "email-recovery" app, makes "email" uneditable by user
Subject: [PATCH] Makes password reset links use recovery email set through "email-recovery" app

This patch adds the necessary changes to core NC controller and template for "email-recovery" app to work correctly. Instead of the user's email address, the user's recovery email address set through the "email-recovery" app is used for the password reset email.
This patch adds the necessary changes to core NC controller for "email-recovery" app to work correctly.
Instead of the user's email address, the user's recovery email address set through the "email-recovery" app is used for the password reset email.
It also handles different input types like username, username@domain, username@aliasdomain.

diff --git ./core/Controller/LostController.php ./core/Controller/LostController.new.php

--- files/LostController.php.orig	2022-03-23 12:00:12.000000000 +0100
+++ files/LostController.php	2022-05-27 01:43:22.000000000 +0200
@@ -173,9 +173,27 @@
 	 * @throws \Exception
--- LostController.php.orig	2022-05-27 02:05:38.000000000 +0200
+++ LostController.php	2022-05-27 02:08:24.000000000 +0200
@@ -174,6 +174,21 @@
 	 */
 	protected function checkPasswordResetToken(string $token, string $userId): void {
+		$domain = $this->config->getSystemValue("mail_domain");
+		$domainSuffix = "@$domain";
 		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);
+			}
+			if(stristr($userId, $altDomainSuffix) !== FALSE) {
+				$userId = str_replace($altDomainSuffix, '', $userId);
+			}
+			if(!$this->userManager->userExists($userId)) {
+				$userId = $userId . $domainSuffix;
+			}
 			$user = $this->userManager->get($userId);
 			$this->verificationToken->check($token, $user, 'lostpassword', $user ? $user->getEMailAddress() : '', true);
 		} catch (InvalidTokenException $e) {
@@ -287,8 +302,22 @@
 	 * @throws \OCP\PreConditionNotMetException
 	 */
 	protected function sendEmail($input) {
+        $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) {
@@ -26,34 +48,6 @@ diff --git ./core/Controller/LostController.php ./core/Controller/LostController
+            $input = $input . $domainSuffix;
+        }
+
+		$user = $this->findUserByIdOrMail($input);
+		$recoveryEmail = $this->config->getUserValue($userId, 'email-recovery', 'recovery-email');
+		$mailAddress = is_null($recoveryEmail) ? '' : $recoveryEmail;
+
 		try {
 			$user = $this->userManager->get($userId);
-			$this->verificationToken->check($token, $user, 'lostpassword', $user ? $user->getEMailAddress() : '', true);
+			$this->verificationToken->check($token, $user, 'lostpassword', $mailAddress, true);
 		} catch (InvalidTokenException $e) {
 			$error = $e->getCode() === InvalidTokenException::TOKEN_EXPIRED
 				? $this->l10n->t('Could not reset password because the token is expired')
@@ -214,6 +232,13 @@
 			return new JSONResponse($this->error($this->l10n->t('Password reset is disabled')));
 		}
 
+		$domain = $this->config->getSystemValue("mail_domain");
+        $domainSuffix = "@$domain";
+
+        if(stristr($input, $domainSuffix) === FALSE ) {
+            $input = $input . $domainSuffix;
+        }
+
 		\OCP\Util::emitHook(
 			'\OCA\Files_Sharing\API\Server2Server',
 			'preLoginNameUsedAsUserName',
@@ -288,7 +313,7 @@
 	 */
 	protected function sendEmail($input) {
 		$user = $this->findUserByIdOrMail($input);
-		$email = $user->getEMailAddress();
+		$email = $this->config->getUserValue($user->getUID(), 'email-recovery', 'recovery-email');