3 namespace BookStack\Auth\Access\Mfa;
5 use BookStack\Auth\User;
10 * Check if MFA is required for the given user.
12 public function isRequiredForUser(User $user): bool
14 // TODO - Test both these cases
15 return $user->mfaValues()->exists() || $this->userRoleEnforcesMfa($user);
19 * Check if a role of the given user enforces MFA.
21 protected function userRoleEnforcesMfa(User $user): bool
24 ->where('mfa_enforced', '=', true)
29 * Check if the current MFA session has already been verified for the given user.
31 public function isVerifiedForUser(User $user): bool
33 return session()->get($this->getMfaVerifiedSessionKey($user)) === 'true';
37 * Mark the current session as MFA-verified.
39 public function markVerifiedForUser(User $user): void
41 session()->put($this->getMfaVerifiedSessionKey($user), 'true');
45 * Get the session key in which the MFA verification status is stored.
47 protected function getMfaVerifiedSessionKey(User $user): string
49 return 'mfa-verification-passed:' . $user->id;