From 140285081538b8ca66f494bad4ff18be980f8872 Mon Sep 17 00:00:00 2001 From: Avinash Gusain Date: Fri, 26 Apr 2024 16:28:06 +0530 Subject: [PATCH 1/2] fix login without domain --- patches/002-login-without-domain.patch | 49 ++++++++++++++++---------- 1 file changed, 30 insertions(+), 19 deletions(-) diff --git a/patches/002-login-without-domain.patch b/patches/002-login-without-domain.patch index 0d61eb88..2792b934 100644 --- a/patches/002-login-without-domain.patch +++ b/patches/002-login-without-domain.patch @@ -9,33 +9,44 @@ only the admin user (also configured in env var) will not have his login appende 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') +@@ -315,7 +315,28 @@ + self::LOGIN_MSG_CSRFCHECKFAILED ); } + $user = trim($user); -+ $user = mb_strtolower($user, 'UTF-8'); -+ $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; -+ ++ $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); -+ } ++ $user = str_replace($legacyDomainSuffix, '', $user); ++ } + -+ if (!$is_admin && str_ends_with($user, $mainDomainSuffix)) { -+ $user = str_replace($mainDomainSuffix, '', $user); -+ } ++ if (!$is_admin && str_ends_with($user, $mainDomainSuffix)) { ++ $user = str_replace($mainDomainSuffix, '', $user); ++ } ++ ++ if (!$this->userManager->userExists($user)) { ++ $user = $user . $legacyDomainSuffix; ++ } + -+ 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 @@ -- GitLab From 04d42dcc52da545da4dd72b1e4ec08b659a66120 Mon Sep 17 00:00:00 2001 From: Avinash Gusain Date: Fri, 26 Apr 2024 16:33:01 +0530 Subject: [PATCH 2/2] fix login without domain --- patches/002-login-without-domain.patch | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/patches/002-login-without-domain.patch b/patches/002-login-without-domain.patch index 2792b934..aa1f15e6 100644 --- a/patches/002-login-without-domain.patch +++ b/patches/002-login-without-domain.patch @@ -7,8 +7,8 @@ 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 +--- ./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 ); -- GitLab