From 5484074d8e551327c12e8dbe1af50fb13222c397 Mon Sep 17 00:00:00 2001 From: Lorenzo Milesi Date: Tue, 23 Jan 2018 05:15:01 +0100 Subject: [PATCH] Enforce password change event only if set #102 --- src/User/Bootstrap.php | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/src/User/Bootstrap.php b/src/User/Bootstrap.php index b1b69ac..18fb8d2 100644 --- a/src/User/Bootstrap.php +++ b/src/User/Bootstrap.php @@ -147,17 +147,16 @@ class Bootstrap implements BootstrapInterface } // Attach an event to check if the password has expired - Event::on(SecurityController::class, FormEvent::EVENT_AFTER_LOGIN, function (FormEvent $event) { - if (is_null(Yii::$app->getModule('user')->maxPasswordAge)) { - return; - } - $user = $event->form->user; - if ($user->password_age >= Yii::$app->getModule('user')->maxPasswordAge) { - // Force password change - Yii::$app->session->setFlash('warning', Yii::t('usuario', 'Your password has expired, you must change it now')); - Yii::$app->response->redirect(['/user/settings/account'])->send(); - } - }); + if (!is_null(Yii::$app->getModule('user')->maxPasswordAge)) { + Event::on(SecurityController::class, FormEvent::EVENT_AFTER_LOGIN, function (FormEvent $event) { + $user = $event->form->user; + if ($user->password_age >= Yii::$app->getModule('user')->maxPasswordAge) { + // Force password change + Yii::$app->session->setFlash('warning', Yii::t('usuario', 'Your password has expired, you must change it now')); + Yii::$app->response->redirect(['/user/settings/account'])->send(); + } + }); + } if ($app instanceof WebApplication) { // override Yii