NOW MANAGED ON CODEBERG
Improved login redirect and setup experience
Dan Brown78e94bb0035d
diff --git a/app/Http/Controllers/Auth/MfaBackupCodesController.php b/app/Http/Controllers/Auth/MfaBackupCodesController.phpindex 65c809196..4b4e11659 100644--- a/app/Http/Controllers/Auth/MfaBackupCodesController.php+++ b/app/Http/Controllers/Auth/MfaBackupCodesController.php@@ -49,6 +49,12 @@ class MfaBackupCodesController extends ControllerMfaValue::upsertWithValue($this->currentOrLastAttemptedUser(), MfaValue::METHOD_BACKUP_CODES, json_encode($codes));$this->logActivity(ActivityType::MFA_SETUP_METHOD, 'backup-codes');++ if (!auth()->check()) {+ $this->showSuccessNotification(trans('auth.mfa_setup_login_notification'));+ return redirect('/login');+ }+return redirect('/mfa/setup');}diff --git a/app/Http/Controllers/Auth/MfaTotpController.php b/app/Http/Controllers/Auth/MfaTotpController.phpindex a1701c4ce..d55f08cff 100644--- a/app/Http/Controllers/Auth/MfaTotpController.php+++ b/app/Http/Controllers/Auth/MfaTotpController.php@@ -61,6 +61,11 @@ class MfaTotpController extends Controllersession()->remove(static::SETUP_SECRET_SESSION_KEY);$this->logActivity(ActivityType::MFA_SETUP_METHOD, 'totp');+ if (!auth()->check()) {+ $this->showSuccessNotification(trans('auth.mfa_setup_login_notification'));+ return redirect('/login');+ }+return redirect('/mfa/setup');}diff --git a/app/Http/Middleware/AuthenticatedOrPendingMfa.php b/app/Http/Middleware/AuthenticatedOrPendingMfa.phpindex 2d68a2a57..febfef207 100644--- a/app/Http/Middleware/AuthenticatedOrPendingMfa.php+++ b/app/Http/Middleware/AuthenticatedOrPendingMfa.php@@ -36,6 +36,6 @@ class AuthenticatedOrPendingMfareturn $next($request);}- return redirect()->guest(url('/login'));+ return redirect()->to(url('/login'));}}diff --git a/resources/lang/en/auth.php b/resources/lang/en/auth.phpindex a24ededd7..e4d4c425b 100644--- a/resources/lang/en/auth.php+++ b/resources/lang/en/auth.php@@ -78,7 +78,7 @@ return [// Multi-factor Authentication'mfa_setup' => 'Setup Multi-Factor Authentication','mfa_setup_desc' => 'Setup multi-factor authentication as an extra layer of security for your user account.',- 'mfa_setup_configured' => 'Already Configured',+ 'mfa_setup_configured' => 'Already configured','mfa_setup_reconfigure' => 'Reconfigure','mfa_setup_remove_confirmation' => 'Are you sure you want to remove this multi-factor authentication method?','mfa_setup_action' => 'Setup',@@ -108,4 +108,5 @@ return ['mfa_verify_backup_code_desc' => 'Enter one of your remaining backup codes below:','mfa_verify_backup_code_enter_here' => 'Enter backup code here','mfa_verify_totp_desc' => 'Enter the code, generated using your mobile app, below:',+ 'mfa_setup_login_notification' => 'Multi-factor method configured, Please now login again using the configured method.',];\ No newline at end of filediff --git a/tests/Auth/AuthTest.php b/tests/Auth/AuthTest.phpindex 085482c35..b4b99d130 100644--- a/tests/Auth/AuthTest.php+++ b/tests/Auth/AuthTest.php@@ -419,6 +419,14 @@ class AuthTest extends BrowserKitTest$login->assertRedirectedTo('http://localhost');}+ public function test_login_intended_redirect_does_not_factor_mfa_routes()+ {+ $this->get('/books')->assertRedirectedTo('/login');+ $this->get('/mfa/setup')->assertRedirectedTo('/login');+ $login = $this->post('/login', ['email' => '[email protected]', 'password' => 'password']);+ $login->assertRedirectedTo('/books');+ }+public function test_login_authenticates_admins_on_all_guards(){$this->post('/login', ['email' => '[email protected]', 'password' => 'password']);diff --git a/tests/Auth/MfaVerificationTest.php b/tests/Auth/MfaVerificationTest.phpindex d007fa490..e63094303 100644--- a/tests/Auth/MfaVerificationTest.php+++ b/tests/Auth/MfaVerificationTest.php@@ -187,11 +187,15 @@ class MfaVerificationTest extends TestCase$resp->assertElementContains('a[href$="/mfa/setup"]', 'Configure');$this->get('/mfa/backup_codes/generate');- $this->followingRedirects()->post('/mfa/backup_codes/confirm');+ $resp = $this->post('/mfa/backup_codes/confirm');+ $resp->assertRedirect('/login');$this->assertDatabaseHas('mfa_values', ['user_id' => $user->id,]);+ $resp = $this->get('/login');+ $resp->assertSeeText('Multi-factor method configured, Please now login again using the configured method.');+$resp = $this->followingRedirects()->post('/login', ['email' => $user->email,'password' => 'password',