From d275d0ba726556f4fb4929c2052a35b6b9aa863c Mon Sep 17 00:00:00 2001 From: Akhil Date: Fri, 15 Mar 2024 20:22:01 +0530 Subject: [PATCH 1/4] Better error logging and message when there is an ldap error while creating --- l10n/de.js | 3 +- l10n/de.json | 3 +- l10n/en.js | 3 +- l10n/en.json | 3 +- l10n/es.js | 3 +- l10n/es.json | 3 +- l10n/fr.js | 3 +- l10n/fr.json | 3 +- l10n/it.js | 3 +- l10n/it.json | 3 +- lib/Controller/AccountController.php | 5 +- lib/Exception/LDAPUserCreationException.php | 9 ++++ lib/Service/UserService.php | 53 ++++++++++----------- 13 files changed, 58 insertions(+), 39 deletions(-) create mode 100644 lib/Exception/LDAPUserCreationException.php diff --git a/l10n/de.js b/l10n/de.js index 9785af83..85981868 100644 --- a/l10n/de.js +++ b/l10n/de.js @@ -82,6 +82,7 @@ OC.L10N.register( "Recovery email address has an incorrect format.": "Die E-Mail-Adresse für die Wiederherstellung hat ein falsches Format.", "Recovery email address is already taken.": "Die E-Mail-Adresse für die Wiederherstellung ist bereits vergeben.", "You cannot set an email address with a Murena domain as recovery email address.": "Sie können keine E-Mail-Adresse mit einer Murena-Domäne als Wiederherstellungs-E-Mail-Adresse festlegen.", - "Captcha is not verified!": "Captcha wird nicht überprüft!" + "Captcha is not verified!": "Captcha wird nicht überprüft!", + "A server-side error occurred while processing your request! Please try again later.": "Ein serverseitiger Fehler ist bei der Bearbeitung Ihrer Anfrage aufgetreten! Bitte versuchen Sie es später noch einmal." }, "nplurals=2; plural=(n != 1);"); diff --git a/l10n/de.json b/l10n/de.json index 09a7588c..93a91342 100644 --- a/l10n/de.json +++ b/l10n/de.json @@ -80,7 +80,8 @@ "Recovery email address has an incorrect format.": "Die E-Mail-Adresse für die Wiederherstellung hat ein falsches Format.", "Recovery email address is already taken.": "Die E-Mail-Adresse für die Wiederherstellung ist bereits vergeben.", "You cannot set an email address with a Murena domain as recovery email address.": "Sie können keine E-Mail-Adresse mit einer Murena-Domäne als Wiederherstellungs-E-Mail-Adresse festlegen.", - "Captcha is not verified!": "Captcha wird nicht überprüft!" + "Captcha is not verified!": "Captcha wird nicht überprüft!", + "A server-side error occurred while processing your request! Please try again later.": "Ein serverseitiger Fehler ist bei der Bearbeitung Ihrer Anfrage aufgetreten! Bitte versuchen Sie es später noch einmal." }, "pluralForm": "nplurals=2; plural=(n != 1);" } diff --git a/l10n/en.js b/l10n/en.js index 3d9794a3..70409d73 100644 --- a/l10n/en.js +++ b/l10n/en.js @@ -86,6 +86,7 @@ OC.L10N.register( "Recovery email address has an incorrect format.": "Recovery email address has an incorrect format.", "Recovery email address is already taken.": "Recovery email address is already taken.", "You cannot set an email address with a Murena domain as recovery email address.": "You cannot set an email address with a Murena domain as recovery email address.", - "Captcha is not verified!": "Captcha is not verified!" + "Captcha is not verified!": "Captcha is not verified!", + "A server-side error occurred while processing your request! Please try again later.": "A server-side error occurred while processing your request! Please try again later." }, "nplurals=2; plural=(n != 1);"); diff --git a/l10n/en.json b/l10n/en.json index d61942f9..cb446611 100644 --- a/l10n/en.json +++ b/l10n/en.json @@ -82,7 +82,8 @@ "Recovery email address has an incorrect format.": "Recovery email address has an incorrect format.", "Recovery email address is already taken.": "Recovery email address is already taken.", "You cannot set an email address with a Murena domain as recovery email address.": "You cannot set an email address with a Murena domain as recovery email address.", - "Captcha is not verified!": "Captcha is not verified!" + "Captcha is not verified!": "Captcha is not verified!", + "A server-side error occurred while processing your request! Please try again later.": "A server-side error occurred while processing your request! Please try again later." }, "pluralForm": "nplurals=2; plural=(n != 1);" } diff --git a/l10n/es.js b/l10n/es.js index 72f2b282..619717cb 100644 --- a/l10n/es.js +++ b/l10n/es.js @@ -84,6 +84,7 @@ OC.L10N.register( "Recovery email address has an incorrect format.": "La dirección de correo electrónico de recuperación tiene un formato incorrecto.", "Recovery email address is already taken.": "La dirección de correo electrónico de recuperación ya está ocupada.", "You cannot set an email address with a Murena domain as recovery email address.": "No puede establecer una dirección de correo electrónico con un dominio de Murena como dirección de correo electrónico de recuperación.", - "Captcha is not verified!": "¡Captcha no está verificado!" + "Captcha is not verified!": "¡Captcha no está verificado!", + "A server-side error occurred while processing your request! Please try again later.": "Hubo un error en el servidor al procesar tu solicitud. Por favor, inténtalo más tarde." }, "nplurals=2; plural=(n != 1);"); diff --git a/l10n/es.json b/l10n/es.json index 409ea77b..13871c86 100644 --- a/l10n/es.json +++ b/l10n/es.json @@ -83,7 +83,8 @@ "Recovery email address has an incorrect format.": "La dirección de correo electrónico de recuperación tiene un formato incorrecto.", "Recovery email address is already taken.": "La dirección de correo electrónico de recuperación ya está ocupada.", "You cannot set an email address with a Murena domain as recovery email address.": "No puede establecer una dirección de correo electrónico con un dominio de Murena como dirección de correo electrónico de recuperación.", - "Captcha is not verified!": "¡Captcha no está verificado!" + "Captcha is not verified!": "¡Captcha no está verificado!", + "A server-side error occurred while processing your request! Please try again later.": "Hubo un error en el servidor al procesar tu solicitud. Por favor, inténtalo más tarde." }, "pluralForm": "nplurals=2; plural=(n != 1);" } diff --git a/l10n/fr.js b/l10n/fr.js index 2b327ea3..2c4914e0 100644 --- a/l10n/fr.js +++ b/l10n/fr.js @@ -83,6 +83,7 @@ OC.L10N.register( "Recovery email address has an incorrect format.": "Le format de l'adresse électronique de récupération est incorrect.", "Recovery email address is already taken.": "L'adresse électronique de récupération est déjà prise.", "You cannot set an email address with a Murena domain as recovery email address.": "Vous ne pouvez pas définir une adresse électronique avec un domaine Murena comme adresse électronique de récupération.", - "Captcha is not verified!": "Captcha n'est pas vérifié !" + "Captcha is not verified!": "Captcha n'est pas vérifié !", + "A server-side error occurred while processing your request! Please try again later.": "Erreur du serveur dans la gestion de votre demande ! Merci d'essayer ultérieurement." }, "nplurals=2; plural=(n != 1);"); diff --git a/l10n/fr.json b/l10n/fr.json index 26fcbfef..60e11c06 100644 --- a/l10n/fr.json +++ b/l10n/fr.json @@ -82,7 +82,8 @@ "Recovery email address has an incorrect format.": "Le format de l'adresse électronique de récupération est incorrect.", "Recovery email address is already taken.": "L'adresse électronique de récupération est déjà prise.", "You cannot set an email address with a Murena domain as recovery email address.": "Vous ne pouvez pas définir une adresse électronique avec un domaine Murena comme adresse électronique de récupération.", - "Captcha is not verified!": "Captcha n'est pas vérifié !" + "Captcha is not verified!": "Captcha n'est pas vérifié !", + "A server-side error occurred while processing your request! Please try again later.": "Erreur du serveur dans la gestion de votre demande ! Merci d'essayer ultérieurement." }, "pluralForm": "nplurals=2; plural=(n != 1);" } diff --git a/l10n/it.js b/l10n/it.js index f3cf4249..7a246e1e 100644 --- a/l10n/it.js +++ b/l10n/it.js @@ -83,6 +83,7 @@ OC.L10N.register( "Recovery email address has an incorrect format.": "L'indirizzo e-mail di recupero ha un formato errato.", "Recovery email address is already taken.": "L'indirizzo e-mail di recupero è già stato preso.", "You cannot set an email address with a Murena domain as recovery email address.": "Non è possibile impostare un indirizzo e-mail con un dominio Murena come indirizzo e-mail di recupero.", - "Captcha is not verified!": "Il Captcha non è verificato!" + "Captcha is not verified!": "Il Captcha non è verificato!", + "A server-side error occurred while processing your request! Please try again later.": "Si è verificato un errore lato server nel processare la tua richiesta! Ritenta più tardi." }, "nplurals=2; plural=(n != 1);"); diff --git a/l10n/it.json b/l10n/it.json index e4ad86d6..a62613bd 100644 --- a/l10n/it.json +++ b/l10n/it.json @@ -78,7 +78,8 @@ "Recovery email address has an incorrect format.": "L'indirizzo e-mail di recupero ha un formato errato.", "Recovery email address is already taken.": "L'indirizzo e-mail di recupero è già stato preso.", "You cannot set an email address with a Murena domain as recovery email address.": "Non è possibile impostare un indirizzo e-mail con un dominio Murena come indirizzo e-mail di recupero.", - "Captcha is not verified!": "Il Captcha non è verificato!" + "Captcha is not verified!": "Il Captcha non è verificato!", + "A server-side error occurred while processing your request! Please try again later.": "Si è verificato un errore lato server nel processare la tua richiesta! Ritenta più tardi." }, "pluralForm": "nplurals=2; plural=(n != 1);" } diff --git a/lib/Controller/AccountController.php b/lib/Controller/AccountController.php index 6aa58aef..cdfedae8 100644 --- a/lib/Controller/AccountController.php +++ b/lib/Controller/AccountController.php @@ -160,10 +160,13 @@ class AccountController extends Controller { } catch (Exception $e) { $this->logger->logException($e, ['app' => Application::APP_ID]); } - $response->setStatus(200); $response->setData(['success' => true]); + } catch (LDAPUserCreationException $e) { + $this->logger->logException($e, ['app' => Application::APP_ID]); + $response->setData(['message' => 'A server-side error occurred while processing your request! Please try again later.', 'success' => false]); + $response->setStatus(500); } catch (Exception $e) { $response->setData(['message' => $e->getMessage(), 'success' => false]); $response->setStatus(500); diff --git a/lib/Exception/LDAPUserCreationException.php b/lib/Exception/LDAPUserCreationException.php new file mode 100644 index 00000000..bfdd7cb8 --- /dev/null +++ b/lib/Exception/LDAPUserCreationException.php @@ -0,0 +1,9 @@ +LDAPConnectionService->getLDAPConnection(); - $base = $this->LDAPConnectionService->getLDAPBaseUsers()[0]; + $connection = $this->LDAPConnectionService->getLDAPConnection(); + $base = $this->LDAPConnectionService->getLDAPBaseUsers()[0]; - $newUserDN = "username=$username," . $base; + $newUserDN = "username=$username," . $base; - $newUserEntry = [ - 'mailAddress' => $userEmail, - 'username' => $username, - 'usernameWithoutDomain' => $username, - 'userPassword' => $password, - 'displayName' => $displayname, - 'quota' => $this->LDAPConnectionService->getLdapQuota(), - 'recoveryMailAddress' => $recoveryEmail, - 'active' => 'TRUE', - 'mailActive' => 'TRUE', - 'userClusterID' => $this->apiConfig['userCluserId'], - 'objectClass' => $this->apiConfig['objectClass'] - ]; - - $ret = ldap_add($connection, $newUserDN, $newUserEntry); + $newUserEntry = [ + 'mailAddress' => $userEmail, + 'username' => $username, + 'usernameWithoutDomain' => $username, + 'userPassword' => $password, + 'displayName' => $displayname, + 'quota' => $this->LDAPConnectionService->getLdapQuota(), + 'recoveryMailAddress' => $recoveryEmail, + 'active' => 'TRUE', + 'mailActive' => 'TRUE', + 'userClusterID' => $this->apiConfig['userCluserId'], + 'objectClass' => $this->apiConfig['objectClass'] + ]; + + $ret = ldap_add($connection, $newUserDN, $newUserEntry); - if (!$ret) { - throw new Exception("Error while creating Murena account."); - } - return $newUserEntry; - } catch (Exception $e) { - $this->logger->error('Error adding adding new user to LDAP: ' . $username . ': ' . $e->getMessage()); - return null; + if (!$ret) { + throw new LDAPUserCreationException("Error while adding entry to LDAP for username: " . $username . ' Error: ' . ldap_error($connection), ldap_errno($connection)); } + return $newUserEntry; } /** * Check if a recovery email address is available (not already taken by another user). -- GitLab From 39b0c08a3deeb05f1de7505996723fb743c16152 Mon Sep 17 00:00:00 2001 From: Akhil Date: Fri, 15 Mar 2024 20:26:10 +0530 Subject: [PATCH 2/4] Also catch 'Error' separately from Exception; it is a server side issue --- lib/Controller/AccountController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Controller/AccountController.php b/lib/Controller/AccountController.php index cdfedae8..c3a8e1e3 100644 --- a/lib/Controller/AccountController.php +++ b/lib/Controller/AccountController.php @@ -163,7 +163,7 @@ class AccountController extends Controller { $response->setStatus(200); $response->setData(['success' => true]); - } catch (LDAPUserCreationException $e) { + } catch (LDAPUserCreationException | Error $e) { $this->logger->logException($e, ['app' => Application::APP_ID]); $response->setData(['message' => 'A server-side error occurred while processing your request! Please try again later.', 'success' => false]); $response->setStatus(500); -- GitLab From 9b16fa08914b4c559d648268ba80f73fcf278a0b Mon Sep 17 00:00:00 2001 From: Akhil Date: Fri, 15 Mar 2024 20:27:54 +0530 Subject: [PATCH 3/4] Run PHP linter --- 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 db56abe6..54c43925 100644 --- a/lib/Service/UserService.php +++ b/lib/Service/UserService.php @@ -242,7 +242,7 @@ class UserService { * * @return array An array containing information about the registered user. * @throws Exception If the username or recovery email is already taken. - * @throws LDAPUserCreationException If there is an error adding new entry to LDAP store + * @throws LDAPUserCreationException If there is an error adding new entry to LDAP store */ public function registerUser(string $displayname, string $recoveryEmail, string $username, string $userEmail, string $password): array { -- GitLab From a0b60bf364dc288492ed423ddfaceed46711a15d Mon Sep 17 00:00:00 2001 From: Akhil Date: Mon, 18 Mar 2024 15:58:23 +0530 Subject: [PATCH 4/4] Add sleep value of 2 --- lib/Controller/AccountController.php | 3 ++- lib/Service/UserService.php | 1 - 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Controller/AccountController.php b/lib/Controller/AccountController.php index c3a8e1e3..18a1613a 100644 --- a/lib/Controller/AccountController.php +++ b/lib/Controller/AccountController.php @@ -137,8 +137,9 @@ class AccountController extends Controller { try { $mainDomain = $this->userService->getMainDomain(); $userEmail = $username.'@'.$mainDomain; - $newUserEntry = $this->userService->registerUser($displayname, $recoveryEmail, $username, $userEmail, $password); + sleep(2); + $this->userService->setAccountDataLocally($username, $userEmail, $newUserEntry['quota']); $this->userService->createHMEAlias($username, $userEmail); $this->userService->createNewDomainAlias($username, $userEmail); diff --git a/lib/Service/UserService.php b/lib/Service/UserService.php index 54c43925..1cf1ffdc 100644 --- a/lib/Service/UserService.php +++ b/lib/Service/UserService.php @@ -438,7 +438,6 @@ class UserService { * @return void */ public function setAccountDataLocally(string $uid, string $mailAddress, string $quota): void { - $user = $this->getUser($uid); if (is_null($user)) { $this->logger->error('User not found'); -- GitLab