From ac36af26a922201bde484f124d3d7e6b93d7d332 Mon Sep 17 00:00:00 2001 From: Avinash Gusain Date: Fri, 28 Jun 2024 13:22:37 +0530 Subject: [PATCH 01/19] limit number of attempt --- .../TooManyVerificationAttemptsException.php | 11 +++++++++ lib/Service/RecoveryEmailService.php | 23 ++++++++++++++++++- 2 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 lib/Exception/TooManyVerificationAttemptsException.php diff --git a/lib/Exception/TooManyVerificationAttemptsException.php b/lib/Exception/TooManyVerificationAttemptsException.php new file mode 100644 index 0000000..62db28e --- /dev/null +++ b/lib/Exception/TooManyVerificationAttemptsException.php @@ -0,0 +1,11 @@ +logger = $logger; $this->config = $config; $this->appName = $appName; $this->LDAPConnectionService = $LDAPConnectionService; + $this->session = $session; $this->userManager = $userManager; $this->mailer = $mailer; $this->l10nFactory = $l10nFactory; @@ -82,6 +85,21 @@ class RecoveryEmailService { public function validateRecoveryEmail(string $username, string $recoveryEmail) : bool { $user = $this->userManager->get($username); $email = $user->getEMailAddress(); + + $attemptKey = "recovery_email_attempts_$username"; + $attempts = $this->session->get($attemptKey, []); + $currentTime = time(); + + // Filter out attempts older than 1 hour (3600 seconds) + $attempts = array_filter($attempts, function($attemptTime) use ($currentTime) { + return ($currentTime - $attemptTime) <= 3600; + }); + + if (count($attempts) >= 3) { + $this->logger->info("User ID $username has exceeded the maximum number of verification attempts."); + throw new TooManyVerificationAttemptsException(); + } + if (!empty($recoveryEmail)) { if (!filter_var($recoveryEmail, FILTER_VALIDATE_EMAIL)) { $this->logger->info("User $username's requested recovery email does not match email format"); @@ -103,6 +121,9 @@ class RecoveryEmailService { $this->logger->info("User ID $username's requested recovery email address domain is blacklisted. Please provide another recovery address."); throw new BlacklistedEmailException(); } + // Add current attempt to the session and save it + $attempts[] = $currentTime; + $this->session->set($attemptKey, $attempts); } return true; } -- GitLab From b51fdf10d4c848f76132f86400baa498bbcb688f Mon Sep 17 00:00:00 2001 From: Avinash Gusain Date: Fri, 28 Jun 2024 13:26:09 +0530 Subject: [PATCH 02/19] lint fix --- lib/Service/RecoveryEmailService.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Service/RecoveryEmailService.php b/lib/Service/RecoveryEmailService.php index d8ce585..430fed9 100644 --- a/lib/Service/RecoveryEmailService.php +++ b/lib/Service/RecoveryEmailService.php @@ -91,7 +91,7 @@ class RecoveryEmailService { $currentTime = time(); // Filter out attempts older than 1 hour (3600 seconds) - $attempts = array_filter($attempts, function($attemptTime) use ($currentTime) { + $attempts = array_filter($attempts, function ($attemptTime) use ($currentTime) { return ($currentTime - $attemptTime) <= 3600; }); -- GitLab From e7cf214ef7d5d331a96e55c158eb559813258e86 Mon Sep 17 00:00:00 2001 From: Avinash Gusain Date: Fri, 28 Jun 2024 17:50:46 +0530 Subject: [PATCH 03/19] limit verification email --- lib/Controller/EmailRecoveryController.php | 13 ++++++++++++- lib/Service/RecoveryEmailService.php | 12 ++++++++++-- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/lib/Controller/EmailRecoveryController.php b/lib/Controller/EmailRecoveryController.php index 776fd43..973a764 100644 --- a/lib/Controller/EmailRecoveryController.php +++ b/lib/Controller/EmailRecoveryController.php @@ -30,6 +30,7 @@ use OCA\EmailRecovery\Exception\InvalidRecoveryEmailException; use OCA\EmailRecovery\Exception\MurenaDomainDisallowedException; use OCA\EmailRecovery\Exception\RecoveryEmailAlreadyFoundException; use OCA\EmailRecovery\Exception\SameRecoveryEmailAsEmailException; +use OCA\EmailRecovery\Exception\TooManyVerificationAttemptsException; use OCA\EmailRecovery\Service\RecoveryEmailService; use OCP\AppFramework\Controller; use OCP\AppFramework\Http\JSONResponse; @@ -156,7 +157,17 @@ class EmailRecoveryController extends Controller { $response->setData(['message' => $this->l->t('Recovery email is verified.')]); return $response; } - $this->recoveryEmailService->sendVerificationEmail($userId, $recoveryEmail); + try { + if ($this->recoveryEmailService->limitVerficationEmail($userId, $recoveryEmail)) { + $this->recoveryEmailService->sendVerificationEmail($userId, $recoveryEmail); + } + } catch (Exception $e) { + $response->setStatus(500); + if ($e instanceof TooManyVerificationAttemptsException) { + $response->setStatus(400); + $response->setData(['message' => $this->l->t('Too many verification emails')]); + } + } return $response; } diff --git a/lib/Service/RecoveryEmailService.php b/lib/Service/RecoveryEmailService.php index 430fed9..db6aaf6 100644 --- a/lib/Service/RecoveryEmailService.php +++ b/lib/Service/RecoveryEmailService.php @@ -82,7 +82,7 @@ class RecoveryEmailService { public function deleteUnverifiedRecoveryEmail(string $username) : void { $this->config->deleteUserValue($username, $this->appName, 'unverified-recovery-email'); } - public function validateRecoveryEmail(string $username, string $recoveryEmail) : bool { + public function limitVerficationEmail(string $username, string $recoveryEmail) : bool { $user = $this->userManager->get($username); $email = $user->getEMailAddress(); @@ -98,7 +98,15 @@ class RecoveryEmailService { if (count($attempts) >= 3) { $this->logger->info("User ID $username has exceeded the maximum number of verification attempts."); throw new TooManyVerificationAttemptsException(); - } + } + $attempts[] = $currentTime; + $this->session->set($attemptKey, $attempts); + + return true; + } + public function validateRecoveryEmail(string $username, string $recoveryEmail) : bool { + $user = $this->userManager->get($username); + $email = $user->getEMailAddress(); if (!empty($recoveryEmail)) { if (!filter_var($recoveryEmail, FILTER_VALIDATE_EMAIL)) { -- GitLab From c9ae700c33c19759537a4965e56b486ff27a0d8a Mon Sep 17 00:00:00 2001 From: Avinash Gusain Date: Fri, 28 Jun 2024 17:53:26 +0530 Subject: [PATCH 04/19] lint fix --- lib/Controller/EmailRecoveryController.php | 6 +++--- lib/Service/RecoveryEmailService.php | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/Controller/EmailRecoveryController.php b/lib/Controller/EmailRecoveryController.php index 973a764..a343595 100644 --- a/lib/Controller/EmailRecoveryController.php +++ b/lib/Controller/EmailRecoveryController.php @@ -157,9 +157,9 @@ class EmailRecoveryController extends Controller { $response->setData(['message' => $this->l->t('Recovery email is verified.')]); return $response; } - try { + try { if ($this->recoveryEmailService->limitVerficationEmail($userId, $recoveryEmail)) { - $this->recoveryEmailService->sendVerificationEmail($userId, $recoveryEmail); + $this->recoveryEmailService->sendVerificationEmail($userId, $recoveryEmail); } } catch (Exception $e) { $response->setStatus(500); @@ -167,7 +167,7 @@ class EmailRecoveryController extends Controller { $response->setStatus(400); $response->setData(['message' => $this->l->t('Too many verification emails')]); } - } + } return $response; } diff --git a/lib/Service/RecoveryEmailService.php b/lib/Service/RecoveryEmailService.php index db6aaf6..e31c7bb 100644 --- a/lib/Service/RecoveryEmailService.php +++ b/lib/Service/RecoveryEmailService.php @@ -98,12 +98,12 @@ class RecoveryEmailService { if (count($attempts) >= 3) { $this->logger->info("User ID $username has exceeded the maximum number of verification attempts."); throw new TooManyVerificationAttemptsException(); - } + } $attempts[] = $currentTime; $this->session->set($attemptKey, $attempts); return true; - } + } public function validateRecoveryEmail(string $username, string $recoveryEmail) : bool { $user = $this->userManager->get($username); $email = $user->getEMailAddress(); -- GitLab From 6909b058e703412da5e49c1b5c64d52a3ee67c53 Mon Sep 17 00:00:00 2001 From: Avinash Gusain Date: Fri, 28 Jun 2024 17:56:12 +0530 Subject: [PATCH 05/19] lint fix --- lib/Service/RecoveryEmailService.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/lib/Service/RecoveryEmailService.php b/lib/Service/RecoveryEmailService.php index e31c7bb..4b03ed2 100644 --- a/lib/Service/RecoveryEmailService.php +++ b/lib/Service/RecoveryEmailService.php @@ -107,7 +107,6 @@ class RecoveryEmailService { public function validateRecoveryEmail(string $username, string $recoveryEmail) : bool { $user = $this->userManager->get($username); $email = $user->getEMailAddress(); - if (!empty($recoveryEmail)) { if (!filter_var($recoveryEmail, FILTER_VALIDATE_EMAIL)) { $this->logger->info("User $username's requested recovery email does not match email format"); @@ -129,9 +128,6 @@ class RecoveryEmailService { $this->logger->info("User ID $username's requested recovery email address domain is blacklisted. Please provide another recovery address."); throw new BlacklistedEmailException(); } - // Add current attempt to the session and save it - $attempts[] = $currentTime; - $this->session->set($attemptKey, $attempts); } return true; } -- GitLab From ad46b66ae0459158383a9c0c547411598ee54a25 Mon Sep 17 00:00:00 2001 From: Avinash Gusain Date: Fri, 28 Jun 2024 18:01:37 +0530 Subject: [PATCH 06/19] lint fix --- lib/Service/RecoveryEmailService.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/Service/RecoveryEmailService.php b/lib/Service/RecoveryEmailService.php index 4b03ed2..58eaaf4 100644 --- a/lib/Service/RecoveryEmailService.php +++ b/lib/Service/RecoveryEmailService.php @@ -87,7 +87,10 @@ class RecoveryEmailService { $email = $user->getEMailAddress(); $attemptKey = "recovery_email_attempts_$username"; - $attempts = $this->session->get($attemptKey, []); + $attempts = $this->session->get($attemptKey); + if (!is_array($attempts)) { + $attempts = []; + } $currentTime = time(); // Filter out attempts older than 1 hour (3600 seconds) -- GitLab From 369caa93f175ddd33cd82b4cb44bcabc56b6381f Mon Sep 17 00:00:00 2001 From: Avinash Gusain Date: Fri, 28 Jun 2024 18:10:40 +0530 Subject: [PATCH 07/19] fix error msg --- src/App.vue | 1 - 1 file changed, 1 deletion(-) diff --git a/src/App.vue b/src/App.vue index 49573a6..840c27d 100644 --- a/src/App.vue +++ b/src/App.vue @@ -94,7 +94,6 @@ export default { if (err.response && err.response.data.message) { this.errorKey = err.response.data.message if (err.response.status === 400) { - this.errorKey = '' this.recoveryEmailVerificationStatus = true } } -- GitLab From 22cbf71a6fdfc5c9e87d8d27bfe5a3eaa45d2b71 Mon Sep 17 00:00:00 2001 From: Avinash Gusain Date: Fri, 28 Jun 2024 18:16:15 +0530 Subject: [PATCH 08/19] fix error msg --- src/App.vue | 1 + 1 file changed, 1 insertion(+) diff --git a/src/App.vue b/src/App.vue index 840c27d..49573a6 100644 --- a/src/App.vue +++ b/src/App.vue @@ -94,6 +94,7 @@ export default { if (err.response && err.response.data.message) { this.errorKey = err.response.data.message if (err.response.status === 400) { + this.errorKey = '' this.recoveryEmailVerificationStatus = true } } -- GitLab From 11fa4ab5e20946584fbf30c9f4c3d64fe9c49833 Mon Sep 17 00:00:00 2001 From: Avinash Gusain Date: Fri, 28 Jun 2024 18:23:30 +0530 Subject: [PATCH 09/19] fix error msg --- src/App.vue | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/App.vue b/src/App.vue index 49573a6..2b51395 100644 --- a/src/App.vue +++ b/src/App.vue @@ -94,8 +94,7 @@ export default { if (err.response && err.response.data.message) { this.errorKey = err.response.data.message if (err.response.status === 400) { - this.errorKey = '' - this.recoveryEmailVerificationStatus = true + this.recoveryEmailVerificationStatus = false } } this.showError = true -- GitLab From 011618fdf36a0f27dd2685af2ef8ac097a1cb1ea Mon Sep 17 00:00:00 2001 From: Avinash Gusain Date: Mon, 1 Jul 2024 13:49:22 +0530 Subject: [PATCH 10/19] added button --- src/App.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/App.vue b/src/App.vue index 2b51395..840c27d 100644 --- a/src/App.vue +++ b/src/App.vue @@ -94,7 +94,7 @@ export default { if (err.response && err.response.data.message) { this.errorKey = err.response.data.message if (err.response.status === 400) { - this.recoveryEmailVerificationStatus = false + this.recoveryEmailVerificationStatus = true } } this.showError = true -- GitLab From 907e41d9eeca2d84b5c0bfcd21588529d391e546 Mon Sep 17 00:00:00 2001 From: Avinash Gusain Date: Mon, 1 Jul 2024 18:18:42 +0530 Subject: [PATCH 11/19] error code 429 --- lib/Controller/EmailRecoveryController.php | 2 +- src/App.vue | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/Controller/EmailRecoveryController.php b/lib/Controller/EmailRecoveryController.php index a343595..26d3317 100644 --- a/lib/Controller/EmailRecoveryController.php +++ b/lib/Controller/EmailRecoveryController.php @@ -164,7 +164,7 @@ class EmailRecoveryController extends Controller { } catch (Exception $e) { $response->setStatus(500); if ($e instanceof TooManyVerificationAttemptsException) { - $response->setStatus(400); + $response->setStatus(429); $response->setData(['message' => $this->l->t('Too many verification emails')]); } } diff --git a/src/App.vue b/src/App.vue index 840c27d..504f0a0 100644 --- a/src/App.vue +++ b/src/App.vue @@ -94,8 +94,12 @@ export default { if (err.response && err.response.data.message) { this.errorKey = err.response.data.message if (err.response.status === 400) { + this.errorKey = '' this.recoveryEmailVerificationStatus = true } + if (err.response.status === 429) { + this.recoveryEmailVerificationStatus = false + } } this.showError = true }).finally(() => { -- GitLab From f5072f2fc83766829ad3690a3d0565da6b6042bd Mon Sep 17 00:00:00 2001 From: Avinash Gusain Date: Mon, 1 Jul 2024 18:29:33 +0530 Subject: [PATCH 12/19] translation added --- l10n/de.js | 4 +++- l10n/de.json | 4 +++- l10n/de_DE.js | 4 +++- l10n/de_DE.json | 4 +++- l10n/en.js | 4 +++- l10n/en.json | 4 +++- l10n/es.js | 4 +++- l10n/es.json | 4 +++- l10n/fr.js | 4 +++- l10n/fr.json | 4 +++- l10n/it.js | 4 +++- l10n/it.json | 4 +++- 12 files changed, 36 insertions(+), 12 deletions(-) diff --git a/l10n/de.js b/l10n/de.js index a123178..1d9aa50 100644 --- a/l10n/de.js +++ b/l10n/de.js @@ -32,6 +32,8 @@ OC.L10N.register( "Could not verify recovery email because the token is invalid": "Wiederherstellungs-E-Mail konnte nicht überprüft werden, da das Token ungültig ist", "Unverified recovery email:": "Nicht überprüfte Wiederherstellungs-E-Mail:", "Please set a recovery email address.": "Bitte geben Sie eine Wiederherstellungs-E-Mail-Adresse an.", - "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." + "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.", + "Too many verification emails.": "Zu viele Bestätigungs-E-Mails.", + "Too many verification emails.": "Zu viele Bestätigungs-E-Mails." }, "nplurals=2; plural=n != 1;"); diff --git a/l10n/de.json b/l10n/de.json index d7eed73..4619167 100644 --- a/l10n/de.json +++ b/l10n/de.json @@ -30,6 +30,8 @@ "Could not verify recovery email because the token is invalid": "Wiederherstellungs-E-Mail konnte nicht überprüft werden, da das Token ungültig ist", "Unverified recovery email:": "Nicht überprüfte Wiederherstellungs-E-Mail:", "Please set a recovery email address.": "Bitte geben Sie eine Wiederherstellungs-E-Mail-Adresse an.", - "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." + "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.", + "Too many verification emails.": "Zu viele Bestätigungs-E-Mails.", + "Too many verification emails.": "Zu viele Bestätigungs-E-Mails." },"pluralForm" :"nplurals=2; plural=n != 1;" } \ No newline at end of file diff --git a/l10n/de_DE.js b/l10n/de_DE.js index a123178..1d9aa50 100644 --- a/l10n/de_DE.js +++ b/l10n/de_DE.js @@ -32,6 +32,8 @@ OC.L10N.register( "Could not verify recovery email because the token is invalid": "Wiederherstellungs-E-Mail konnte nicht überprüft werden, da das Token ungültig ist", "Unverified recovery email:": "Nicht überprüfte Wiederherstellungs-E-Mail:", "Please set a recovery email address.": "Bitte geben Sie eine Wiederherstellungs-E-Mail-Adresse an.", - "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." + "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.", + "Too many verification emails.": "Zu viele Bestätigungs-E-Mails.", + "Too many verification emails.": "Zu viele Bestätigungs-E-Mails." }, "nplurals=2; plural=n != 1;"); diff --git a/l10n/de_DE.json b/l10n/de_DE.json index d7eed73..4619167 100644 --- a/l10n/de_DE.json +++ b/l10n/de_DE.json @@ -30,6 +30,8 @@ "Could not verify recovery email because the token is invalid": "Wiederherstellungs-E-Mail konnte nicht überprüft werden, da das Token ungültig ist", "Unverified recovery email:": "Nicht überprüfte Wiederherstellungs-E-Mail:", "Please set a recovery email address.": "Bitte geben Sie eine Wiederherstellungs-E-Mail-Adresse an.", - "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." + "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.", + "Too many verification emails.": "Zu viele Bestätigungs-E-Mails.", + "Too many verification emails.": "Zu viele Bestätigungs-E-Mails." },"pluralForm" :"nplurals=2; plural=n != 1;" } \ No newline at end of file diff --git a/l10n/en.js b/l10n/en.js index 3b7fc65..716c6f7 100644 --- a/l10n/en.js +++ b/l10n/en.js @@ -29,6 +29,8 @@ OC.L10N.register( "Please verify your recovery email address to fully enjoy your murena.io account.": "Please verify your recovery email address to fully enjoy your murena.io account.", "VERIFY RECOVERY EMAIL NOW": "VERIFY RECOVERY EMAIL NOW", "Please set a recovery email address.": "Please set a recovery email address.", - "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." + "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.", + "Too many verification emails.": "Too many verification emails.", + "Too many verification emails.": "Too many verification emails." }, "nplurals=2; plural=(n != 1);"); diff --git a/l10n/en.json b/l10n/en.json index 46c1dbf..ed66004 100644 --- a/l10n/en.json +++ b/l10n/en.json @@ -30,7 +30,9 @@ "Please verify your recovery email address to fully enjoy your murena.io account.": "Please verify your recovery email address to fully enjoy your murena.io account.", "VERIFY RECOVERY EMAIL NOW": "VERIFY RECOVERY EMAIL NOW", "Please set a recovery email address.": "Please set a recovery email address.", - "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." + "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.", + "Too many verification emails.": "Too many verification emails.", + "Too many verification emails.": "Too many verification emails." }, "pluralForm": "nplurals=2; plural=(n != 1);" } \ No newline at end of file diff --git a/l10n/es.js b/l10n/es.js index 1d0f7c1..89ef861 100644 --- a/l10n/es.js +++ b/l10n/es.js @@ -32,6 +32,8 @@ OC.L10N.register( "Could not verify recovery email because the token is invalid": "No se pudo verificar el correo electrónico de recuperación porque el token no es válido", "Unverified recovery email:": "Correo electrónico de recuperación no verificado:", "Please set a recovery email address.": "Por favor configura un correo electrónico para recuperación.", - "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." + "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.", + "Too many verification emails.": "Demasiados correos electrónicos de verificación.", + "Too many verification emails.": "Demasiados correos electrónicos de verificación." }, "nplurals=2; plural=n != 1;"); diff --git a/l10n/es.json b/l10n/es.json index a235c02..82ff03b 100644 --- a/l10n/es.json +++ b/l10n/es.json @@ -30,7 +30,9 @@ "Could not verify recovery email because the token is invalid": "No se pudo verificar el correo electrónico de recuperación porque el token no es válido", "Unverified recovery email:": "Correo electrónico de recuperación no verificado:", "Please set a recovery email address.": "Por favor configura un correo electrónico para recuperación.", - "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." + "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.", + "Too many verification emails.": "Demasiados correos electrónicos de verificación.", + "Too many verification emails.": "Demasiados correos electrónicos de verificación." },"pluralForm" :"nplurals=2; plural=n != 1;" } \ No newline at end of file diff --git a/l10n/fr.js b/l10n/fr.js index 44f37ae..5c7b944 100644 --- a/l10n/fr.js +++ b/l10n/fr.js @@ -32,6 +32,8 @@ OC.L10N.register( "Could not verify recovery email because the token is invalid": "Impossible de vérifier l'e-mail de récupération car le jeton n'est pas valide.", "Unverified recovery email:": "E-mail de récupération non vérifié :", "Please set a recovery email address.": "Merci d'ajouter une adresse e-mail de récupération.", - "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." + "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.", + "Too many verification emails.": "Trop de courriels de vérification.", + "Too many verification emails.": "Trop de courriels de vérification." }, "nplurals=2; plural=n > 1;"); diff --git a/l10n/fr.json b/l10n/fr.json index c49d475..289b94e 100644 --- a/l10n/fr.json +++ b/l10n/fr.json @@ -30,7 +30,9 @@ "Could not verify recovery email because the token is invalid": "Impossible de vérifier l'e-mail de récupération car le jeton n'est pas valide.", "Unverified recovery email:": "E-mail de récupération non vérifié :", "Please set a recovery email address.": "Merci d'ajouter une adresse e-mail de récupération.", - "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." + "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.", + "Too many verification emails.": "Too many verification emails.", + "Too many verification emails.": "Too many verification emails." },"pluralForm" :"nplurals=2; plural=n > 1;" } \ No newline at end of file diff --git a/l10n/it.js b/l10n/it.js index eaa598a..b8581d0 100644 --- a/l10n/it.js +++ b/l10n/it.js @@ -32,6 +32,8 @@ OC.L10N.register( "Could not verify recovery email because the token is invalid": "Impossibile verificare l'e-mail di recovery perché il token non è valido", "Unverified recovery email:": "E-mail di recovery non verificata:", "Please set a recovery email address.": "Imposta un indirizzo e-mail di recovery.", - "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." + "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.", + "Too many verification emails.": "Troppe e-mail di verifica.", + "Too many verification emails.": "Troppe e-mail di verifica." }, "nplurals=2; plural=n != 1;"); diff --git a/l10n/it.json b/l10n/it.json index 653ed50..aa34eec 100644 --- a/l10n/it.json +++ b/l10n/it.json @@ -30,6 +30,8 @@ "Could not verify recovery email because the token is invalid": "Impossibile verificare l'e-mail di recovery perché il token non è valido", "Unverified recovery email:": "E-mail di recovery non verificata:", "Please set a recovery email address.": "Imposta un indirizzo e-mail di recovery.", - "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." + "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.", + "Too many verification emails.": "Too many verification emails.", + "Too many verification emails.": "Too many verification emails." },"pluralForm" :"nplurals=2; plural=n != 1;" } \ No newline at end of file -- GitLab From de543b1dcd80209031153a71fa4f04768ad70560 Mon Sep 17 00:00:00 2001 From: Avinash Gusain Date: Mon, 1 Jul 2024 18:31:48 +0530 Subject: [PATCH 13/19] translation added --- l10n/de.js | 1 - l10n/de.json | 1 - l10n/de_DE.js | 1 - l10n/de_DE.json | 1 - l10n/en.js | 3 +-- l10n/en.json | 3 +-- l10n/es.js | 1 - l10n/es.json | 1 - l10n/fr.js | 1 - l10n/fr.json | 1 - l10n/it.js | 1 - l10n/it.json | 1 - 12 files changed, 2 insertions(+), 14 deletions(-) diff --git a/l10n/de.js b/l10n/de.js index 1d9aa50..ff9a990 100644 --- a/l10n/de.js +++ b/l10n/de.js @@ -33,7 +33,6 @@ OC.L10N.register( "Unverified recovery email:": "Nicht überprüfte Wiederherstellungs-E-Mail:", "Please set a recovery email address.": "Bitte geben Sie eine Wiederherstellungs-E-Mail-Adresse an.", "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.", - "Too many verification emails.": "Zu viele Bestätigungs-E-Mails.", "Too many verification emails.": "Zu viele Bestätigungs-E-Mails." }, "nplurals=2; plural=n != 1;"); diff --git a/l10n/de.json b/l10n/de.json index 4619167..c2cfc90 100644 --- a/l10n/de.json +++ b/l10n/de.json @@ -31,7 +31,6 @@ "Unverified recovery email:": "Nicht überprüfte Wiederherstellungs-E-Mail:", "Please set a recovery email address.": "Bitte geben Sie eine Wiederherstellungs-E-Mail-Adresse an.", "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.", - "Too many verification emails.": "Zu viele Bestätigungs-E-Mails.", "Too many verification emails.": "Zu viele Bestätigungs-E-Mails." },"pluralForm" :"nplurals=2; plural=n != 1;" } \ No newline at end of file diff --git a/l10n/de_DE.js b/l10n/de_DE.js index 1d9aa50..ff9a990 100644 --- a/l10n/de_DE.js +++ b/l10n/de_DE.js @@ -33,7 +33,6 @@ OC.L10N.register( "Unverified recovery email:": "Nicht überprüfte Wiederherstellungs-E-Mail:", "Please set a recovery email address.": "Bitte geben Sie eine Wiederherstellungs-E-Mail-Adresse an.", "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.", - "Too many verification emails.": "Zu viele Bestätigungs-E-Mails.", "Too many verification emails.": "Zu viele Bestätigungs-E-Mails." }, "nplurals=2; plural=n != 1;"); diff --git a/l10n/de_DE.json b/l10n/de_DE.json index 4619167..c2cfc90 100644 --- a/l10n/de_DE.json +++ b/l10n/de_DE.json @@ -31,7 +31,6 @@ "Unverified recovery email:": "Nicht überprüfte Wiederherstellungs-E-Mail:", "Please set a recovery email address.": "Bitte geben Sie eine Wiederherstellungs-E-Mail-Adresse an.", "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.", - "Too many verification emails.": "Zu viele Bestätigungs-E-Mails.", "Too many verification emails.": "Zu viele Bestätigungs-E-Mails." },"pluralForm" :"nplurals=2; plural=n != 1;" } \ No newline at end of file diff --git a/l10n/en.js b/l10n/en.js index 716c6f7..00b1f85 100644 --- a/l10n/en.js +++ b/l10n/en.js @@ -30,7 +30,6 @@ OC.L10N.register( "VERIFY RECOVERY EMAIL NOW": "VERIFY RECOVERY EMAIL NOW", "Please set a recovery email address.": "Please set a recovery email address.", "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.", - "Too many verification emails.": "Too many verification emails.", - "Too many verification emails.": "Too many verification emails." + "Too many verification emails.": "Too many verification emails." }, "nplurals=2; plural=(n != 1);"); diff --git a/l10n/en.json b/l10n/en.json index ed66004..cea2af7 100644 --- a/l10n/en.json +++ b/l10n/en.json @@ -31,8 +31,7 @@ "VERIFY RECOVERY EMAIL NOW": "VERIFY RECOVERY EMAIL NOW", "Please set a recovery email address.": "Please set a recovery email address.", "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.", - "Too many verification emails.": "Too many verification emails.", - "Too many verification emails.": "Too many verification emails." + "Too many verification emails.": "Too many verification emails." }, "pluralForm": "nplurals=2; plural=(n != 1);" } \ No newline at end of file diff --git a/l10n/es.js b/l10n/es.js index 89ef861..0d05bd8 100644 --- a/l10n/es.js +++ b/l10n/es.js @@ -33,7 +33,6 @@ OC.L10N.register( "Unverified recovery email:": "Correo electrónico de recuperación no verificado:", "Please set a recovery email address.": "Por favor configura un correo electrónico para recuperación.", "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.", - "Too many verification emails.": "Demasiados correos electrónicos de verificación.", "Too many verification emails.": "Demasiados correos electrónicos de verificación." }, "nplurals=2; plural=n != 1;"); diff --git a/l10n/es.json b/l10n/es.json index 82ff03b..819dd12 100644 --- a/l10n/es.json +++ b/l10n/es.json @@ -31,7 +31,6 @@ "Unverified recovery email:": "Correo electrónico de recuperación no verificado:", "Please set a recovery email address.": "Por favor configura un correo electrónico para recuperación.", "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.", - "Too many verification emails.": "Demasiados correos electrónicos de verificación.", "Too many verification emails.": "Demasiados correos electrónicos de verificación." },"pluralForm" :"nplurals=2; plural=n != 1;" diff --git a/l10n/fr.js b/l10n/fr.js index 5c7b944..3085599 100644 --- a/l10n/fr.js +++ b/l10n/fr.js @@ -33,7 +33,6 @@ OC.L10N.register( "Unverified recovery email:": "E-mail de récupération non vérifié :", "Please set a recovery email address.": "Merci d'ajouter une adresse e-mail de récupération.", "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.", - "Too many verification emails.": "Trop de courriels de vérification.", "Too many verification emails.": "Trop de courriels de vérification." }, "nplurals=2; plural=n > 1;"); diff --git a/l10n/fr.json b/l10n/fr.json index 289b94e..55ec894 100644 --- a/l10n/fr.json +++ b/l10n/fr.json @@ -31,7 +31,6 @@ "Unverified recovery email:": "E-mail de récupération non vérifié :", "Please set a recovery email address.": "Merci d'ajouter une adresse e-mail de récupération.", "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.", - "Too many verification emails.": "Too many verification emails.", "Too many verification emails.": "Too many verification emails." },"pluralForm" :"nplurals=2; plural=n > 1;" diff --git a/l10n/it.js b/l10n/it.js index b8581d0..ebc1939 100644 --- a/l10n/it.js +++ b/l10n/it.js @@ -33,7 +33,6 @@ OC.L10N.register( "Unverified recovery email:": "E-mail di recovery non verificata:", "Please set a recovery email address.": "Imposta un indirizzo e-mail di recovery.", "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.", - "Too many verification emails.": "Troppe e-mail di verifica.", "Too many verification emails.": "Troppe e-mail di verifica." }, "nplurals=2; plural=n != 1;"); diff --git a/l10n/it.json b/l10n/it.json index aa34eec..665127d 100644 --- a/l10n/it.json +++ b/l10n/it.json @@ -31,7 +31,6 @@ "Unverified recovery email:": "E-mail di recovery non verificata:", "Please set a recovery email address.": "Imposta un indirizzo e-mail di recovery.", "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.", - "Too many verification emails.": "Too many verification emails.", "Too many verification emails.": "Too many verification emails." },"pluralForm" :"nplurals=2; plural=n != 1;" } \ No newline at end of file -- GitLab From a5a2fabacc346a66bcb17ed03bce3adeb2f27558 Mon Sep 17 00:00:00 2001 From: Avinash Gusain Date: Mon, 1 Jul 2024 19:15:09 +0530 Subject: [PATCH 14/19] translation key correction --- lib/Controller/EmailRecoveryController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Controller/EmailRecoveryController.php b/lib/Controller/EmailRecoveryController.php index 26d3317..d0ce873 100644 --- a/lib/Controller/EmailRecoveryController.php +++ b/lib/Controller/EmailRecoveryController.php @@ -165,7 +165,7 @@ class EmailRecoveryController extends Controller { $response->setStatus(500); if ($e instanceof TooManyVerificationAttemptsException) { $response->setStatus(429); - $response->setData(['message' => $this->l->t('Too many verification emails')]); + $response->setData(['message' => $this->l->t('Too many verification emails.')]); } } return $response; -- GitLab From c57751d1fa94df63df7610fa957d03f063c5976d Mon Sep 17 00:00:00 2001 From: Avinash Gusain Date: Mon, 1 Jul 2024 21:08:40 +0530 Subject: [PATCH 15/19] removed username from key --- lib/Service/RecoveryEmailService.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Service/RecoveryEmailService.php b/lib/Service/RecoveryEmailService.php index 58eaaf4..1a2f689 100644 --- a/lib/Service/RecoveryEmailService.php +++ b/lib/Service/RecoveryEmailService.php @@ -86,7 +86,7 @@ class RecoveryEmailService { $user = $this->userManager->get($username); $email = $user->getEMailAddress(); - $attemptKey = "recovery_email_attempts_$username"; + $attemptKey = "recovery_email_attempts"; $attempts = $this->session->get($attemptKey); if (!is_array($attempts)) { $attempts = []; -- GitLab From c25151892ee6054c6ac6516e1f3352f9d83809b0 Mon Sep 17 00:00:00 2001 From: Avinash Gusain Date: Fri, 5 Jul 2024 07:40:43 +0530 Subject: [PATCH 16/19] log exception --- lib/Controller/EmailRecoveryController.php | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/lib/Controller/EmailRecoveryController.php b/lib/Controller/EmailRecoveryController.php index d0ce873..526e540 100644 --- a/lib/Controller/EmailRecoveryController.php +++ b/lib/Controller/EmailRecoveryController.php @@ -161,12 +161,21 @@ class EmailRecoveryController extends Controller { if ($this->recoveryEmailService->limitVerficationEmail($userId, $recoveryEmail)) { $this->recoveryEmailService->sendVerificationEmail($userId, $recoveryEmail); } + }catch (TooManyVerificationAttemptsException $e) { + $this->logger->error('Too many verification attempts for user {userId} and email {email}: {message}', [ + 'userId' => $userId, + 'email' => $recoveryEmail, + 'message' => $e->getMessage() + ]); + $response->setStatus(429); + $response->setData(['message' => $this->l->t('Too many verification emails.')]); } catch (Exception $e) { + $this->logger->error('Error sending verification email for user {userId} and email {email}: {message}', [ + 'userId' => $userId, + 'email' => $recoveryEmail, + 'message' => $e->getMessage() + ]); $response->setStatus(500); - if ($e instanceof TooManyVerificationAttemptsException) { - $response->setStatus(429); - $response->setData(['message' => $this->l->t('Too many verification emails.')]); - } } return $response; } -- GitLab From ba3b018a13940dedacefe3ffa12012a1825be489 Mon Sep 17 00:00:00 2001 From: Avinash Gusain Date: Fri, 5 Jul 2024 07:41:54 +0530 Subject: [PATCH 17/19] fixed lint --- lib/Controller/EmailRecoveryController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Controller/EmailRecoveryController.php b/lib/Controller/EmailRecoveryController.php index 526e540..1d7ec66 100644 --- a/lib/Controller/EmailRecoveryController.php +++ b/lib/Controller/EmailRecoveryController.php @@ -161,7 +161,7 @@ class EmailRecoveryController extends Controller { if ($this->recoveryEmailService->limitVerficationEmail($userId, $recoveryEmail)) { $this->recoveryEmailService->sendVerificationEmail($userId, $recoveryEmail); } - }catch (TooManyVerificationAttemptsException $e) { + } catch (TooManyVerificationAttemptsException $e) { $this->logger->error('Too many verification attempts for user {userId} and email {email}: {message}', [ 'userId' => $userId, 'email' => $recoveryEmail, -- GitLab From 1cf0ff34e639071707aa56cadbb54c63c5cada45 Mon Sep 17 00:00:00 2001 From: Avinash Gusain Date: Tue, 9 Jul 2024 10:15:33 +0530 Subject: [PATCH 18/19] global key --- lib/Service/RecoveryEmailService.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/Service/RecoveryEmailService.php b/lib/Service/RecoveryEmailService.php index 1a2f689..478d28b 100644 --- a/lib/Service/RecoveryEmailService.php +++ b/lib/Service/RecoveryEmailService.php @@ -40,6 +40,7 @@ class RecoveryEmailService { private CurlService $curl; private array $apiConfig; protected const TOKEN_LIFETIME = 60 * 30; // 30 minutes + private const ATTEMPT_KEY = "recovery_email_attempts"; private BlackListService $blackListService; public function __construct(string $appName, ILogger $logger, IConfig $config, LDAPConnectionService $LDAPConnectionService, ISession $session, IUserManager $userManager, IMailer $mailer, IFactory $l10nFactory, IURLGenerator $urlGenerator, Defaults $themingDefaults, IVerificationToken $verificationToken, CurlService $curlService, BlackListService $blackListService) { @@ -86,8 +87,7 @@ class RecoveryEmailService { $user = $this->userManager->get($username); $email = $user->getEMailAddress(); - $attemptKey = "recovery_email_attempts"; - $attempts = $this->session->get($attemptKey); + $attempts = $this->session->get(self::ATTEMPT_KEY); if (!is_array($attempts)) { $attempts = []; } @@ -103,7 +103,7 @@ class RecoveryEmailService { throw new TooManyVerificationAttemptsException(); } $attempts[] = $currentTime; - $this->session->set($attemptKey, $attempts); + $this->session->set(self::ATTEMPT_KEY, $attempts); return true; } -- GitLab From f703588de1571285f60df3272ec7d567309f3f16 Mon Sep 17 00:00:00 2001 From: Akhil Date: Tue, 9 Jul 2024 11:45:04 +0000 Subject: [PATCH 19/19] Apply 1 suggestion(s) to 1 file(s) Co-authored-by: Akhil --- lib/Controller/EmailRecoveryController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Controller/EmailRecoveryController.php b/lib/Controller/EmailRecoveryController.php index 1d7ec66..d572ed5 100644 --- a/lib/Controller/EmailRecoveryController.php +++ b/lib/Controller/EmailRecoveryController.php @@ -170,7 +170,7 @@ class EmailRecoveryController extends Controller { $response->setStatus(429); $response->setData(['message' => $this->l->t('Too many verification emails.')]); } catch (Exception $e) { - $this->logger->error('Error sending verification email for user {userId} and email {email}: {message}', [ + $this->logger->error('Error sending verification email for user {userId} and recovery email {email}: {message}', [ 'userId' => $userId, 'email' => $recoveryEmail, 'message' => $e->getMessage() -- GitLab