Skip to content

Commit

Permalink
Merge pull request #519 from deadmantfa/master
Browse files Browse the repository at this point in the history
🐛 fix(2FA): Two Factor Authentication - Filter - Blocks even when two…
  • Loading branch information
maxxer authored Dec 15, 2023
2 parents 723ae81 + 4b1536f commit 739c0ca
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## dev

- Fix: Two Factor Authentication - Filter - Blocks even when two factor authentication is enabled
- Fix: update Dutch (nl) translations (squio)
- Enh: possibility to limit the depth of the recursion when getting user ids from roles (mp1509)

Expand Down
6 changes: 4 additions & 2 deletions src/User/Filter/TwoFactorAuthenticationEnforceFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,10 @@ public function beforeAction($action)
}

$permissions = $module->twoFactorAuthenticationForcedPermissions;
$itemsByUser = array_keys($this->getAuthManager()->getItemsByUser(Yii::$app->user->identity->id));
if (!empty(array_intersect($permissions, $itemsByUser))) {

$user = Yii::$app->user->identity;
$itemsByUser = array_keys($this->getAuthManager()->getItemsByUser($user->id));
if (!empty(array_intersect($permissions, $itemsByUser)) && !$user->auth_tf_enabled) {
Yii::$app->session->setFlash('warning', Yii::t('usuario', 'Your role requires 2FA, you won\'t be able to use the application until you enable it'));
return Yii::$app->response->redirect(['/user/settings/account'])->send();
}
Expand Down
7 changes: 6 additions & 1 deletion src/User/Service/MailService.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,16 @@ public function getType()
*/
public function run()
{
return $this->mailer
$result = $this->mailer
->compose(['html' => $this->view, 'text' => "text/{$this->view}"], $this->params)
->setFrom($this->from)
->setTo($this->to)
->setSubject($this->subject)
->send();

if (!$result) {
Yii::error("Email sending failed to '{$this->to}'.", 'mailer');
}
return $result;
}
}
2 changes: 1 addition & 1 deletion src/User/Validator/TwoFactorEmailValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,6 @@ public function getUnsuccessLoginMessage($codeDurationTime)
*/
public function generateCode()
{
return $this->make(TwoFactorEmailCodeGeneratorService::class, $this->user)->run();
return $this->make(TwoFactorEmailCodeGeneratorService::class, [$this->user])->run();
}
}

0 comments on commit 739c0ca

Please sign in to comment.