Skip to content

Commit

Permalink
refactor core/Middleware
Browse files Browse the repository at this point in the history
Signed-off-by: Hamid Dehnavi <hamid.dev.pro@gmail.com>
  • Loading branch information
shdehnavi committed Jul 5, 2023
1 parent 6862ff2 commit e59c535
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions core/Middleware/TwoFactorMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,11 @@ public function __construct(
/**
* @param Controller $controller
* @param string $methodName
* @throws TwoFactorAuthRequiredException
* @throws UserAlreadyLoggedInException
* @throws Exception
*/
public function beforeController($controller, $methodName) {
public function beforeController(Controller $controller, string $methodName): void {
if ($this->reflector->hasAnnotation('NoTwoFactorRequired')) {
// Route handler explicitly marked to work without finished 2FA are
// not blocked
Expand Down Expand Up @@ -111,7 +114,11 @@ public function beforeController($controller, $methodName) {
// TODO: dont check/enforce 2FA if a auth token is used
}

private function checkTwoFactor(Controller $controller, $methodName, IUser $user) {
/**
* @throws UserAlreadyLoggedInException
* @throws TwoFactorAuthRequiredException
*/
private function checkTwoFactor(Controller $controller, $methodName, IUser $user): void {
// If two-factor auth is in progress disallow access to any controllers
// defined within "LoginController".
$needsSecondFactor = $this->twoFactorManager->needsSecondFactor($user);
Expand All @@ -129,7 +136,7 @@ private function checkTwoFactor(Controller $controller, $methodName, IUser $user
}
}

public function afterException($controller, $methodName, Exception $exception) {
public function afterException($controller, $methodName, Exception $exception): RedirectResponse {
if ($exception instanceof TwoFactorAuthRequiredException) {
$params = [];
if (isset($this->request->server['REQUEST_URI'])) {
Expand Down

0 comments on commit e59c535

Please sign in to comment.