]> BookStack Code Mirror - bookstack/blob - app/Http/Controllers/Auth/MfaController.php
Started on some MFA access-time checks
[bookstack] / app / Http / Controllers / Auth / MfaController.php
1 <?php
2
3 namespace BookStack\Http\Controllers\Auth;
4
5 use BookStack\Actions\ActivityType;
6 use BookStack\Auth\Access\Mfa\MfaValue;
7 use BookStack\Http\Controllers\Controller;
8
9 class MfaController extends Controller
10 {
11     /**
12      * Show the view to setup MFA for the current user.
13      */
14     public function setup()
15     {
16         $userMethods = user()->mfaValues()
17             ->get(['id', 'method'])
18             ->groupBy('method');
19         return view('mfa.setup', [
20             'userMethods' => $userMethods,
21         ]);
22     }
23
24     /**
25      * Remove an MFA method for the current user.
26      * @throws \Exception
27      */
28     public function remove(string $method)
29     {
30         if (in_array($method, MfaValue::allMethods())) {
31             $value = user()->mfaValues()->where('method', '=', $method)->first();
32             if ($value) {
33                 $value->delete();
34                 $this->logActivity(ActivityType::MFA_REMOVE_METHOD, $method);
35             }
36         }
37
38         return redirect('/mfa/setup');
39     }
40
41     /**
42      * Show the page to start an MFA verification.
43      */
44     public function verify()
45     {
46         $userMethods = user()->mfaValues()
47             ->get(['id', 'method'])
48             ->groupBy('method');
49
50         return view('mfa.verify', [
51             'userMethods' => $userMethods,
52         ]);
53     }
54 }