From d8dfc853e6e5c08b3f0a067fd65b29e2f2a7fcea Mon Sep 17 00:00:00 2001 From: Ronak Patel Date: Mon, 25 Mar 2024 15:19:57 -0700 Subject: [PATCH 1/6] Adding into Bytes --- lib/Service/UserService.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Service/UserService.php b/lib/Service/UserService.php index 1cf1ffdc..c9ba176a 100644 --- a/lib/Service/UserService.php +++ b/lib/Service/UserService.php @@ -290,14 +290,14 @@ class UserService { $base = $this->LDAPConnectionService->getLDAPBaseUsers()[0]; $newUserDN = "username=$username," . $base; - + $quota = $this->LDAPConnectionService->getLdapQuota() * 1024 * 1024; $newUserEntry = [ 'mailAddress' => $userEmail, 'username' => $username, 'usernameWithoutDomain' => $username, 'userPassword' => $password, 'displayName' => $displayname, - 'quota' => $this->LDAPConnectionService->getLdapQuota(), + 'quota' => $quota, 'recoveryMailAddress' => $recoveryEmail, 'active' => 'TRUE', 'mailActive' => 'TRUE', -- GitLab From 69fd63847aa301a0d29fe557a0f5131c67df95f6 Mon Sep 17 00:00:00 2001 From: Ronak Patel Date: Mon, 25 Mar 2024 15:21:59 -0700 Subject: [PATCH 2/6] lint php --- lib/Service/UserService.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Service/UserService.php b/lib/Service/UserService.php index c9ba176a..5b3d2055 100644 --- a/lib/Service/UserService.php +++ b/lib/Service/UserService.php @@ -290,7 +290,7 @@ class UserService { $base = $this->LDAPConnectionService->getLDAPBaseUsers()[0]; $newUserDN = "username=$username," . $base; - $quota = $this->LDAPConnectionService->getLdapQuota() * 1024 * 1024; + $quota = $this->LDAPConnectionService->getLdapQuota() * 1024 * 1024; $newUserEntry = [ 'mailAddress' => $userEmail, 'username' => $username, -- GitLab From 50900c5b83ef8e99ffef8ea337f9751095e61c5e Mon Sep 17 00:00:00 2001 From: Ronak Patel Date: Mon, 25 Mar 2024 15:58:41 -0700 Subject: [PATCH 3/6] adding try catch --- lib/Service/UserService.php | 44 +++++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 19 deletions(-) diff --git a/lib/Service/UserService.php b/lib/Service/UserService.php index 5b3d2055..9a6e4214 100644 --- a/lib/Service/UserService.php +++ b/lib/Service/UserService.php @@ -291,26 +291,32 @@ class UserService { $newUserDN = "username=$username," . $base; $quota = $this->LDAPConnectionService->getLdapQuota() * 1024 * 1024; - $newUserEntry = [ - 'mailAddress' => $userEmail, - 'username' => $username, - 'usernameWithoutDomain' => $username, - 'userPassword' => $password, - 'displayName' => $displayname, - 'quota' => $quota, - 'recoveryMailAddress' => $recoveryEmail, - 'active' => 'TRUE', - 'mailActive' => 'TRUE', - 'userClusterID' => $this->apiConfig['userCluserId'], - 'objectClass' => $this->apiConfig['objectClass'] - ]; - - $ret = ldap_add($connection, $newUserDN, $newUserEntry); - - if (!$ret) { - throw new LDAPUserCreationException("Error while adding entry to LDAP for username: " . $username . ' Error: ' . ldap_error($connection), ldap_errno($connection)); + try { + $newUserEntry = [ + 'mailAddress' => $userEmail, + 'username' => $username, + 'usernameWithoutDomain' => $username, + 'userPassword' => $password, + 'displayName' => $displayname, + 'quota' => $quota, + 'recoveryMailAddress' => $recoveryEmail, + 'active' => 'TRUE', + 'mailActive' => 'TRUE', + 'userClusterID' => $this->apiConfig['userCluserId'], + 'objectClass' => $this->apiConfig['objectClass'] + ]; + + $ret = ldap_add($connection, $newUserDN, $newUserEntry); + + if (!$ret) { + throw new LDAPUserCreationException("Error while adding entry to LDAP for username: " . $username . ' Error: ' . ldap_error($connection), ldap_errno($connection)); + } + return $newUserEntry; + } catch (LDAPUserCreationException $e) { + throw $e; + } catch (Exception $e) { + throw $e; } - return $newUserEntry; } /** * Check if a recovery email address is available (not already taken by another user). -- GitLab From a329cbbaf373c00fad29339a615b6a9adda2e566 Mon Sep 17 00:00:00 2001 From: Ronak Patel Date: Tue, 26 Mar 2024 22:58:25 -0700 Subject: [PATCH 4/6] added condition to stop exection --- lib/Service/UserService.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/Service/UserService.php b/lib/Service/UserService.php index 9a6e4214..34573cc9 100644 --- a/lib/Service/UserService.php +++ b/lib/Service/UserService.php @@ -311,6 +311,9 @@ class UserService { if (!$ret) { throw new LDAPUserCreationException("Error while adding entry to LDAP for username: " . $username . ' Error: ' . ldap_error($connection), ldap_errno($connection)); } + if (is_null($this->getUser($username))) { + throw new Exception($username." user not found."); + } return $newUserEntry; } catch (LDAPUserCreationException $e) { throw $e; -- GitLab From ea0ecd64fe63f0c561f992d294ec43d68fe4cf6e Mon Sep 17 00:00:00 2001 From: Ronak Patel Date: Tue, 26 Mar 2024 23:01:23 -0700 Subject: [PATCH 5/6] removed try block --- lib/Service/UserService.php | 50 ++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 28 deletions(-) diff --git a/lib/Service/UserService.php b/lib/Service/UserService.php index 34573cc9..3798426d 100644 --- a/lib/Service/UserService.php +++ b/lib/Service/UserService.php @@ -291,35 +291,29 @@ class UserService { $newUserDN = "username=$username," . $base; $quota = $this->LDAPConnectionService->getLdapQuota() * 1024 * 1024; - try { - $newUserEntry = [ - 'mailAddress' => $userEmail, - 'username' => $username, - 'usernameWithoutDomain' => $username, - 'userPassword' => $password, - 'displayName' => $displayname, - 'quota' => $quota, - 'recoveryMailAddress' => $recoveryEmail, - 'active' => 'TRUE', - 'mailActive' => 'TRUE', - 'userClusterID' => $this->apiConfig['userCluserId'], - 'objectClass' => $this->apiConfig['objectClass'] - ]; - - $ret = ldap_add($connection, $newUserDN, $newUserEntry); - - if (!$ret) { - throw new LDAPUserCreationException("Error while adding entry to LDAP for username: " . $username . ' Error: ' . ldap_error($connection), ldap_errno($connection)); - } - if (is_null($this->getUser($username))) { - throw new Exception($username." user not found."); - } - return $newUserEntry; - } catch (LDAPUserCreationException $e) { - throw $e; - } catch (Exception $e) { - throw $e; + $newUserEntry = [ + 'mailAddress' => $userEmail, + 'username' => $username, + 'usernameWithoutDomain' => $username, + 'userPassword' => $password, + 'displayName' => $displayname, + 'quota' => $quota, + 'recoveryMailAddress' => $recoveryEmail, + 'active' => 'TRUE', + 'mailActive' => 'TRUE', + 'userClusterID' => $this->apiConfig['userCluserId'], + 'objectClass' => $this->apiConfig['objectClass'] + ]; + + $ret = ldap_add($connection, $newUserDN, $newUserEntry); + + if (!$ret) { + throw new LDAPUserCreationException("Error while adding entry to LDAP for username: " . $username . ' Error: ' . ldap_error($connection), ldap_errno($connection)); + } + if (is_null($this->getUser($username))) { + throw new Exception($username." user not found."); } + return $newUserEntry; } /** * Check if a recovery email address is available (not already taken by another user). -- GitLab From 74b360f59cb37b57dd54a42fd48af98132121b0a Mon Sep 17 00:00:00 2001 From: Ronak Patel Date: Mon, 1 Apr 2024 07:20:27 +0000 Subject: [PATCH 6/6] Update UserService.php --- lib/Service/UserService.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/lib/Service/UserService.php b/lib/Service/UserService.php index 3798426d..5b3d2055 100644 --- a/lib/Service/UserService.php +++ b/lib/Service/UserService.php @@ -310,9 +310,6 @@ class UserService { if (!$ret) { throw new LDAPUserCreationException("Error while adding entry to LDAP for username: " . $username . ' Error: ' . ldap_error($connection), ldap_errno($connection)); } - if (is_null($this->getUser($username))) { - throw new Exception($username." user not found."); - } return $newUserEntry; } /** -- GitLab