diff --git a/appinfo/info.xml b/appinfo/info.xml index fdd6d0b909946cacf3a7333ec7daa794d19f060e..99285740c96f53881eac7e8b8e33b72bc25069be 100644 --- a/appinfo/info.xml +++ b/appinfo/info.xml @@ -25,7 +25,6 @@ OCA\EcloudAccounts\Settings\BetaSection - OCA\EcloudAccounts\Command\UpdateBlacklistedDomains OCA\EcloudAccounts\Command\Migrate2FASecrets OCA\EcloudAccounts\Command\MigrateWebmailAddressbooks OCA\EcloudAccounts\Command\MapActiveAttributetoLDAP diff --git a/l10n/de.js b/l10n/de.js index 26bd31c01c9cfc5cb14f2c378735626d9b00e786..92cbe4eebb4831be39489d2acd44c1dfa8be4cb7 100644 --- a/l10n/de.js +++ b/l10n/de.js @@ -79,12 +79,8 @@ OC.L10N.register( "Important:": "Das ist wichtig:", "For security reasons, a recovery email is required. If you decide to set it later, your account will be partially restricted.": "Aus Sicherheitsgründen ist eine Wiederherstellungs-E-Mail erforderlich. Wenn Sie sich entscheiden, diese später einzustellen, wird Ihr Konto teilweise eingeschränkt.", "Set a recovery email address": "Festlegen einer Wiederherstellungs-E-Mail-Adresse", - "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!", "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.", - "An error occurred while creating your account!": "Beim Anlegen Ihres Kontos ist ein Fehler aufgetreten!", - "The domain of this email address is blacklisted. Please provide another recovery address.": "Die Domäne dieser E-Mailadresse ist auf der Sperrliste. Bitte geben Sie eine andere E-Mailadresse an." + "An error occurred while creating your account!": "Beim Anlegen Ihres Kontos ist ein Fehler aufgetreten!" }, "nplurals=2; plural=(n != 1);"); diff --git a/l10n/de.json b/l10n/de.json index 581f0a74d6fe392e0ba0f1ac3c7fe8581fb7a154..8d5e2d082f3c0e47f94476443bba3726c67cdc6d 100644 --- a/l10n/de.json +++ b/l10n/de.json @@ -77,13 +77,9 @@ "Important:": "Das ist wichtig:", "For security reasons, a recovery email is required. If you decide to set it later, your account will be partially restricted.": "Aus Sicherheitsgründen ist eine Wiederherstellungs-E-Mail erforderlich. Wenn Sie sich entscheiden, diese später einzustellen, wird Ihr Konto teilweise eingeschränkt.", "Set a recovery email address": "Festlegen einer Wiederherstellungs-E-Mail-Adresse", - "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!", "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.", - "An error occurred while creating your account!": "Beim Anlegen Ihres Kontos ist ein Fehler aufgetreten!", - "The domain of this email address is blacklisted. Please provide another recovery address.": "Die Domäne dieser E-Mailadresse ist auf der Sperrliste. Bitte geben Sie eine andere E-Mailadresse an." + "An error occurred while creating your account!": "Beim Anlegen Ihres Kontos ist ein Fehler aufgetreten!" }, "pluralForm": "nplurals=2; plural=(n != 1);" } diff --git a/l10n/en.js b/l10n/en.js index b25bf722096e77033efb6c418d6718b57e761578..8030a730be324aeffc0d2a1f4437fdf49a0811a3 100644 --- a/l10n/en.js +++ b/l10n/en.js @@ -77,18 +77,13 @@ OC.L10N.register( "Success!": "Success!", "Your __username__@__domain__ account was successfully created.": "Your __username__@__domain__ account was successfully created.", "If you want to use your murena.io email in a mail app like Thunderbird, Outlook or another, please visit this page.": "If you want to use your murena.io email in a mail app like Thunderbird, Outlook or another, please visit this page.", - "Recovery email address is already taken.": "Recovery email address is already taken.", "Incorrect password length: Required length is 8 to 32": "Incorrect password length: Required length is 8 to 32", "Use an alternative email": "Use an alternative email", "Important:": "Important:", "For security reasons, a recovery email is required. If you decide to set it later, your account will be partially restricted.": "For security reasons, a recovery email is required. If you decide to set it later, your account will be partially restricted.", "Set a recovery email address": "Set a recovery email address", - "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!", "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.", - "An error occurred while creating your account!": "An error occurred while creating your account!", - "The domain of this email address is blacklisted. Please provide another recovery address.": "The domain of this email address is blacklisted. Please provide another recovery address." + "An error occurred while creating your account!": "An error occurred while creating your account!" }, "nplurals=2; plural=(n != 1);"); diff --git a/l10n/en.json b/l10n/en.json index be378a0a3f41d137df72a90ae03f860d3517c702..4ff11bf0e0e595c67999f1d16ac0f613dded45ed 100644 --- a/l10n/en.json +++ b/l10n/en.json @@ -79,13 +79,9 @@ "Important:": "Important:", "For security reasons, a recovery email is required. If you decide to set it later, your account will be partially restricted.": "For security reasons, a recovery email is required. If you decide to set it later, your account will be partially restricted.", "Set a recovery email address": "Set a recovery email address", - "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!", "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.", - "An error occurred while creating your account!": "An error occurred while creating your account!", - "The domain of this email address is blacklisted. Please provide another recovery address.": "The domain of this email address is blacklisted. Please provide another recovery address." + "An error occurred while creating your account!": "An error occurred while creating your account!" }, "pluralForm": "nplurals=2; plural=(n != 1);" } diff --git a/l10n/es.js b/l10n/es.js index 19fa33c78166b5c3f303859ed96c028886d6aced..5f992f49fb7c6ea4829c932782b155fb49b3c357 100644 --- a/l10n/es.js +++ b/l10n/es.js @@ -81,12 +81,8 @@ OC.L10N.register( "Important:": "Importante:", "For security reasons, a recovery email is required. If you decide to set it later, your account will be partially restricted.": "Por razones de seguridad, se requiere un correo electrónico de recuperación. Si decides configurarlo más tarde, tu cuenta quedará parcialmente restringida.", "Set a recovery email address": "Establecer una dirección de correo electrónico de recuperación", - "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!", "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.", - "An error occurred while creating your account!": "¡Hubo un error creando tu cuenta!", - "The domain of this email address is blacklisted. Please provide another recovery address.": "El dominio de esta dirección de correo electrónico está en lista negra. Por favor, proporciona otra dirección de recuperación." + "An error occurred while creating your account!": "¡Hubo un error creando tu cuenta!" }, "nplurals=2; plural=(n != 1);"); diff --git a/l10n/es.json b/l10n/es.json index 867f150d23f64979e34524a5d2607fb5073ef574..d4083680d12822f88775ed0ac5d3db079da5b445 100644 --- a/l10n/es.json +++ b/l10n/es.json @@ -80,13 +80,9 @@ "Important:": "Importante:", "For security reasons, a recovery email is required. If you decide to set it later, your account will be partially restricted.": "Por razones de seguridad, se requiere un correo electrónico de recuperación. Si decides configurarlo más tarde, tu cuenta quedará parcialmente restringida.", "Set a recovery email address": "Establecer una dirección de correo electrónico de recuperación", - "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!", "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.", - "An error occurred while creating your account!": "¡Hubo un error creando tu cuenta!", - "The domain of this email address is blacklisted. Please provide another recovery address.": "El dominio de esta dirección de correo electrónico está en lista negra. Por favor, proporciona otra dirección de recuperación." + "An error occurred while creating your account!": "¡Hubo un error creando tu cuenta!" }, "pluralForm": "nplurals=2; plural=(n != 1);" } diff --git a/l10n/fr.js b/l10n/fr.js index 6efaeeca5d3313287d35f2fa0b890a48e29cd1c6..f4e12ac11f66d0a61561a12bfa66937d3920d1b8 100644 --- a/l10n/fr.js +++ b/l10n/fr.js @@ -80,12 +80,8 @@ OC.L10N.register( "Important:": "Important :", "For security reasons, a recovery email is required. If you decide to set it later, your account will be partially restricted.": "Pour des raisons de sécurité, un courriel de récupération est nécessaire. Si vous décidez de le désactiver ultérieurement, votre compte sera partiellement restreint.", "Set a recovery email address": "Définir une adresse électronique de récupération", - "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é !", "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.", - "An error occurred while creating your account!": "Une erreur s'est produite lors de la création de votre compte!", - "The domain of this email address is blacklisted. Please provide another recovery address.": "Le domain de cette adresse e-mail est sur liste noire. Merci de bien vouloir fournir une autre adresse de récupération." + "An error occurred while creating your account!": "Une erreur s'est produite lors de la création de votre compte!" }, "nplurals=2; plural=(n != 1);"); diff --git a/l10n/fr.json b/l10n/fr.json index 19facc3020f5d4e52d2c1edefc1efaf4d59c0410..479b0cf10af8b7dbc3feb77ae758d290ecc5121c 100644 --- a/l10n/fr.json +++ b/l10n/fr.json @@ -79,13 +79,9 @@ "Important:": "Important :", "For security reasons, a recovery email is required. If you decide to set it later, your account will be partially restricted.": "Pour des raisons de sécurité, un courriel de récupération est nécessaire. Si vous décidez de le désactiver ultérieurement, votre compte sera partiellement restreint.", "Set a recovery email address": "Définir une adresse électronique de récupération", - "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é !", "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.", - "An error occurred while creating your account!": "Une erreur s'est produite lors de la création de votre compte!", - "The domain of this email address is blacklisted. Please provide another recovery address.": "Le domain de cette adresse e-mail est sur liste noire. Merci de bien vouloir fournir une autre adresse de récupération." + "An error occurred while creating your account!": "Une erreur s'est produite lors de la création de votre compte!" }, "pluralForm": "nplurals=2; plural=(n != 1);" } diff --git a/l10n/it.js b/l10n/it.js index 84c211cd0278b6b30f84a0ea53f76df4e5a2650e..6399df1e65b3544ad45631617eb8984da21715f1 100644 --- a/l10n/it.js +++ b/l10n/it.js @@ -80,12 +80,8 @@ OC.L10N.register( "Important:": "Importante:", "For security reasons, a recovery email is required. If you decide to set it later, your account will be partially restricted.": "Per motivi di sicurezza, è necessaria un'e-mail di recupero. Se si decide di impostarla in un secondo momento, l'account verrà parzialmente limitato.", "Set a recovery email address": "Impostare un indirizzo e-mail di recupero", - "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!", "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.", - "An error occurred while creating your account!": "Si è verificato un errore nella creazione dell'account!", - "The domain of this email address is blacklisted. Please provide another recovery address.": "Il dominio cui appartiene questo indirizzo e-mail è contenuto in una black list. Inserisci un indirizzo di recovery differente." + "An error occurred while creating your account!": "Si è verificato un errore nella creazione dell'account!" }, "nplurals=2; plural=(n != 1);"); diff --git a/l10n/it.json b/l10n/it.json index 2685c394b55388e6f571ca7c1675214645c6eeb0..840043dc10d2516e9b7ad647dc2c2db6a6ceca84 100644 --- a/l10n/it.json +++ b/l10n/it.json @@ -75,13 +75,9 @@ "Important:": "Importante:", "For security reasons, a recovery email is required. If you decide to set it later, your account will be partially restricted.": "Per motivi di sicurezza, è necessaria un'e-mail di recupero. Se si decide di impostarla in un secondo momento, l'account verrà parzialmente limitato.", "Set a recovery email address": "Impostare un indirizzo e-mail di recupero", - "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!", "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.", - "An error occurred while creating your account!": "Si è verificato un errore nella creazione dell'account!", - "The domain of this email address is blacklisted. Please provide another recovery address.": "Il dominio cui appartiene questo indirizzo e-mail è contenuto in una black list. Inserisci un indirizzo di recovery differente." + "An error occurred while creating your account!": "Si è verificato un errore nella creazione dell'account!" }, "pluralForm": "nplurals=2; plural=(n != 1);" } diff --git a/lib/Command/UpdateBlacklistedDomains.php b/lib/Command/UpdateBlacklistedDomains.php deleted file mode 100644 index 74bc1642c188e927c5fe1ac38f3adcd84fdee38c..0000000000000000000000000000000000000000 --- a/lib/Command/UpdateBlacklistedDomains.php +++ /dev/null @@ -1,39 +0,0 @@ -blackListService = $blackListService; - $this->logger = $logger; - } - - protected function configure() { - $this->setName(Application::APP_ID.':update-blacklisted-domains')->setDescription('Update blacklisted domains'); - } - - protected function execute(InputInterface $input, OutputInterface $output): int { - try { - $this->blackListService->updateBlacklistedDomains(); - $output->writeln('Updated blacklisted domains for creation.'); - } catch (\Throwable $th) { - $this->logger->error('Error while updating blacklisted domains. ' . $th->getMessage()); - $output->writeln('Error while updating blacklisted domains. '. $th->getMessage()); - } - return 1; - } -} diff --git a/lib/Controller/AccountController.php b/lib/Controller/AccountController.php index 4b1421d17f2ba05cf1c993969730716a12ceced2..6d78e275cc21d2b67c0aa0fef8e350f5526241f0 100644 --- a/lib/Controller/AccountController.php +++ b/lib/Controller/AccountController.php @@ -9,7 +9,6 @@ namespace OCA\EcloudAccounts\Controller; use Exception; use OCA\EcloudAccounts\AppInfo\Application; use OCA\EcloudAccounts\Exception\AddUsernameToCommonStoreException; -use OCA\EcloudAccounts\Exception\BlacklistedEmailException; use OCA\EcloudAccounts\Exception\LDAPUserCreationException; use OCA\EcloudAccounts\Exception\RecoveryEmailValidationException; use OCA\EcloudAccounts\Service\CaptchaService; @@ -142,7 +141,7 @@ class AccountController extends Controller { $username = mb_strtolower($username, 'UTF-8'); $mainDomain = $this->userService->getMainDomain(); $userEmail = $username.'@'.$mainDomain; - $this->userService->registerUser($displayname, $recoveryEmail, $username, $userEmail, $password); + $this->userService->registerUser($displayname, $recoveryEmail, $username, $userEmail, $password, $language); sleep(2); $this->userService->setAccountDataLocally($username, $userEmail); @@ -169,10 +168,10 @@ class AccountController extends Controller { $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 (BlacklistedEmailException | RecoveryEmailValidationException | Error $e) { + } catch (RecoveryEmailValidationException $e) { $this->logger->logException($e, ['app' => Application::APP_ID]); $response->setData(['message' => $e->getMessage(), 'success' => false]); - $response->setStatus(500); + $response->setStatus(400); } catch (AddUsernameToCommonStoreException $e) { $this->logger->logException($e, ['app' => Application::APP_ID]); $response->setStatus(200); diff --git a/lib/Event/BeforeUserRegisteredEvent.php b/lib/Event/BeforeUserRegisteredEvent.php new file mode 100644 index 0000000000000000000000000000000000000000..422873e74cc727e7d1b4437262ab495f6216327f --- /dev/null +++ b/lib/Event/BeforeUserRegisteredEvent.php @@ -0,0 +1,62 @@ + + * + * @author Murena SAS + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + +namespace OCA\EcloudAccounts\Event; + +use OCP\EventDispatcher\Event; + +/** + * Emitted before a new user is created on the back-end. + * + * @since 18.0.0 + */ +class BeforeUserRegisteredEvent extends Event { + + private $recoveryMailAddress; + private $language; + private $username; + private $displayName; + + public function __construct(string $username, string $displayName, string $recoveryMailAddress, string $language) { + $this->username = $username; + $this->displayName = $displayName; + $this->recoveryMailAddress = $recoveryMailAddress; + $this->language = $language; + } + public function getRecoveryEmail(): string { + return $this->recoveryMailAddress; + } + + public function getLanguage(): string { + return $this->language; + } + public function getUsername(): string { + return $this->username; + } + public function getDisplayName(): string { + return $this->displayName; + } +} diff --git a/lib/Exception/BlacklistedEmailException.php b/lib/Exception/BlacklistedEmailException.php deleted file mode 100644 index a435268bd78562f1339ae895b0b250f005df2783..0000000000000000000000000000000000000000 --- a/lib/Exception/BlacklistedEmailException.php +++ /dev/null @@ -1,9 +0,0 @@ -util = $util; - $this->ldapConnectionService = $LDAPConnectionService; $this->mailboxMapper = $mailboxMapper; $this->logger = $logger; $this->userService = $userService; + $this->LDAPConnectionService = $LDAPConnectionService; } public function handle(Event $event): void { @@ -57,15 +53,6 @@ class UserChangedListener implements IEventListener { $this->updateQuota($username, $backend, $quotaInBytes); } - if ($feature === self::RECOVERY_EMAIL_FEATURE) { - $recoveryEmail = $event->getValue(); - $recoveryEmailAttribute = [ - 'recoveryMailAddress' => $recoveryEmail - ]; - - $this->userService->updateAttributesInLDAP($username, $recoveryEmailAttribute); - } - if ($feature === self::ENABLED_FEATURE) { try { $this->userService->mapActiveAttributesInLDAP($username, $newValue); @@ -84,7 +71,7 @@ class UserChangedListener implements IEventListener { $quotaAttribute = [ 'quota' => $quotaInBytes ]; - $this->userService->updateAttributesInLDAP($username, $quotaAttribute); + $this->LDAPConnectionService->updateAttributesInLDAP($username, $quotaAttribute); } } catch (Exception $e) { $this->logger->error("Error setting quota for user $username " . $e->getMessage()); diff --git a/lib/Service/BlackListService.php b/lib/Service/BlackListService.php deleted file mode 100644 index ba9d0a219f91970540371d6915e72c96fea728a7..0000000000000000000000000000000000000000 --- a/lib/Service/BlackListService.php +++ /dev/null @@ -1,118 +0,0 @@ -appData = $appData; - $this->logger = $logger; - } - - /** - * Check if an email domain is blacklisted against a JSON list of disposable email domains. - * - * @param string $email The email address to check. - * @return bool True if the email domain is blacklisted, false otherwise. - */ - public function isBlacklistedEmail(string $email): bool { - if (!$this->ensureDocumentsFolder()) { - return false; - } - $blacklistedDomains = $this->getBlacklistedDomainData(); - if (empty($blacklistedDomains)) { - return false; - } - $emailParts = explode('@', $email); - $emailDomain = strtolower(end($emailParts)); - return in_array($emailDomain, $blacklistedDomains); - } - /** - * Update the blacklisted domains data by fetching it from a URL and saving it locally. - * - * @return void - */ - public function updateBlacklistedDomains(): void { - $blacklisted_domain_url = self::BLACKLISTED_DOMAINS_URL; - $json_data = file_get_contents($blacklisted_domain_url); - $this->setBlacklistedDomainsData($json_data); - } - /** - * Store blacklisted domain data in a file within AppData. - * - * @param string $data The data to be stored in the file. - * @return void - */ - private function setBlacklistedDomainsData(string $data): void { - $file = $this->getBlacklistedDomainsFile(); - $file->putContent($data); - } - /** - * Retrieve the blacklisted domain file path - * - * @return ISimpleFile - */ - private function getBlacklistedDomainsFile(): ISimpleFile { - try { - $currentFolder = $this->appData->getFolder('/'); - } catch (NotFoundException $e) { - $currentFolder = $this->appData->newFolder('/'); - } - $filename = self::BLACKLISTED_DOMAINS_FILE_NAME; - if ($currentFolder->fileExists($filename)) { - return $currentFolder->getFile($filename); - } - return $currentFolder->newFile($filename); - } - /** - * Retrieve the blacklisted domain data. - * - * @return array The array of blacklisted domains. - */ - public function getBlacklistedDomainData(): array { - $document = self::BLACKLISTED_DOMAINS_FILE_NAME; - $file = $this->getBlacklistedDomainsFile(); - try { - $blacklistedDomainsInJson = $file->getContent(); - if (empty($blacklistedDomainsInJson)) { - return []; - } - return json_decode($blacklistedDomainsInJson, true, 512, JSON_THROW_ON_ERROR); - } catch (NotFoundException $e) { - $this->logger->warning('Blacklisted domains file ' . $document . ' not found!'); - return []; - } catch (\Throwable $e) { - $this->logger->warning('Error decoding blacklisted domains file ' . $document . ': ' . $e->getMessage()); - return []; - } - } - - /** - * Ensure the specified folder exists within AppData. - * - * @return bool - */ - private function ensureDocumentsFolder(): bool { - try { - $this->appData->getFolder('/'); - } catch (NotFoundException $e) { - $this->logger->error(Application::APP_ID . ' AppData folder not found!'); - return false; - } catch (\RuntimeException $e) { - $this->logger->error(Application::APP_ID . ' AppData folder not found! Runtime Error: '.$e->getMessage()); - return false; - } - return true; - } -} diff --git a/lib/Service/LDAPConnectionService.php b/lib/Service/LDAPConnectionService.php index 35537b56d86ad1bc28b68ea85f077fae1b7bd63b..f7609941af21cc77e50b6ec2de74a61732f0fa0f 100644 --- a/lib/Service/LDAPConnectionService.php +++ b/lib/Service/LDAPConnectionService.php @@ -104,4 +104,22 @@ class LDAPConnectionService { public function getLdapQuota() { return $this->config->getSystemValue('default_quota', '1024'); } + public function updateAttributesInLDAP(string $username, array $attributes): void { + if (!$this->isLDAPEnabled()) { + return; + } + + $conn = $this->getLDAPConnection(); + $userDn = $this->username2dn($username); + + if ($userDn === false) { + throw new Exception('Could not find DN for username: ' . $username); + } + + if (!ldap_modify($conn, $userDn, $attributes)) { + throw new Exception('Could not modify user ' . $username . ' entry at LDAP server. Attributes: ' . print_r($attributes, true)); + } + + $this->closeLDAPConnection($conn); + } } diff --git a/lib/Service/UserService.php b/lib/Service/UserService.php index 1c1b85cb88c5fbf5789a4ab077fe5a086dee746a..8fb5b220fac41751c94041005da22c1593d6d500 100644 --- a/lib/Service/UserService.php +++ b/lib/Service/UserService.php @@ -8,18 +8,17 @@ require __DIR__ . '/../../vendor/autoload.php'; use Exception; use OCA\EcloudAccounts\AppInfo\Application; +use OCA\EcloudAccounts\Event\BeforeUserRegisteredEvent; use OCA\EcloudAccounts\Exception\AddUsernameToCommonStoreException; -use OCA\EcloudAccounts\Exception\BlacklistedEmailException; use OCA\EcloudAccounts\Exception\LDAPUserCreationException; -use OCA\EcloudAccounts\Exception\RecoveryEmailValidationException; use OCP\Defaults; +use OCP\EventDispatcher\IEventDispatcher; use OCP\IConfig; use OCP\ILogger; use OCP\IUser; use OCP\IUserManager; use OCP\L10N\IFactory; use OCP\Util; - use Throwable; use UnexpectedValueException; @@ -42,8 +41,8 @@ class UserService { private $apiConfig; /** @var LDAPConnectionService */ private $LDAPConnectionService; - private BlackListService $blackListService; - public function __construct($appName, IUserManager $userManager, IConfig $config, CurlService $curlService, ILogger $logger, Defaults $defaults, IFactory $l10nFactory, LDAPConnectionService $LDAPConnectionService, BlackListService $blackListService) { + private IEventDispatcher $dispatcher; + public function __construct($appName, IUserManager $userManager, IConfig $config, CurlService $curlService, ILogger $logger, Defaults $defaults, IFactory $l10nFactory, LDAPConnectionService $LDAPConnectionService, IEventDispatcher $dispatcher) { $this->userManager = $userManager; $this->config = $config; $this->appConfig = $this->config->getSystemValue($appName); @@ -52,7 +51,7 @@ class UserService { $this->defaults = $defaults; $this->l10nFactory = $l10nFactory; $this->LDAPConnectionService = $LDAPConnectionService; - $this->blackListService = $blackListService; + $this->dispatcher = $dispatcher; $commonServiceURL = $this->config->getSystemValue('common_services_url', ''); if (!empty($commonServiceURL)) { @@ -249,37 +248,14 @@ class UserService { * @throws Exception If the username or recovery email is already taken. * @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): void { + public function registerUser(string $displayname, string $recoveryEmail, string $username, string $userEmail, string $password, string $language = 'en'): void { if ($this->userExists($username) || $this->isUsernameTaken($username)) { throw new Exception("Username '$username' is already taken."); } - if (!empty($recoveryEmail)) { - $this->validateRecoveryEmail($recoveryEmail); - } + $this->dispatcher->dispatchTyped(new BeforeUserRegisteredEvent($username, $displayname, $recoveryEmail, $language)); $this->addNewUserToLDAP($displayname, $username, $userEmail, $password); } - /** - * Validates the recovery email address. - * - * @param string $recoveryEmail The recovery email address to be validated. - * @throws Exception If the recovery email address has an incorrect format, is already taken, or if the domain is disallowed. - * @return void - */ - public function validateRecoveryEmail(string $recoveryEmail): void { - if (!$this->isValidEmailFormat($recoveryEmail)) { - throw new RecoveryEmailValidationException('Recovery email address has an incorrect format.'); - } - if ($this->checkRecoveryEmailAvailable($recoveryEmail)) { - throw new RecoveryEmailValidationException('Recovery email address is already taken.'); - } - if ($this->isRecoveryEmailDomainDisallowed($recoveryEmail)) { - throw new RecoveryEmailValidationException('You cannot set an email address with a Murena domain as recovery email address.'); - } - if ($this->blackListService->isBlacklistedEmail($recoveryEmail)) { - throw new BlacklistedEmailException('The domain of this email address is blacklisted. Please provide another recovery address.'); - } - } /** * Add a new user to the LDAP directory. * @@ -319,59 +295,6 @@ class UserService { throw new LDAPUserCreationException("Error while adding entry to LDAP for username: " . $username . ' Error: ' . ldap_error($connection), ldap_errno($connection)); } } - /** - * Check if a recovery email address is available (not already taken by another user). - * - * @param string $recoveryEmail The recovery email address to check. - * - * @return bool True if the recovery email address is available, false otherwise. - */ - public function checkRecoveryEmailAvailable(string $recoveryEmail): bool { - $recoveryEmail = strtolower($recoveryEmail); - $users = $this->config->getUsersForUserValue('email-recovery', 'recovery-email', $recoveryEmail); - if(count($users)) { - return true; - } - $users = $this->config->getUsersForUserValue('email-recovery', 'unverified-recovery-email', $recoveryEmail); - if(count($users)) { - return true; - } - return false; - } - - /** - * Check if a recovery email address domain is restricted for some domains - * - * @param string $recoveryEmail The recovery email address to check. - * - * @return bool True if the recovery email address is disallowed, false otherwise. - */ - public function isRecoveryEmailDomainDisallowed(string $recoveryEmail): bool { - - $recoveryEmail = strtolower($recoveryEmail); - - $emailParts = explode('@', $recoveryEmail); - $domain = $emailParts[1] ?? ''; - - $legacyDomain = $this->getLegacyDomain(); - $mainDomain = $this->getMainDomain(); - - $restrictedDomains = [ $legacyDomain, $mainDomain ]; - - return in_array($domain, $restrictedDomains); - } - - /** - * Check if a recovery email address is in valid format - * - * @param string $recoveryEmail The recovery email address to check. - * - * @return bool True if the recovery email address is valid, false otherwise. - */ - public function isValidEmailFormat(string $recoveryEmail): bool { - return filter_var($recoveryEmail, FILTER_VALIDATE_EMAIL) !== false; - } - /** * Create a Hide My Email (HME) alias for a user. * @@ -528,7 +451,7 @@ class UserService { public function mapActiveAttributesInLDAP(string $username, bool $isEnabled): void { $userActiveAttributes = $this->getActiveAttributes($isEnabled); - $this->updateAttributesInLDAP($username, $userActiveAttributes); + $this->LDAPConnectionService->updateAttributesInLDAP($username, $userActiveAttributes); } private function getActiveAttributes(bool $isEnabled): array { @@ -537,26 +460,6 @@ class UserService { 'mailActive' => $isEnabled ? 'TRUE' : 'FALSE', ]; } - - public function updateAttributesInLDAP(string $username, array $attributes): void { - if (!$this->LDAPConnectionService->isLDAPEnabled()) { - return; - } - - $conn = $this->LDAPConnectionService->getLDAPConnection(); - $userDn = $this->LDAPConnectionService->username2dn($username); - - if ($userDn === false) { - throw new Exception('Could not find DN for username: ' . $username); - } - - if (!ldap_modify($conn, $userDn, $attributes)) { - throw new Exception('Could not modify user ' . $username . ' entry at LDAP server. Attributes: ' . print_r($attributes, true)); - } - - $this->LDAPConnectionService->closeLDAPConnection($conn); - } - private function getDefaultQuota() { return $this->config->getSystemValueInt('default_quota_in_megabytes', 1024); }