Skip to content

Commit

Permalink
Enhanced ValidateAuthenticationFilter and not-allowed-ip filter to ha…
Browse files Browse the repository at this point in the history
…ndle cases when user is not authenticated yet
  • Loading branch information
SilverFire committed Aug 8, 2017
1 parent c82ddcc commit cea0e53
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 4 deletions.
9 changes: 8 additions & 1 deletion src/controllers/AllowedIpsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,15 @@ public function behaviors()
'allow' => true,
'matchCallback' => function ($action) {
$filter = new ValidateAuthenticationFilter();

$identity = Yii::$app->user->identity ?: $this->module->getHalfUser();

if ($identity === null) {
return false;
}

try {
$filter->validateAuthentication(Yii::$app->user->identity);
$filter->validateAuthentication($identity);
} catch (AuthenticationException $e) {
// Show this page only when user have problems with IP
return true;
Expand Down
5 changes: 3 additions & 2 deletions src/filters/ValidateAuthenticationFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,12 @@ class ValidateAuthenticationFilter extends ActionFilter

public function beforeAction($action)
{
if (Yii::$app->user->isGuest) {
$identity = Yii::$app->user->identity;

if (Yii::$app->user->isGuest || $identity === null) {
return $this->denyAccess(new NotAuthenticatedException());
}

$identity = Yii::$app->user->identity;
try {
$this->validateAuthentication($identity);
} catch (AuthenticationException $e) {
Expand Down
1 change: 1 addition & 0 deletions src/messages/ru/mfa.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,5 @@
'Wrong verification code. Please verify your secret and try again.' => 'Неправильный проверочный код. Пожалуйста, проверьте ваш секретный код и попробуйте снова.',
'You are not allowed to login from this IP' => 'Вам не разрешен доступ с этого IP',
'enter this text code instead' => 'введите этот код',
'Or log out and sign in as a different user' => 'Или выйти и зайти другим пользователем'
];
6 changes: 5 additions & 1 deletion src/views/allowed-ips/notAllowedIp.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,9 @@
</p>

<p align="center">
<?= Html::a(Yii::t('mfa', 'Add this IP to the list of allowed IPs'), ['token' => 'send']) ?>
<b><?= Html::a(Yii::t('mfa', 'Add this IP to the list of allowed IPs'), ['token' => 'send']) ?></b>
</p>

<p align="center">
<?= Html::a(Yii::t('mfa', 'Or log out and sign in as a different user'), ['/site/logout']) ?>
</p>

0 comments on commit cea0e53

Please sign in to comment.