diff --git a/app/Http/Controllers/UserController.php b/app/Http/Controllers/UserController.php index f7b2afef8..7f42e94cc 100644 --- a/app/Http/Controllers/UserController.php +++ b/app/Http/Controllers/UserController.php @@ -128,12 +128,14 @@ class UserController extends Controller $authMethod = ($user->system_name) ? 'system' : config('auth.method'); $activeSocialDrivers = $socialAuthService->getActiveDrivers(); + $mfaMethods = user()->mfaValues()->get(['id', 'method'])->groupBy('method'); $this->setPageTitle(trans('settings.user_profile')); $roles = $this->userRepo->getAllRoles(); return view('users.edit', [ 'user' => $user, 'activeSocialDrivers' => $activeSocialDrivers, + 'mfaMethods' => $mfaMethods, 'authMethod' => $authMethod, 'roles' => $roles, ]); diff --git a/resources/views/users/edit.blade.php b/resources/views/users/edit.blade.php index 5712855e6..2d719668f 100644 --- a/resources/views/users/edit.blade.php +++ b/resources/views/users/edit.blade.php @@ -63,6 +63,30 @@ +
+

Multi-Factor Authentication

+

+ Setup multi-factor authentication as an extra layer of security + for your user account. +

+
+
+ @if ($mfaMethods->count() > 0) + @icon('check-circle') + @else + @icon('cancel') + @endif + {{ $mfaMethods->count() }} {{ $mfaMethods->count() === 1 ? 'method' : 'methods' }} configured +
+
+ @if($user->id === user()->id) + Configure Methods + @endif +
+
+ +
+ @if(user()->id === $user->id && count($activeSocialDrivers) > 0)

{{ trans('settings.users_social_accounts') }}

diff --git a/tests/Auth/MfaConfigurationTest.php b/tests/Auth/MfaConfigurationTest.php index 870850a73..f332b6721 100644 --- a/tests/Auth/MfaConfigurationTest.php +++ b/tests/Auth/MfaConfigurationTest.php @@ -106,4 +106,29 @@ class MfaConfigurationTest extends TestCase $resp->assertStatus(500); } + public function test_mfa_method_count_is_visible_on_user_edit_page() + { + $admin = $this->getAdmin(); + $resp = $this->actingAs($admin)->get($admin->getEditUrl()); + $resp->assertSee('0 methods configured'); + + MfaValue::upsertWithValue($admin, MfaValue::METHOD_TOTP, 'test'); + $resp = $this->actingAs($admin)->get($admin->getEditUrl()); + $resp->assertSee('1 method configured'); + + MfaValue::upsertWithValue($admin, MfaValue::METHOD_BACKUP_CODES, 'test'); + $resp = $this->actingAs($admin)->get($admin->getEditUrl()); + $resp->assertSee('2 methods configured'); + } + + public function test_mfa_setup_link_only_shown_when_viewing_own_user_edit_page() + { + $admin = $this->getAdmin(); + $resp = $this->actingAs($admin)->get($admin->getEditUrl()); + $resp->assertElementExists('a[href$="/mfa/setup"]'); + + $resp = $this->actingAs($admin)->get($this->getEditor()->getEditUrl()); + $resp->assertElementNotExists('a[href$="/mfa/setup"]'); + } + } \ No newline at end of file