From 0045eec5891ccf87df319463e829606113e93d94 Mon Sep 17 00:00:00 2001 From: Eduardo Morales Date: Fri, 1 Mar 2024 14:26:21 -0600 Subject: [PATCH 1/4] feat: added login's initial possible email-states Signed-off-by: Eduardo Morales --- core/Controller/LoginController.php | 31 +++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/core/Controller/LoginController.php b/core/Controller/LoginController.php index beeb2034fb7cf..a7f1ae41d255d 100644 --- a/core/Controller/LoginController.php +++ b/core/Controller/LoginController.php @@ -41,6 +41,9 @@ use OC\Authentication\WebAuthn\Manager as WebAuthnManager; use OC\User\Session; use OC_App; +use OCA\User_LDAP\Configuration; +use OCA\User_LDAP\Helper; +use OCP\App\IAppManager; use OCP\AppFramework\Controller; use OCP\AppFramework\Http; use OCP\AppFramework\Http\Attribute\OpenAPI; @@ -81,6 +84,7 @@ public function __construct( private WebAuthnManager $webAuthnManager, private IManager $manager, private IL10N $l10n, + private IAppManager $appManager, ) { parent::__construct($appName, $request); } @@ -172,6 +176,8 @@ public function showLoginForm(string $user = null, string $redirect_url = null): $this->setPasswordResetInitialState($user); + $this->setEmailStates(); + $this->initialStateService->provideInitialState('core', 'webauthn-available', $this->webAuthnManager->isWebAuthnAvailable()); $this->initialStateService->provideInitialState('core', 'hideLoginForm', $this->config->getSystemValueBool('hide_login_form', false)); @@ -226,6 +232,31 @@ private function setPasswordResetInitialState(?string $username): void { $this->canResetPassword($passwordLink, $user) ); } + + /** + * Sets the initial state of whether or not a user is allowed to login with their email + * initial state is passed in the array of 1 for email allowed and 0 for not allowed + */ + private function setEmailStates(): void { + $emailStates = []; // true: can login with email, false otherwise - default to true + + // check if user_ldap is enabled, and the required classes exist + if ($this->appManager->isAppLoaded('user_ldap') + && class_exists(Helper::class)) { + $helper = \OCP\Server::get(Helper::class); + $allPrefixes = $helper->getServerConfigurationPrefixes(); + // check each LDAP server the user is connected too + foreach ($allPrefixes as $prefix) { + $emailConfig = new Configuration($prefix); + array_push($emailStates, $emailConfig->__get('ldapLoginFilterEmail')); + } + } + $this->initialStateService-> + provideInitialState( + 'core', + 'emailStates', + $emailStates); + } /** * @param string|null $passwordLink From 8db750f66141f825e826e537555bd2f50c44131f Mon Sep 17 00:00:00 2001 From: Eduardo Morales Date: Mon, 4 Mar 2024 09:34:44 -0600 Subject: [PATCH 2/4] fix: login page now correctly shows email LDAP settings Signed-off-by: Eduardo Morales --- core/src/components/login/LoginForm.vue | 15 +++++++++++++++ core/src/views/Login.vue | 2 ++ 2 files changed, 17 insertions(+) diff --git a/core/src/components/login/LoginForm.vue b/core/src/components/login/LoginForm.vue index 9a8689dc9cc6e..523fb8b6586ba 100644 --- a/core/src/components/login/LoginForm.vue +++ b/core/src/components/login/LoginForm.vue @@ -156,6 +156,12 @@ export default { type: Boolean, default: false, }, + emailStates: { + type: Array, + default() { + return [] + } + }, }, data() { @@ -207,6 +213,15 @@ export default { loginActionUrl() { return generateUrl('login') }, + emailEnabled() { + return this.emailStates ? this.emailStates.every((state) => state === '1') : 1 + }, + loginText() { + if (this.emailEnabled) { + return t('core', 'Login with username or email') + } + return t('core', 'Login with username') + }, }, mounted() { diff --git a/core/src/views/Login.vue b/core/src/views/Login.vue index 643cf66c07be5..4c5d256109fe4 100644 --- a/core/src/views/Login.vue +++ b/core/src/views/Login.vue @@ -32,6 +32,7 @@ :errors="errors" :throttle-delay="throttleDelay" :auto-complete-allowed="autoCompleteAllowed" + :email-states="emailStates" @submit="loading = true" /> Date: Thu, 7 Mar 2024 07:27:43 -0600 Subject: [PATCH 3/4] chore: update logincontroller tests Signed-off-by: Eduardo Morales --- core/src/components/login/LoginForm.vue | 2 +- tests/Core/Controller/LoginControllerTest.php | 17 ++++++++++++----- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/core/src/components/login/LoginForm.vue b/core/src/components/login/LoginForm.vue index 523fb8b6586ba..417c0d67819db 100644 --- a/core/src/components/login/LoginForm.vue +++ b/core/src/components/login/LoginForm.vue @@ -60,7 +60,7 @@