diff --git a/app/Actions/ActivityType.php b/app/Actions/ActivityType.php index e2e7b5a5d..60b1630e0 100644 --- a/app/Actions/ActivityType.php +++ b/app/Actions/ActivityType.php @@ -52,4 +52,5 @@ class ActivityType const AUTH_REGISTER = 'auth_register'; const MFA_SETUP_METHOD = 'mfa_setup_method'; + const MFA_REMOVE_METHOD = 'mfa_remove_method'; } diff --git a/app/Auth/Access/Mfa/MfaValue.php b/app/Auth/Access/Mfa/MfaValue.php index cba90dcac..9f9ab29a5 100644 --- a/app/Auth/Access/Mfa/MfaValue.php +++ b/app/Auth/Access/Mfa/MfaValue.php @@ -21,6 +21,14 @@ class MfaValue extends Model const METHOD_TOTP = 'totp'; const METHOD_BACKUP_CODES = 'backup_codes'; + /** + * Get all the MFA methods available. + */ + public static function allMethods(): array + { + return [self::METHOD_TOTP, self::METHOD_BACKUP_CODES]; + } + /** * Upsert a new MFA value for the given user and method * using the provided value. diff --git a/app/Http/Controllers/Auth/MfaController.php b/app/Http/Controllers/Auth/MfaController.php index caee416d3..9feda9433 100644 --- a/app/Http/Controllers/Auth/MfaController.php +++ b/app/Http/Controllers/Auth/MfaController.php @@ -2,6 +2,8 @@ namespace BookStack\Http\Controllers\Auth; +use BookStack\Actions\ActivityType; +use BookStack\Auth\Access\Mfa\MfaValue; use BookStack\Http\Controllers\Controller; class MfaController extends Controller @@ -18,4 +20,21 @@ class MfaController extends Controller 'userMethods' => $userMethods, ]); } + + /** + * 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'); + } } diff --git a/resources/lang/en/activities.php b/resources/lang/en/activities.php index 2c371729b..50bda60bd 100644 --- a/resources/lang/en/activities.php +++ b/resources/lang/en/activities.php @@ -49,6 +49,7 @@ return [ // MFA 'mfa_setup_method_notification' => 'Multi-factor method successfully configured', + 'mfa_remove_method_notification' => 'Multi-factor method successfully removed', // Other 'commented_on' => 'commented on', diff --git a/resources/sass/_layout.scss b/resources/sass/_layout.scss index 516d7d612..e26948301 100644 --- a/resources/sass/_layout.scss +++ b/resources/sass/_layout.scss @@ -181,6 +181,10 @@ body.flexbox { display: inline-block !important; } +.relative { + position: relative; +} + .hidden { display: none !important; } diff --git a/resources/views/mfa/setup.blade.php b/resources/views/mfa/setup.blade.php index c98d78885..2ec8d0f77 100644 --- a/resources/views/mfa/setup.blade.php +++ b/resources/views/mfa/setup.blade.php @@ -26,6 +26,17 @@ Already configured Reconfigure +