From 5cc9ad35d016b6064e2eebaeaa8c5eda798b303a Mon Sep 17 00:00:00 2001 From: Ronak Patel Date: Mon, 10 Jun 2024 20:12:03 +0530 Subject: [PATCH 1/6] Removed unverfied-email as recoveryMailAddress while account creation --- lib/Service/UserService.php | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/Service/UserService.php b/lib/Service/UserService.php index 7cea78aa..0d5f9b8c 100644 --- a/lib/Service/UserService.php +++ b/lib/Service/UserService.php @@ -325,7 +325,6 @@ class UserService { 'userPassword' => $password, 'displayName' => $displayName, 'quota' => $quota, - 'recoveryMailAddress' => $recoveryEmail, 'active' => 'TRUE', 'mailActive' => 'TRUE', 'userClusterID' => $this->apiConfig['userCluserId'], -- GitLab From dd3bc7478fecfc1619b48714292b03099bc4d550 Mon Sep 17 00:00:00 2001 From: Ronak Patel Date: Mon, 10 Jun 2024 20:21:18 +0530 Subject: [PATCH 2/6] set recovery email function change: added ldap change too --- lib/Service/UserService.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/Service/UserService.php b/lib/Service/UserService.php index 0d5f9b8c..f10f0887 100644 --- a/lib/Service/UserService.php +++ b/lib/Service/UserService.php @@ -104,6 +104,10 @@ class UserService { public function setRecoveryEmail(string $uid, string $recoveryEmail): void { $this->config->setUserValue($uid, 'email-recovery', 'recovery-email', $recoveryEmail); + $recoveryMailAddressAttribute = [ + 'recoveryMailAddress' => $recoveryEmail + ]; + $this->updateAttributesInLDAP($uid, $recoveryMailAddressAttribute); } public function setUnverifiedRecoveryEmail(string $uid, string $recoveryEmail): void { $this->config->setUserValue($uid, 'email-recovery', 'unverified-recovery-email', $recoveryEmail); @@ -325,6 +329,7 @@ class UserService { 'userPassword' => $password, 'displayName' => $displayName, 'quota' => $quota, + 'recoveryMailAddress' => '', 'active' => 'TRUE', 'mailActive' => 'TRUE', 'userClusterID' => $this->apiConfig['userCluserId'], -- GitLab From b15afcc7cffa0f8aef6435c4a538b4b921fd7972 Mon Sep 17 00:00:00 2001 From: Ronak Patel Date: Tue, 11 Jun 2024 05:16:24 +0530 Subject: [PATCH 3/6] recoveryEmail attribute update on change of NC config change --- lib/Listeners/UserConfigChangedListener.php | 37 +++++++++++++++++++++ lib/Service/UserService.php | 4 --- 2 files changed, 37 insertions(+), 4 deletions(-) create mode 100644 lib/Listeners/UserConfigChangedListener.php diff --git a/lib/Listeners/UserConfigChangedListener.php b/lib/Listeners/UserConfigChangedListener.php new file mode 100644 index 00000000..d3a7847d --- /dev/null +++ b/lib/Listeners/UserConfigChangedListener.php @@ -0,0 +1,37 @@ +logger = $logger; + $this->userService = $userService; + } + + public function handle(Event $event): void { + if (!($event instanceof UserConfigChangedEvent)) { + return; + } + if ($event->getKey() === 'recovery-email') { + $uid = $event->getUserId(); + $newRecoveryEmail = $event->getValue(); + if ($newRecoveryEmail !== '') { + $recoveryMailAddressAttribute = [ + 'recoveryMailAddress' => $newRecoveryEmail + ]; + $this->userService->updateAttributesInLDAP($uid, $recoveryMailAddressAttribute); + } + } + } +} diff --git a/lib/Service/UserService.php b/lib/Service/UserService.php index f10f0887..9c8d4b8a 100644 --- a/lib/Service/UserService.php +++ b/lib/Service/UserService.php @@ -104,10 +104,6 @@ class UserService { public function setRecoveryEmail(string $uid, string $recoveryEmail): void { $this->config->setUserValue($uid, 'email-recovery', 'recovery-email', $recoveryEmail); - $recoveryMailAddressAttribute = [ - 'recoveryMailAddress' => $recoveryEmail - ]; - $this->updateAttributesInLDAP($uid, $recoveryMailAddressAttribute); } public function setUnverifiedRecoveryEmail(string $uid, string $recoveryEmail): void { $this->config->setUserValue($uid, 'email-recovery', 'unverified-recovery-email', $recoveryEmail); -- GitLab From de9dc188e5f52f6be00689bd1759885d29761a89 Mon Sep 17 00:00:00 2001 From: Ronak Patel Date: Tue, 11 Jun 2024 05:17:53 +0530 Subject: [PATCH 4/6] lint fi --- lib/Listeners/UserConfigChangedListener.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Listeners/UserConfigChangedListener.php b/lib/Listeners/UserConfigChangedListener.php index d3a7847d..4b7d1278 100644 --- a/lib/Listeners/UserConfigChangedListener.php +++ b/lib/Listeners/UserConfigChangedListener.php @@ -4,11 +4,11 @@ declare(strict_types=1); namespace OCA\EcloudAccounts\Listeners; +use OCA\EcloudAccounts\Service\UserService; use OCP\EventDispatcher\Event; use OCP\EventDispatcher\IEventListener; use OCP\ILogger; use OCP\User\Events\UserConfigChangedEvent; -use OCA\EcloudAccounts\Service\UserService; class UserConfigChangedListener implements IEventListener { private $logger; -- GitLab From fe056a9c0e3c4965b7d8813e5d7e77429b068c2d Mon Sep 17 00:00:00 2001 From: Ronak Patel Date: Tue, 11 Jun 2024 06:00:31 +0530 Subject: [PATCH 5/6] removed config file --- lib/Listeners/UserConfigChangedListener.php | 37 --------------------- 1 file changed, 37 deletions(-) delete mode 100644 lib/Listeners/UserConfigChangedListener.php diff --git a/lib/Listeners/UserConfigChangedListener.php b/lib/Listeners/UserConfigChangedListener.php deleted file mode 100644 index 4b7d1278..00000000 --- a/lib/Listeners/UserConfigChangedListener.php +++ /dev/null @@ -1,37 +0,0 @@ -logger = $logger; - $this->userService = $userService; - } - - public function handle(Event $event): void { - if (!($event instanceof UserConfigChangedEvent)) { - return; - } - if ($event->getKey() === 'recovery-email') { - $uid = $event->getUserId(); - $newRecoveryEmail = $event->getValue(); - if ($newRecoveryEmail !== '') { - $recoveryMailAddressAttribute = [ - 'recoveryMailAddress' => $newRecoveryEmail - ]; - $this->userService->updateAttributesInLDAP($uid, $recoveryMailAddressAttribute); - } - } - } -} -- GitLab From 5eec4628b5634c142aa65022c71772cec65425f1 Mon Sep 17 00:00:00 2001 From: Ronak Patel Date: Tue, 11 Jun 2024 06:33:16 +0530 Subject: [PATCH 6/6] removed config file --- lib/Service/UserService.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/Service/UserService.php b/lib/Service/UserService.php index 9c8d4b8a..1371c74f 100644 --- a/lib/Service/UserService.php +++ b/lib/Service/UserService.php @@ -255,7 +255,7 @@ class UserService { if (!empty($recoveryEmail)) { $this->validateRecoveryEmail($recoveryEmail); } - $this->addNewUserToLDAP($displayname, $recoveryEmail, $username, $userEmail, $password); + $this->addNewUserToLDAP($displayname, $username, $userEmail, $password); } /** * Validates the recovery email address. @@ -302,7 +302,6 @@ class UserService { * Add a new user to the LDAP directory. * * @param string $displayname The display name of the new user. - * @param string $recoveryEmail The recovery email address of the new user. * @param string $username The username of the new user. * @param string $userEmail The email address of the new user. * @param string $password The password of the new user. @@ -310,7 +309,7 @@ class UserService { * @return void * @throws LDAPUserCreationException If there is an error adding new entry to LDAP store */ - private function addNewUserToLDAP(string $displayName, string $recoveryEmail, string $username, string $userEmail, string $password): void { + private function addNewUserToLDAP(string $displayName, string $username, string $userEmail, string $password): void { $connection = $this->LDAPConnectionService->getLDAPConnection(); $base = $this->LDAPConnectionService->getLDAPBaseUsers()[0]; $newUserDN = "username=$username," . $base; -- GitLab