]> BookStack Code Mirror - bookstack/commitdiff
Added MFA setup link on user edit view
authorDan Brown <redacted>
Wed, 14 Jul 2021 19:06:41 +0000 (20:06 +0100)
committerDan Brown <redacted>
Wed, 14 Jul 2021 19:06:41 +0000 (20:06 +0100)
app/Http/Controllers/UserController.php
resources/views/users/edit.blade.php
tests/Auth/MfaConfigurationTest.php

index f7b2afef8d2e97d37db5ab1a7bea33bd002a0887..7f42e94ccbff1557e058563d822cafc7c4559585 100644 (file)
@@ -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,
         ]);
index 5712855e6125e393c865c6f4af1fdaf94c11f5c8..2d719668f65b3c65821d260df0f549a180f82811 100644 (file)
             </form>
         </section>
 
+        <section class="card content-wrap auto-height">
+            <h2 class="list-heading">Multi-Factor Authentication</h2>
+            <p>
+                Setup multi-factor authentication as an extra layer of security
+                for your user account.
+            </p>
+            <div class="grid half gap-xl v-center pb-s">
+                <div>
+                    @if ($mfaMethods->count() > 0)
+                        <span class="text-pos">@icon('check-circle')</span>
+                    @else
+                        <span class="text-neg">@icon('cancel')</span>
+                    @endif
+                    {{ $mfaMethods->count() }} {{ $mfaMethods->count() === 1 ? 'method' : 'methods' }} configured
+                </div>
+                <div class="text-m-right">
+                    @if($user->id === user()->id)
+                        <a href="{{ url('/mfa/setup')  }}" class="button outline">Configure Methods</a>
+                    @endif
+                </div>
+            </div>
+
+        </section>
+
         @if(user()->id === $user->id && count($activeSocialDrivers) > 0)
             <section class="card content-wrap auto-height">
                 <h2 class="list-heading">{{ trans('settings.users_social_accounts') }}</h2>
index 870850a73bc292fbb059fbe7ab5fe6f95ebfa3ed..f332b6721d56d16e132b6506ef31a87b9e0da0f8 100644 (file)
@@ -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
Morty Proxy This is a proxified and sanitized view of the page, visit original site.