diff --git a/src/Authentication/Actions/EmailActivator.php b/src/Authentication/Actions/EmailActivator.php index 2b47f374e..db9b1e61c 100644 --- a/src/Authentication/Actions/EmailActivator.php +++ b/src/Authentication/Actions/EmailActivator.php @@ -54,36 +54,56 @@ public function show(): string ); } - $code = $this->createIdentity($user); - - /** @var IncomingRequest $request */ - $request = service('request'); - - $ipAddress = $request->getIPAddress(); - $userAgent = (string) $request->getUserAgent(); - $date = Time::now()->toDateTimeString(); - - // Send the email - helper('email'); - $email = emailer(['mailType' => 'html']) - ->setFrom(setting('Email.fromEmail'), setting('Email.fromName') ?? ''); - $email->setTo($userEmail); - $email->setSubject(lang('Auth.emailActivateSubject')); - $email->setMessage($this->view( - setting('Auth.views')['action_email_activate_email'], - ['code' => $code, 'user' => $user, 'ipAddress' => $ipAddress, 'userAgent' => $userAgent, 'date' => $date], - ['debug' => false] - )); - - if ($email->send(false) === false) { - throw new RuntimeException('Cannot send email for user: ' . $user->email . "\n" . $email->printDebugger(['headers'])); - } + $userIdentities = $user->identities; + $userIdentity = array_pop($userIdentities); + + $now = new Time('now'); + $identityCreated = Time::parse($userIdentity->created_at); + + $timDiff = $identityCreated->difference($now); + + $configRCV = setting('Auth.resendCodeVerification'); + + $resendCodeVerificationTime = ((int) $configRCV - $timDiff->getSeconds()); + + if ($timDiff->getSeconds() >= (int) $configRCV || $userIdentity->secret2 === null) { + $code = $this->createIdentity($user); - // Clear the email - $email->clear(); + /** @var IncomingRequest $request */ + $request = service('request'); + + $ipAddress = $request->getIPAddress(); + $userAgent = (string) $request->getUserAgent(); + $date = Time::now()->toDateTimeString(); + + // Send the email + helper('email'); + $email = emailer(['mailType' => 'html']) + ->setFrom(setting('Email.fromEmail'), setting('Email.fromName') ?? ''); + $email->setTo($userEmail); + $email->setSubject(lang('Auth.emailActivateSubject')); + $email->setMessage($this->view( + setting('Auth.views')['action_email_activate_email'], + ['code' => $code, 'user' => $user, 'ipAddress' => $ipAddress, 'userAgent' => $userAgent, 'date' => $date], + ['debug' => false] + )); + + if ($email->send(false) === false) { + throw new RuntimeException('Cannot send email for user: ' . $user->email . "\n" . $email->printDebugger(['headers'])); + } + + /** @var UserIdentityModel $identityModel */ + model(UserIdentityModel::class) + ->where('secret', $code) + ->set(['secret2' => 'SEND']) + ->update(); + + // Clear the email + $email->clear(); + } // Display the info page - return $this->view(setting('Auth.views')['action_email_activate_show'], ['user' => $user]); + return $this->view(setting('Auth.views')['action_email_activate_show'], ['user' => $user, 'remainingTime' => $resendCodeVerificationTime]); } /** diff --git a/src/Config/Auth.php b/src/Config/Auth.php index 194631726..beceb6f20 100644 --- a/src/Config/Auth.php +++ b/src/Config/Auth.php @@ -187,6 +187,15 @@ class Auth extends BaseConfig */ public int $magicLinkLifetime = HOUR; + /** + * -------------------------------------------------------------------- + * Resend Code Verification Time for re-new the code and send it again + * -------------------------------------------------------------------- + * Specify in integer how many seconds of delay time you want to + * re-new the code and send it from email. The default is 60 seconds. + */ + public int $resendCodeVerification = 60; + /** * -------------------------------------------------------------------- * Session Authenticator Configuration diff --git a/src/Language/ar/Auth.php b/src/Language/ar/Auth.php index 5f44a4284..569014c63 100644 --- a/src/Language/ar/Auth.php +++ b/src/Language/ar/Auth.php @@ -107,6 +107,7 @@ 'invalidActivateToken' => 'الرمز غير صحيح', 'needActivate' => 'يجب عليك إكمال تسجيل حسابك عن طريق تأكيد الرمز المرسل إلى عنوان بريدك الإلكتروني.', 'activationBlocked' => 'يجب عليك تفعيل حسابك قبل تسجيل الدخول.', + 'remainingTime' => '(To be translated) You can receive a new code in {0, number} seconds.', // Groups 'unknownGroup' => '{0} ليست مجموعة صالحة.', diff --git a/src/Language/bg/Auth.php b/src/Language/bg/Auth.php index b34e37f86..063418507 100644 --- a/src/Language/bg/Auth.php +++ b/src/Language/bg/Auth.php @@ -107,6 +107,7 @@ 'invalidActivateToken' => 'Кода е невалиден.', 'needActivate' => 'Трябва да завършите регистрацията си, като потвърдите кода, изпратен на вашия имейл адрес.', 'activationBlocked' => 'Трябва да активирате акаунта си, преди да влезете.', + 'remainingTime' => '(To be translated) You can receive a new code in {0, number} seconds.', // Групи 'unknownGroup' => '{0} не е валидна група.', diff --git a/src/Language/cs/Auth.php b/src/Language/cs/Auth.php index 269bf2801..ca30a0773 100644 --- a/src/Language/cs/Auth.php +++ b/src/Language/cs/Auth.php @@ -107,6 +107,7 @@ 'invalidActivateToken' => 'Kód byl nesprávný', 'needActivate' => 'Registraci musíte dokončit potvrzením kódu zaslaného na vaši e-mailovou adresu.', 'activationBlocked' => 'Před přihlášením musíte svůj účet aktivovat.', + 'remainingTime' => '(To be translated) You can receive a new code in {0, number} seconds.', // Groups 'unknownGroup' => '{0} není platná skupina.', diff --git a/src/Language/de/Auth.php b/src/Language/de/Auth.php index 1517082ea..044bd07cc 100644 --- a/src/Language/de/Auth.php +++ b/src/Language/de/Auth.php @@ -107,6 +107,7 @@ 'invalidActivateToken' => 'Der Code war falsch.', 'needActivate' => 'Sie müssen Ihre Anmeldung abschließen, indem Sie den an Ihre E-Mail-Adresse gesendeten Code bestätigen.', 'activationBlocked' => 'Bevor Sie sich anmelden können muss das Konto aktiviert werden.', + 'remainingTime' => '(To be translated) You can receive a new code in {0, number} seconds.', // Groups 'unknownGroup' => '{0} ist eine ungültige Gruppe.', diff --git a/src/Language/en/Auth.php b/src/Language/en/Auth.php index 6f34fe3ee..8cda219ab 100644 --- a/src/Language/en/Auth.php +++ b/src/Language/en/Auth.php @@ -107,6 +107,7 @@ 'invalidActivateToken' => 'The code was incorrect.', 'needActivate' => 'You must complete your registration by confirming the code sent to your email address.', 'activationBlocked' => 'You must activate your account before logging in.', + 'remainingTime' => 'You can receive a new code in {0, number} seconds.', // Groups 'unknownGroup' => '{0} is not a valid group.', diff --git a/src/Language/es/Auth.php b/src/Language/es/Auth.php index 9f3797744..f535a5041 100644 --- a/src/Language/es/Auth.php +++ b/src/Language/es/Auth.php @@ -107,6 +107,7 @@ 'invalidActivateToken' => 'El código era incorrecto.', 'needActivate' => 'Debes completar tu registro confirmando el código enviado a tu dirección de correo electrónico.', 'activationBlocked' => 'Debes activar tu cuenta antes de iniciar sesión.', + 'remainingTime' => '(To be translated) You can receive a new code in {0, number} seconds.', // Grupos 'unknownGroup' => '{0} no es un grupo válido.', diff --git a/src/Language/fa/Auth.php b/src/Language/fa/Auth.php index e42ae39a4..80a09847d 100644 --- a/src/Language/fa/Auth.php +++ b/src/Language/fa/Auth.php @@ -107,6 +107,7 @@ 'invalidActivateToken' => 'کد صحیح نمی باشد.', 'needActivate' => 'شما باید با ارائه کد ارسال شده به ایمیلتان، ثبت نام را تکمیل کنید.', 'activationBlocked' => 'قبل از تلاش برای ورود، باید اکانت خود را فعال کنید.', + 'remainingTime' => '(To be translated) You can receive a new code in {0, number} seconds.', // Groups 'unknownGroup' => '{0} گروهی معتبر نیست.', diff --git a/src/Language/fr/Auth.php b/src/Language/fr/Auth.php index c6f8e4919..3464343bf 100644 --- a/src/Language/fr/Auth.php +++ b/src/Language/fr/Auth.php @@ -107,6 +107,7 @@ 'invalidActivateToken' => 'Le code était incorrect.', 'needActivate' => 'Complétez votre inscription en confirmant le code envoyé à votre email.', 'activationBlocked' => 'Vous devez activer votre compte avant de vous connecter.', + 'remainingTime' => '(To be translated) You can receive a new code in {0, number} seconds.', // Groups 'unknownGroup' => '{0} n\'est pas un groupe valide.', diff --git a/src/Language/id/Auth.php b/src/Language/id/Auth.php index 6910a81fd..a0e40a4ec 100644 --- a/src/Language/id/Auth.php +++ b/src/Language/id/Auth.php @@ -107,6 +107,7 @@ 'invalidActivateToken' => 'Kode tidak sesuai.', 'needActivate' => 'Anda harus menyelesaikan registrasi Anda dengan mengonfirmasi kode yang dikirim ke alamat email Anda.', 'activationBlocked' => 'Anda harus mengaktifkan akun Anda sebelum masuk.', + 'remainingTime' => 'Anda dapat menerima kode baru dalam {0, number} detik lagi.', // Groups 'unknownGroup' => '{0} bukan grup yang sah.', diff --git a/src/Language/it/Auth.php b/src/Language/it/Auth.php index 9cafd7f48..917f4b227 100644 --- a/src/Language/it/Auth.php +++ b/src/Language/it/Auth.php @@ -107,6 +107,7 @@ 'invalidActivateToken' => 'Il codice era sbagliato.', 'needActivate' => 'Devi completare la registrazione confermando il codice inviato al tuo indrizzo email.', 'activationBlocked' => '(to be translated) You must activate your account before logging in.', + 'remainingTime' => '(To be translated) You can receive a new code in {0, number} seconds.', // Groups 'unknownGroup' => '{0} non è un gruppo valido.', diff --git a/src/Language/ja/Auth.php b/src/Language/ja/Auth.php index 282335160..f43ec44e8 100644 --- a/src/Language/ja/Auth.php +++ b/src/Language/ja/Auth.php @@ -107,6 +107,7 @@ 'invalidActivateToken' => 'コードが間違っています。', // 'The code was incorrect.' 'needActivate' => 'メールアドレスに送信されたコードを確認し、登録を完了する必要があります。', // 'You must complete your registration by confirming the code sent to your email address.' 'activationBlocked' => 'ログインする前にアカウントを有効化する必要があります。', // 'You must activate your account before logging in.' + 'remainingTime' => '(To be translated) You can receive a new code in {0, number} seconds.', // Groups 'unknownGroup' => '{0} は有効なグループではありません。', // '{0} is not a valid group.' diff --git a/src/Language/lt/Auth.php b/src/Language/lt/Auth.php index 716f6f263..33c5ea6f1 100644 --- a/src/Language/lt/Auth.php +++ b/src/Language/lt/Auth.php @@ -107,6 +107,7 @@ 'invalidActivateToken' => 'Kodas buvo neteisingas.', 'needActivate' => 'Turite baigti registraciją panaudodami kodą, išsiųstą Jums el. pašto adresu.', 'activationBlocked' => 'Prieš prisijungdami turite aktyvuoti paskyrą.', + 'remainingTime' => '(To be translated) You can receive a new code in {0, number} seconds.', // Groups 'unknownGroup' => '{0} nėra egzistuojanti grupė.', diff --git a/src/Language/nl/Auth.php b/src/Language/nl/Auth.php index e3d082a4a..791f5705c 100644 --- a/src/Language/nl/Auth.php +++ b/src/Language/nl/Auth.php @@ -107,6 +107,7 @@ 'invalidActivateToken' => 'De code was niet correct.', 'needActivate' => 'Je moet je registratie voltooien door de code te bevestigen die naar je e-mailadres is gestuurd.', 'activationBlocked' => 'Je moet je account activeren voordat je kunt inloggen.', + 'remainingTime' => '(To be translated) You can receive a new code in {0, number} seconds.', // Groups 'unknownGroup' => '{0} is geen geldige groep.', diff --git a/src/Language/pl/Auth.php b/src/Language/pl/Auth.php index 06bc98456..3c8976296 100644 --- a/src/Language/pl/Auth.php +++ b/src/Language/pl/Auth.php @@ -107,6 +107,7 @@ 'invalidActivateToken' => 'Kod był nieprawidłowy.', 'needActivate' => 'Musisz zakończyć rejestrację, potwierdzając kod wysłany na adres e-mail.', 'activationBlocked' => 'Musisz aktywować swoje konto przed zalogowaniem się.', + 'remainingTime' => '(To be translated) You can receive a new code in {0, number} seconds.', // Groups 'unknownGroup' => '{0} nie jest ważną grupą.', diff --git a/src/Language/pt-BR/Auth.php b/src/Language/pt-BR/Auth.php index f8aa21912..47b7d0880 100644 --- a/src/Language/pt-BR/Auth.php +++ b/src/Language/pt-BR/Auth.php @@ -107,6 +107,7 @@ 'invalidActivateToken' => 'O código estava incorreto.', 'needActivate' => 'Você deve concluir seu registro confirmando o código enviado para seu endereço de e-mail.', 'activationBlocked' => 'Você deve ativar sua conta antes de fazer o login.', + 'remainingTime' => '(To be translated) You can receive a new code in {0, number} seconds.', // Grupos 'unknownGroup' => '{0} não é um grupo válido.', diff --git a/src/Language/pt/Auth.php b/src/Language/pt/Auth.php index 50d39b0dd..1fe6e2b18 100644 --- a/src/Language/pt/Auth.php +++ b/src/Language/pt/Auth.php @@ -107,6 +107,7 @@ 'invalidActivateToken' => 'O código estava incorreto.', 'needActivate' => 'Deve concluir seu registro confirmando o código enviado para seu endereço de e-mail.', 'activationBlocked' => 'Deve ativar sua conta antes de fazer o login.', + 'remainingTime' => '(To be translated) You can receive a new code in {0, number} seconds.', // Grupos 'unknownGroup' => '{0} não é um grupo válido.', diff --git a/src/Language/ru/Auth.php b/src/Language/ru/Auth.php index 4efd5c58b..a7ca18996 100644 --- a/src/Language/ru/Auth.php +++ b/src/Language/ru/Auth.php @@ -107,6 +107,7 @@ 'invalidActivateToken' => 'Код неверный.', 'needActivate' => 'Вы должны завершить регистрацию, подтвердив код, отправленный на ваш адрес электронной почты.', 'activationBlocked' => 'Вы должны активировать свою учетную запись перед входом в систему.', + 'remainingTime' => '(To be translated) You can receive a new code in {0, number} seconds.', // Groups 'unknownGroup' => '{0} не является действительной группой.', diff --git a/src/Language/sk/Auth.php b/src/Language/sk/Auth.php index f12c1310e..b81d99f8c 100644 --- a/src/Language/sk/Auth.php +++ b/src/Language/sk/Auth.php @@ -107,6 +107,7 @@ 'invalidActivateToken' => 'Kód bol nesprávny', 'needActivate' => 'Registráciu musíte dokončiť potvrdením kódu zaslaného na vašu e-mailovú adresu.', 'activationBlocked' => 'Pred prihlásením si musíte aktivovať svoj účet.', + 'remainingTime' => '(To be translated) You can receive a new code in {0, number} seconds.', // Groups 'unknownGroup' => '{0} nie je platná skupina.', diff --git a/src/Language/sr/Auth.php b/src/Language/sr/Auth.php index 03ce96794..adb595361 100644 --- a/src/Language/sr/Auth.php +++ b/src/Language/sr/Auth.php @@ -107,6 +107,7 @@ 'invalidActivateToken' => 'Kod nije ispravan.', 'needActivate' => 'Morate dovršiti registraciju potvrdom koda poslatog na vašu email adresu.', 'activationBlocked' => 'Morate aktivirati vaš nalog pre pristupanja sistemu.', + 'remainingTime' => '(To be translated) You can receive a new code in {0, number} seconds.', // Groups 'unknownGroup' => '{0} neispravna grupa.', diff --git a/src/Language/sv-SE/Auth.php b/src/Language/sv-SE/Auth.php index d857e7c4b..e6dca8b79 100644 --- a/src/Language/sv-SE/Auth.php +++ b/src/Language/sv-SE/Auth.php @@ -107,6 +107,7 @@ 'invalidActivateToken' => 'Koden var fel.', 'needActivate' => 'Du måste slutföra registreringen genom att ange aktiveringskoden som skickats till din epostadress.', 'activationBlocked' => 'Du måste aktivera ditt konto innan du kan logga in.', + 'remainingTime' => '(To be translated) You can receive a new code in {0, number} seconds.', // Groups 'unknownGroup' => '{0} är inte en giltig grupp.', diff --git a/src/Language/tr/Auth.php b/src/Language/tr/Auth.php index 02d2ff55e..ef31e9e3b 100644 --- a/src/Language/tr/Auth.php +++ b/src/Language/tr/Auth.php @@ -107,6 +107,7 @@ 'invalidActivateToken' => 'Kod yanlıştı.', 'needActivate' => 'E-posta adresinize gönderilen kodu onaylayarak kaydınızı tamamlamanız gerekmektedir.', 'activationBlocked' => 'Giriş yapmadan önce hesabınızı etkinleştirmeniz gerekmektedir.', + 'remainingTime' => '(To be translated) You can receive a new code in {0, number} seconds.', // Groups 'unknownGroup' => '{0} geçerli bir grup değil.', diff --git a/src/Language/uk/Auth.php b/src/Language/uk/Auth.php index 76ea90b90..b6ffa1f34 100644 --- a/src/Language/uk/Auth.php +++ b/src/Language/uk/Auth.php @@ -107,6 +107,7 @@ 'invalidActivateToken' => 'Код був невірний.', 'needActivate' => 'Ви повинні завершити реєстрацію, підтвердивши код, надісланий на вашу електронну адресу.', 'activationBlocked' => 'Ви повинні активувати свій обліковий запис перед входом.', + 'remainingTime' => '(To be translated) You can receive a new code in {0, number} seconds.', // Groups 'unknownGroup' => '{0} недійсна група.', diff --git a/src/Views/email_activate_show.php b/src/Views/email_activate_show.php index 6b41d4626..11f47ee1e 100644 --- a/src/Views/email_activate_show.php +++ b/src/Views/email_activate_show.php @@ -29,6 +29,8 @@ +
= lang('Auth.remainingTime', [$remainingTime]) ?>
+