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

Commit 0fe4cf63 authored by AVINASH GUSAIN's avatar AVINASH GUSAIN
Browse files

Merge branch 'dev/fix-username-login' into 'main'

fix login without domain

See merge request !236
parents 3331af74 b49c62d4
Loading
Loading
Loading
Loading
Loading
+32 −21
Original line number Diff line number Diff line
@@ -7,21 +7,22 @@ This patch auto append the domain handled by nc, configured in env var.
only the admin user (also configured in env var) will not have his login appended with a @domain suffix

diff --git ./core/Controller/LoginController.php ./core/Controller/LoginController-new.php
--- ./core/Controller/LoginController.php	2023-04-21 15:08:54.979407062 +0530
+++ ./core/Controller/LoginController-new.php	2023-04-21 15:16:48.582366408 +0530
@@ -318,6 +318,26 @@
 				$this->l10n->t('Please try again')
--- ./core/Controller/LoginController.php	2024-04-26 15:08:54.979407062 +0530
+++ ./core/Controller/LoginController-new.php	2024-04-26 15:16:48.582366408 +0530
@@ -315,7 +315,28 @@
 				self::LOGIN_MSG_CSRFCHECKFAILED
 			);
 		}
+		$user = trim($user);
+		$user = mb_strtolower($user, 'UTF-8');
+		$actualUser = $user;
+		$legacyDomain = $this->config->getSystemValue('legacy_domain', '');
+		$legacyDomainSuffix = !empty($legacyDomain) ? '@' . $legacyDomain : '';
+		$mainDomain = $this->config->getSystemValue('main_domain', '');
+		$mainDomainSuffix = !empty($mainDomain) ? '@'  . $mainDomain : '';
+		$admin_username = $_ENV["NEXTCLOUD_ADMIN_USER"];
+		$is_admin = strcmp($user, $admin_username) === 0;
+        
 
+		if (!$is_admin && str_ends_with($user, $legacyDomainSuffix)) {
+			$user = str_replace($legacyDomainSuffix, '', $user);
+		}
@@ -33,9 +34,19 @@ diff --git ./core/Controller/LoginController.php ./core/Controller/LoginControll
+		if (!$this->userManager->userExists($user)) {
+			$user = $user . $legacyDomainSuffix;
+		}
 
+
 		$data = new LoginData(
 			$this->request,
 			trim($user),
@@ -328,7 +349,7 @@
 		if (!$result->isSuccess()) {
 			return $this->createLoginFailedResponse(
 				$data->getUsername(),
-				$user,
+				$actualUser,
 				$redirect_url,
 				$result->getErrorMessage()
 			);
--- ./core/Controller/WebAuthnController.php	2023-04-21 15:18:58.813220092 +0530
+++ ./core/Controller/WebAuthnController-new.php	2023-04-21 15:24:40.036538414 +0530
@@ -66,6 +66,27 @@