2021-06-28 17:02:45 -04:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace BookStack\Http\Controllers\Auth;
|
|
|
|
|
2021-07-14 16:27:21 -04:00
|
|
|
use BookStack\Actions\ActivityType;
|
|
|
|
use BookStack\Auth\Access\Mfa\MfaValue;
|
2021-06-28 17:02:45 -04:00
|
|
|
use BookStack\Http\Controllers\Controller;
|
|
|
|
|
|
|
|
class MfaController extends Controller
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Show the view to setup MFA for the current user.
|
|
|
|
*/
|
|
|
|
public function setup()
|
|
|
|
{
|
2021-06-30 17:10:02 -04:00
|
|
|
$userMethods = user()->mfaValues()
|
|
|
|
->get(['id', 'method'])
|
|
|
|
->groupBy('method');
|
|
|
|
return view('mfa.setup', [
|
|
|
|
'userMethods' => $userMethods,
|
|
|
|
]);
|
2021-06-28 17:02:45 -04:00
|
|
|
}
|
2021-07-14 16:27:21 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove an MFA method for the current user.
|
|
|
|
* @throws \Exception
|
|
|
|
*/
|
|
|
|
public function remove(string $method)
|
|
|
|
{
|
|
|
|
if (in_array($method, MfaValue::allMethods())) {
|
|
|
|
$value = user()->mfaValues()->where('method', '=', $method)->first();
|
|
|
|
if ($value) {
|
|
|
|
$value->delete();
|
|
|
|
$this->logActivity(ActivityType::MFA_REMOVE_METHOD, $method);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return redirect('/mfa/setup');
|
|
|
|
}
|
2021-07-16 18:23:36 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Show the page to start an MFA verification.
|
|
|
|
*/
|
|
|
|
public function verify()
|
|
|
|
{
|
|
|
|
$userMethods = user()->mfaValues()
|
|
|
|
->get(['id', 'method'])
|
|
|
|
->groupBy('method');
|
|
|
|
|
|
|
|
return view('mfa.verify', [
|
|
|
|
'userMethods' => $userMethods,
|
|
|
|
]);
|
|
|
|
}
|
2021-06-28 17:02:45 -04:00
|
|
|
}
|