Merge pull request #519 from deadmantfa/master

🐛 fix(2FA): Two Factor Authentication - Filter - Blocks even when two…
This commit is contained in:
Lorenzo Milesi
2023-12-15 12:14:54 +01:00
committed by GitHub
4 changed files with 12 additions and 4 deletions

View File

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

View File

@ -38,8 +38,10 @@ class TwoFactorAuthenticationEnforceFilter extends ActionFilter
} }
$permissions = $module->twoFactorAuthenticationForcedPermissions; $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')); 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(); return Yii::$app->response->redirect(['/user/settings/account'])->send();
} }

View File

@ -83,11 +83,16 @@ class MailService implements ServiceInterface
*/ */
public function run() public function run()
{ {
return $this->mailer $result = $this->mailer
->compose(['html' => $this->view, 'text' => "text/{$this->view}"], $this->params) ->compose(['html' => $this->view, 'text' => "text/{$this->view}"], $this->params)
->setFrom($this->from) ->setFrom($this->from)
->setTo($this->to) ->setTo($this->to)
->setSubject($this->subject) ->setSubject($this->subject)
->send(); ->send();
if (!$result) {
Yii::error("Email sending failed to '{$this->to}'.", 'mailer');
}
return $result;
} }
} }

View File

@ -111,6 +111,6 @@ class TwoFactorEmailValidator extends TwoFactorCodeValidator
*/ */
public function generateCode() public function generateCode()
{ {
return $this->make(TwoFactorEmailCodeGeneratorService::class, $this->user)->run(); return $this->make(TwoFactorEmailCodeGeneratorService::class, [$this->user])->run();
} }
} }