From 84d6ed407ed870c7173511868c521b6c5b64d91d Mon Sep 17 00:00:00 2001 From: Pooya Parsa Dadashi Date: Wed, 9 Aug 2023 22:26:55 +0330 Subject: [PATCH 1/9] fix: add limitation if `allowMagicLinkLogins` is `false` --- src/Controllers/MagicLinkController.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/Controllers/MagicLinkController.php b/src/Controllers/MagicLinkController.php index 45cfb1060..4ff0e86b7 100644 --- a/src/Controllers/MagicLinkController.php +++ b/src/Controllers/MagicLinkController.php @@ -50,6 +50,11 @@ public function __construct() */ public function loginView() { + // Check if magic-link is not allowed + if (! setting('Auth.allowMagicLinkLogins')) { + return redirect()->route('login')->with('error', lang('Auth.magicLinkDisabled')); + } + if (auth()->loggedIn()) { return redirect()->to(config('Auth')->loginRedirect()); } @@ -66,6 +71,11 @@ public function loginView() */ public function loginAction() { + // Check if magic-link is not allowed + if (! setting('Auth.allowMagicLinkLogins')) { + return redirect()->route('login')->with('error', lang('Auth.magicLinkDisabled')); + } + // Validate email format $rules = $this->getValidationRules(); if (! $this->validateData($this->request->getPost(), $rules, [], config('Auth')->DBGroup)) { From 40af448fb188ebef1f922e0cc50265361e07734b Mon Sep 17 00:00:00 2001 From: Pooya Parsa Dadashi Date: Wed, 9 Aug 2023 22:42:10 +0330 Subject: [PATCH 2/9] lang: add new string for `magicLinkDisabled` --- src/Language/bg/Auth.php | 1 + src/Language/de/Auth.php | 1 + src/Language/en/Auth.php | 1 + src/Language/es/Auth.php | 1 + src/Language/fa/Auth.php | 1 + src/Language/fr/Auth.php | 1 + src/Language/id/Auth.php | 1 + src/Language/it/Auth.php | 1 + src/Language/ja/Auth.php | 1 + src/Language/lt/Auth.php | 1 + src/Language/pt-BR/Auth.php | 1 + src/Language/pt/Auth.php | 1 + src/Language/sk/Auth.php | 1 + src/Language/sr/Auth.php | 1 + src/Language/sv-SE/Auth.php | 1 + src/Language/tr/Auth.php | 1 + src/Language/uk/Auth.php | 1 + 17 files changed, 17 insertions(+) diff --git a/src/Language/bg/Auth.php b/src/Language/bg/Auth.php index 625c52592..f83fda6e9 100644 --- a/src/Language/bg/Auth.php +++ b/src/Language/bg/Auth.php @@ -51,6 +51,7 @@ 'magicLinkExpired' => 'Съжаляваме, линкът е изтекъл.', 'checkYourEmail' => 'Проверете вашия имейл!', 'magicLinkDetails' => 'Току що ви изпратихме имейл с линк за вход. Линкът ще бъде валиден само {0} минути.', + 'magicLinkDisabled' => '(To be translated) Use of MagicLink is currently not allowed.', 'successLogout' => 'Успешно излязохте от системата.', 'backToLogin' => 'Обратно към входа', diff --git a/src/Language/de/Auth.php b/src/Language/de/Auth.php index 7b982fd2c..977feb0a6 100644 --- a/src/Language/de/Auth.php +++ b/src/Language/de/Auth.php @@ -51,6 +51,7 @@ 'magicLinkExpired' => 'Sorry, der Link ist abgelaufen.', 'checkYourEmail' => 'Prüfen Sie Ihre E-Mail!', 'magicLinkDetails' => 'Wir haben Ihnen gerade eine E-Mail mit einem Login-Link geschickt. Er ist nur für {0} Minuten gültig.', + 'magicLinkDisabled' => '(To be translated) Use of MagicLink is currently not allowed.', 'successLogout' => 'Sie haben sich erfolgreich abgemeldet.', 'backToLogin' => 'Zurück zur Anmeldung', diff --git a/src/Language/en/Auth.php b/src/Language/en/Auth.php index f64911f69..d9271cc78 100644 --- a/src/Language/en/Auth.php +++ b/src/Language/en/Auth.php @@ -51,6 +51,7 @@ 'magicLinkExpired' => 'Sorry, link has expired.', 'checkYourEmail' => 'Check your email!', 'magicLinkDetails' => 'We just sent you an email with a Login link inside. It is only valid for {0} minutes.', + 'magicLinkDisabled' => 'Use of MagicLink is currently not allowed.', 'successLogout' => 'You have successfully logged out.', 'backToLogin' => 'Back to Login', diff --git a/src/Language/es/Auth.php b/src/Language/es/Auth.php index a6b52b4bc..027e7d4ec 100644 --- a/src/Language/es/Auth.php +++ b/src/Language/es/Auth.php @@ -51,6 +51,7 @@ 'magicLinkExpired' => 'Lo siento, el enlace ha caducado.', 'checkYourEmail' => '¡Revisa tu correo electrónico!', 'magicLinkDetails' => 'Acabamos de enviarte un correo electrónico con un enlace de inicio de sesión. Solo es válido durante {0} minutos.', + 'magicLinkDisabled' => '(To be translated) Use of MagicLink is currently not allowed.', 'successLogout' => 'Has cerrado sesión correctamente.', 'backToLogin' => 'Volver al inicio de sesión', diff --git a/src/Language/fa/Auth.php b/src/Language/fa/Auth.php index 5c0a05f5a..4cedff90d 100644 --- a/src/Language/fa/Auth.php +++ b/src/Language/fa/Auth.php @@ -51,6 +51,7 @@ 'magicLinkExpired' => 'متاسفانه, لینک منقضی شده است.', 'checkYourEmail' => 'ایمیلتان را بررسی کنید!', 'magicLinkDetails' => 'ما فقط یک لینک ورود به ایمیلتان ارسال کردیم. این لینک فقط برای {0} دقیقه معتبر خواهد بود.', + 'magicLinkDisabled' => 'امکان استفاده از لینک جادویی وجود ندارد.', 'successLogout' => 'با موفقیت خارج شدید.', 'backToLogin' => 'بازگشت به ورود به سیستم', diff --git a/src/Language/fr/Auth.php b/src/Language/fr/Auth.php index 3a3d2b8a0..9bf794ea3 100644 --- a/src/Language/fr/Auth.php +++ b/src/Language/fr/Auth.php @@ -51,6 +51,7 @@ 'magicLinkExpired' => 'Désolé, le lien a expiré.', 'checkYourEmail' => 'Vérifier votre email !', 'magicLinkDetails' => 'Nous venons de vous envoyer un email contenant un lien de connexion. Il n\'est valable que {0} minutes.', + 'magicLinkDisabled' => '(To be translated) Use of MagicLink is currently not allowed.', 'successLogout' => 'Vous avez été déconnecté avec succès.', 'backToLogin' => 'Retour à la connexion', diff --git a/src/Language/id/Auth.php b/src/Language/id/Auth.php index ff97d9a3a..62a90d8e6 100644 --- a/src/Language/id/Auth.php +++ b/src/Language/id/Auth.php @@ -51,6 +51,7 @@ 'magicLinkExpired' => 'Maaf, tautan sudah tidak berlaku.', 'checkYourEmail' => 'Periksa email Anda!', 'magicLinkDetails' => 'Kami baru saja mengirimi Anda email dengan tautan Masuk di dalamnya. Ini hanya berlaku selama {0} menit.', + 'magicLinkDisabled' => '(To be translated) Use of MagicLink is currently not allowed.', 'successLogout' => 'Anda telah berhasil keluar.', 'backToLogin' => 'Kembali ke masuk', diff --git a/src/Language/it/Auth.php b/src/Language/it/Auth.php index e62989d7c..dc531886a 100644 --- a/src/Language/it/Auth.php +++ b/src/Language/it/Auth.php @@ -51,6 +51,7 @@ 'magicLinkExpired' => 'Spiacente, il link è scaduto.', 'checkYourEmail' => 'Controlla la tua email!', 'magicLinkDetails' => 'Ti abbiamo appena inviato una mail contenente un Login link. È valido solo per {0} minuti.', + 'magicLinkDisabled' => '(To be translated) Use of MagicLink is currently not allowed.', 'successLogout' => 'Hai effettuato il logout con successo.', 'backToLogin' => 'Torna al login', diff --git a/src/Language/ja/Auth.php b/src/Language/ja/Auth.php index 0a3befa0a..f8722ab12 100644 --- a/src/Language/ja/Auth.php +++ b/src/Language/ja/Auth.php @@ -51,6 +51,7 @@ 'magicLinkExpired' => '申し訳ございません、リンクは切れています。', // 'Sorry, link has expired.' 'checkYourEmail' => 'メールをチェックしてください!', // 'Check your email!' 'magicLinkDetails' => 'ログインリンクが含まれたメールを送信しました。これは {0} 分間だけ有効です。', // 'We just sent you an email with a Login link inside. It is only valid for {0} minutes.' + 'magicLinkDisabled' => '(To be translated) Use of MagicLink is currently not allowed.', 'successLogout' => '正常にログアウトしました。', // 'You have successfully logged out.' 'backToLogin' => 'ログインに戻る', // 'Back to Login' diff --git a/src/Language/lt/Auth.php b/src/Language/lt/Auth.php index 6efc8e00a..0b10631c0 100644 --- a/src/Language/lt/Auth.php +++ b/src/Language/lt/Auth.php @@ -51,6 +51,7 @@ 'magicLinkExpired' => 'Deja, nuorodos galiojimas baigėsi.', 'checkYourEmail' => 'Patikrinkite savo el. paštą!', 'magicLinkDetails' => 'Mes ką tik išsiuntėme Jums el. laišką su prisijungimo nuoroda. Ji galios tiki {0} minučių(-es).', + 'magicLinkDisabled' => '(To be translated) Use of MagicLink is currently not allowed.', 'successLogout' => 'Jūs sėkmingai atsijungėte.', 'backToLogin' => 'Grįžti į prisijungimą', diff --git a/src/Language/pt-BR/Auth.php b/src/Language/pt-BR/Auth.php index 4885d3298..b001a9511 100644 --- a/src/Language/pt-BR/Auth.php +++ b/src/Language/pt-BR/Auth.php @@ -51,6 +51,7 @@ 'magicLinkExpired' => 'Desculpe, o link expirou.', 'checkYourEmail' => 'Verifique seu e-mail!', 'magicLinkDetails' => 'Acabamos de enviar um e-mail com um link de Login. Ele é válido apenas por {0} minutos.', + 'magicLinkDisabled' => '(To be translated) Use of MagicLink is currently not allowed.', 'successLogout' => 'Você saiu com sucesso.', 'backToLogin' => 'Voltar para o login', diff --git a/src/Language/pt/Auth.php b/src/Language/pt/Auth.php index d4b5261c8..ee7a5ab90 100644 --- a/src/Language/pt/Auth.php +++ b/src/Language/pt/Auth.php @@ -51,6 +51,7 @@ 'magicLinkExpired' => 'Desculpe, o link expirou.', 'checkYourEmail' => 'Verifique o seu e-mail!', 'magicLinkDetails' => 'Acabamos de enviar um e-mail com um link de Login. Ele é válido apenas por {0} minutos.', + 'magicLinkDisabled' => '(To be translated) Use of MagicLink is currently not allowed.', 'successLogout' => 'Saiu com sucesso.', 'backToLogin' => 'Voltar ao login', diff --git a/src/Language/sk/Auth.php b/src/Language/sk/Auth.php index c18741d9b..bc0de4962 100644 --- a/src/Language/sk/Auth.php +++ b/src/Language/sk/Auth.php @@ -51,6 +51,7 @@ 'magicLinkExpired' => 'Ľutujeme, platnosť odkazu vypršala.', 'checkYourEmail' => 'Skontrolujte e-mail', 'magicLinkDetails' => 'Práve sme vám poslali e-mail s odkazom na prihlásenie. Platí iba {0} minút.', + 'magicLinkDisabled' => '(To be translated) Use of MagicLink is currently not allowed.', 'successLogout' => 'Úspešne ste sa odhlásili.', 'backToLogin' => 'Späť na prihlásenie', diff --git a/src/Language/sr/Auth.php b/src/Language/sr/Auth.php index 12236dfc2..8030c6a4d 100644 --- a/src/Language/sr/Auth.php +++ b/src/Language/sr/Auth.php @@ -51,6 +51,7 @@ 'magicLinkExpired' => 'Žao nam je, link je istekao.', 'checkYourEmail' => 'Proverite Vaš email!', 'magicLinkDetails' => 'Upravo smo Vam poslali pristupni link. Pristupni link će biti validan još samo {0} minuta.', + 'magicLinkDisabled' => '(To be translated) Use of MagicLink is currently not allowed.', 'successLogout' => 'Uspešno ste se odjavili sa sistema.', 'backToLogin' => 'Nazad na prijavljivanje', diff --git a/src/Language/sv-SE/Auth.php b/src/Language/sv-SE/Auth.php index d57ec3b33..1031b7963 100644 --- a/src/Language/sv-SE/Auth.php +++ b/src/Language/sv-SE/Auth.php @@ -51,6 +51,7 @@ 'magicLinkExpired' => 'Tyvärr, länken har gått ut.', 'checkYourEmail' => 'Kontrollera din epost!', 'magicLinkDetails' => 'En login-länk har skickats med epost. Den gäller bara i {0} minuter.', + 'magicLinkDisabled' => '(To be translated) Use of MagicLink is currently not allowed.', 'successLogout' => 'Du har loggats ut.', 'backToLogin' => 'Tillbaka till inloggning', diff --git a/src/Language/tr/Auth.php b/src/Language/tr/Auth.php index 6d1766732..b54865ba5 100644 --- a/src/Language/tr/Auth.php +++ b/src/Language/tr/Auth.php @@ -51,6 +51,7 @@ 'magicLinkExpired' => 'Üzgünüm, bağlantının süresi doldu.', 'checkYourEmail' => 'E-postanı kontrol et!', 'magicLinkDetails' => 'Az önce size içinde bir Giriş bağlantısı olan bir e-posta gönderdik. Bağlantı {0} dakika için geçerlidir.', + 'magicLinkDisabled' => '(To be translated) Use of MagicLink is currently not allowed.', 'successLogout' => 'Başarıyla çıkış yaptınız.', 'backToLogin' => 'Girişe Geri Dön', diff --git a/src/Language/uk/Auth.php b/src/Language/uk/Auth.php index 1ff36314b..c012540ce 100644 --- a/src/Language/uk/Auth.php +++ b/src/Language/uk/Auth.php @@ -51,6 +51,7 @@ 'magicLinkExpired' => 'Вибачте, термін дії посилання закінчився.', 'checkYourEmail' => 'Перевірте свою електронну пошту!', 'magicLinkDetails' => 'Ми щойно надіслали вам електронний лист із посиланням для входу. Він дійсний лише протягом {0} хвилин.', + 'magicLinkDisabled' => '(To be translated) Use of MagicLink is currently not allowed.', 'successLogout' => 'Ви успішно вийшли.', 'backToLogin' => 'Повернутися до входу', From 71fee5b5d5ba202ff765aa54e52b4e33614e2ddb Mon Sep 17 00:00:00 2001 From: Pooya Parsa Dadashi Date: Wed, 9 Aug 2023 22:57:25 +0330 Subject: [PATCH 3/9] tests: add test for magicLinkDisabled --- tests/Controllers/MagicLinkTest.php | 32 +++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/tests/Controllers/MagicLinkTest.php b/tests/Controllers/MagicLinkTest.php index 7bf92fc6b..dfb963993 100644 --- a/tests/Controllers/MagicLinkTest.php +++ b/tests/Controllers/MagicLinkTest.php @@ -120,4 +120,36 @@ public function testBackToLoginLinkOnPage(): void $result = $this->get('/login/magic-link'); $this->assertStringContainsString(lang('Auth.backToLogin'), $result->getBody()); } + + public function testMagicLinkRedirectsIfNotAllowed(): void + { + $config = config('Auth'); + $config->allowMagicLinkLogins = false; + Factories::injectMock('config', 'Auth', $config); + + $result = $this->withSession()->get('/login/magic-link'); + + $result->assertStatus(302); + $result->assertRedirect(); + $result->assertSessionHas( + 'error', + lang('Auth.magicLinkDisabled'), + ); + } + + public function testMagicLinkActionRedirectsIfNotAllowed(): void + { + $config = config('Auth'); + $config->allowMagicLinkLogins = false; + Factories::injectMock('config', 'Auth', $config); + + $result = $this->withSession()->post('/login/magic-link'); + + $result->assertStatus(302); + $result->assertRedirect(); + $result->assertSessionHas( + 'error', + lang('Auth.magicLinkDisabled'), + ); + } } From 9faa42e33ee8fceb5937c615a0aa774c7e1f23c4 Mon Sep 17 00:00:00 2001 From: Pooya Parsa Dadashi Date: Thu, 10 Aug 2023 07:20:07 +0330 Subject: [PATCH 4/9] tests: add test for check verify-magic-link route if `allowMagicLinkLogins=false` --- tests/Controllers/MagicLinkTest.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tests/Controllers/MagicLinkTest.php b/tests/Controllers/MagicLinkTest.php index dfb963993..b8b1f794e 100644 --- a/tests/Controllers/MagicLinkTest.php +++ b/tests/Controllers/MagicLinkTest.php @@ -152,4 +152,20 @@ public function testMagicLinkActionRedirectsIfNotAllowed(): void lang('Auth.magicLinkDisabled'), ); } + + public function testMagicLinkVerifyRedirectsIfNotAllowed(): void + { + $config = config('Auth'); + $config->allowMagicLinkLogins = false; + Factories::injectMock('config', 'Auth', $config); + + $result = $this->withSession()->get('/login/verify-magic-link'); + + $result->assertStatus(302); + $result->assertRedirect(); + $result->assertSessionHas( + 'error', + lang('Auth.magicLinkDisabled'), + ); + } } From 569d4b902831871f6dbde8075ada5282562fb913 Mon Sep 17 00:00:00 2001 From: Pooya Parsa Dadashi Date: Thu, 10 Aug 2023 07:32:08 +0330 Subject: [PATCH 5/9] fix: add limite verify-magic-link route if magicLinkDisabled --- src/Controllers/MagicLinkController.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Controllers/MagicLinkController.php b/src/Controllers/MagicLinkController.php index 4ff0e86b7..4f1ea05a9 100644 --- a/src/Controllers/MagicLinkController.php +++ b/src/Controllers/MagicLinkController.php @@ -145,6 +145,11 @@ protected function displayMessage(): string */ public function verify(): RedirectResponse { + // Check if magic-link is not allowed + if (! setting('Auth.allowMagicLinkLogins')) { + return redirect()->route('login')->with('error', lang('Auth.magicLinkDisabled')); + } + $token = $this->request->getGet('token'); /** @var UserIdentityModel $identityModel */ From 635aacb9181a327ce3dcba87566a5f5a38266a94 Mon Sep 17 00:00:00 2001 From: Pooya Parsa Dadashi Date: Fri, 11 Aug 2023 07:32:22 +0330 Subject: [PATCH 6/9] refactor: use praivate method for check magicLink is disabled --- src/Controllers/MagicLinkController.php | 27 ++++++++++++++----------- 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/src/Controllers/MagicLinkController.php b/src/Controllers/MagicLinkController.php index 4f1ea05a9..a6c16558e 100644 --- a/src/Controllers/MagicLinkController.php +++ b/src/Controllers/MagicLinkController.php @@ -50,10 +50,7 @@ public function __construct() */ public function loginView() { - // Check if magic-link is not allowed - if (! setting('Auth.allowMagicLinkLogins')) { - return redirect()->route('login')->with('error', lang('Auth.magicLinkDisabled')); - } + $this->displayErrorMagicLinkDisabled(); if (auth()->loggedIn()) { return redirect()->to(config('Auth')->loginRedirect()); @@ -71,10 +68,7 @@ public function loginView() */ public function loginAction() { - // Check if magic-link is not allowed - if (! setting('Auth.allowMagicLinkLogins')) { - return redirect()->route('login')->with('error', lang('Auth.magicLinkDisabled')); - } + $this->displayErrorMagicLinkDisabled(); // Validate email format $rules = $this->getValidationRules(); @@ -145,10 +139,7 @@ protected function displayMessage(): string */ public function verify(): RedirectResponse { - // Check if magic-link is not allowed - if (! setting('Auth.allowMagicLinkLogins')) { - return redirect()->route('login')->with('error', lang('Auth.magicLinkDisabled')); - } + $this->displayErrorMagicLinkDisabled(); $token = $this->request->getGet('token'); @@ -228,6 +219,18 @@ private function recordLoginAttempt( ); } + /** + * Display error to the user if magic-link is not allowed. + * + * @return RedirectResponse|void + */ + private function displayErrorMagicLinkDisabled() + { + if (! setting('Auth.allowMagicLinkLogins')) { + return redirect()->route('login')->with('error', lang('Auth.magicLinkDisabled')); + } + } + /** * Returns the rules that should be used for validation. * From 6d56e4635079cace978ac72b6104f5e486cdeeaf Mon Sep 17 00:00:00 2001 From: Pooya Parsa Dadashi Date: Fri, 11 Aug 2023 07:35:42 +0330 Subject: [PATCH 7/9] lang: [ar] add string magicLinkDisabled --- src/Language/ar/Auth.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Language/ar/Auth.php b/src/Language/ar/Auth.php index 460241154..2eaad4faa 100644 --- a/src/Language/ar/Auth.php +++ b/src/Language/ar/Auth.php @@ -51,6 +51,7 @@ 'magicLinkExpired' => 'عذرا ، لقد انتهت صلاحية الرابط.', 'checkYourEmail' => 'تحقق من بريدك الالكتروني!', 'magicLinkDetails' => 'لقد أرسلنا لك بريدًا إلكترونيًا يحتوي على رابط تسجيل الدخول بالداخل. الرابط صالح فقط لمدة {0} دقيقة.', + 'magicLinkDisabled' => '(To be translated) Use of MagicLink is currently not allowed.', 'successLogout' => 'لقد قمت بتسجيل الخروج بنجاح.', 'backToLogin' => 'العودة إلى نموذج تسجيل الدخول', From 48aa4759f3e488853fa1c5a9032ca3b4bb14cd9e Mon Sep 17 00:00:00 2001 From: Pooya Parsa Dadashi Date: Sat, 12 Aug 2023 07:45:58 +0330 Subject: [PATCH 8/9] lang: [ja] add string magicLinkDisabled --- src/Language/ja/Auth.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Language/ja/Auth.php b/src/Language/ja/Auth.php index f8722ab12..10af048fe 100644 --- a/src/Language/ja/Auth.php +++ b/src/Language/ja/Auth.php @@ -51,7 +51,7 @@ 'magicLinkExpired' => '申し訳ございません、リンクは切れています。', // 'Sorry, link has expired.' 'checkYourEmail' => 'メールをチェックしてください!', // 'Check your email!' 'magicLinkDetails' => 'ログインリンクが含まれたメールを送信しました。これは {0} 分間だけ有効です。', // 'We just sent you an email with a Login link inside. It is only valid for {0} minutes.' - 'magicLinkDisabled' => '(To be translated) Use of MagicLink is currently not allowed.', + 'magicLinkDisabled' => 'マジックリンクは使えません。', // 'Use of MagicLink is currently not allowed.' 'successLogout' => '正常にログアウトしました。', // 'You have successfully logged out.' 'backToLogin' => 'ログインに戻る', // 'Back to Login' From eb5375869226a7f55c73f813847338f04d52672b Mon Sep 17 00:00:00 2001 From: Pooya Parsa Dadashi Date: Sat, 12 Aug 2023 08:21:20 +0330 Subject: [PATCH 9/9] revert: back to old ver --- src/Controllers/MagicLinkController.php | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/src/Controllers/MagicLinkController.php b/src/Controllers/MagicLinkController.php index a6c16558e..fb036e640 100644 --- a/src/Controllers/MagicLinkController.php +++ b/src/Controllers/MagicLinkController.php @@ -50,7 +50,9 @@ public function __construct() */ public function loginView() { - $this->displayErrorMagicLinkDisabled(); + if (! setting('Auth.allowMagicLinkLogins')) { + return redirect()->route('login')->with('error', lang('Auth.magicLinkDisabled')); + } if (auth()->loggedIn()) { return redirect()->to(config('Auth')->loginRedirect()); @@ -68,7 +70,9 @@ public function loginView() */ public function loginAction() { - $this->displayErrorMagicLinkDisabled(); + if (! setting('Auth.allowMagicLinkLogins')) { + return redirect()->route('login')->with('error', lang('Auth.magicLinkDisabled')); + } // Validate email format $rules = $this->getValidationRules(); @@ -139,7 +143,9 @@ protected function displayMessage(): string */ public function verify(): RedirectResponse { - $this->displayErrorMagicLinkDisabled(); + if (! setting('Auth.allowMagicLinkLogins')) { + return redirect()->route('login')->with('error', lang('Auth.magicLinkDisabled')); + } $token = $this->request->getGet('token'); @@ -219,18 +225,6 @@ private function recordLoginAttempt( ); } - /** - * Display error to the user if magic-link is not allowed. - * - * @return RedirectResponse|void - */ - private function displayErrorMagicLinkDisabled() - { - if (! setting('Auth.allowMagicLinkLogins')) { - return redirect()->route('login')->with('error', lang('Auth.magicLinkDisabled')); - } - } - /** * Returns the rules that should be used for validation. *