Loading src/EventSubscriber/PasswordPolicyEventSubscriber.php +22 −2 Changes for src/EventSubscriber/PasswordPolicyEventSubscriber.php: 22 added lines, 2 removed lines. Original line number Diff line number Diff line Loading @@ -77,6 +77,7 @@ class PasswordPolicyEventSubscriber implements EventSubscriberInterface { public function checkForUserPasswordExpiration(RequestEvent $event) { $route_name = $this->request->attributes->get(RouteObjectInterface::ROUTE_NAME); $ignore_route = in_array($route_name, [ 'system.403', 'entity.user.edit_form', 'system.ajax', 'user.logout', Loading Loading @@ -105,8 +106,27 @@ class PasswordPolicyEventSubscriber implements EventSubscriberInterface { $user_expired = $user_expired['value']; } // Save the token passed in the URL when the user access the site via // one time login. $session = $this->request->getSession(); $token = $this->request->query->get('pass-reset-token'); if (isset($token)) { $session->set('pass-reset-token-password-policy', $token); } // Check if the hash saved in the session is the same as the one saved in // UserController::resetPassLogin() so the user is not redirected when // access the site via one time login. This will prevent the user to // populate manually the parameter. $token = $session->get('pass-reset-token-password-policy'); $pass_reset_token = $session->get('pass_reset_' . $user->id()); $is_hash_equal = FALSE; if (isset($token) && isset($pass_reset_token)) { $is_hash_equal = hash_equals($pass_reset_token, $token); } // @todo Consider excluding admins here. if ($user_expired && !$ignore_route && !$is_ajax) { if ($user_expired && !$ignore_route && !$is_ajax && !$is_hash_equal) { $url = new Url('entity.user.edit_form', ['user' => $user->id()]); $url = $url->setAbsolute()->toString(); $event->setResponse(new RedirectResponse($url)); Loading @@ -122,7 +142,7 @@ class PasswordPolicyEventSubscriber implements EventSubscriberInterface { */ public static function getSubscribedEvents() { // @todo Evaluate if there is a better place to add this check. $events[KernelEvents::REQUEST][] = ['checkForUserPasswordExpiration']; $events[KernelEvents::REQUEST][] = ['checkForUserPasswordExpiration', 28]; return $events; } Loading Loading
src/EventSubscriber/PasswordPolicyEventSubscriber.php +22 −2 Changes for src/EventSubscriber/PasswordPolicyEventSubscriber.php: 22 added lines, 2 removed lines. Original line number Diff line number Diff line Loading @@ -77,6 +77,7 @@ class PasswordPolicyEventSubscriber implements EventSubscriberInterface { public function checkForUserPasswordExpiration(RequestEvent $event) { $route_name = $this->request->attributes->get(RouteObjectInterface::ROUTE_NAME); $ignore_route = in_array($route_name, [ 'system.403', 'entity.user.edit_form', 'system.ajax', 'user.logout', Loading Loading @@ -105,8 +106,27 @@ class PasswordPolicyEventSubscriber implements EventSubscriberInterface { $user_expired = $user_expired['value']; } // Save the token passed in the URL when the user access the site via // one time login. $session = $this->request->getSession(); $token = $this->request->query->get('pass-reset-token'); if (isset($token)) { $session->set('pass-reset-token-password-policy', $token); } // Check if the hash saved in the session is the same as the one saved in // UserController::resetPassLogin() so the user is not redirected when // access the site via one time login. This will prevent the user to // populate manually the parameter. $token = $session->get('pass-reset-token-password-policy'); $pass_reset_token = $session->get('pass_reset_' . $user->id()); $is_hash_equal = FALSE; if (isset($token) && isset($pass_reset_token)) { $is_hash_equal = hash_equals($pass_reset_token, $token); } // @todo Consider excluding admins here. if ($user_expired && !$ignore_route && !$is_ajax) { if ($user_expired && !$ignore_route && !$is_ajax && !$is_hash_equal) { $url = new Url('entity.user.edit_form', ['user' => $user->id()]); $url = $url->setAbsolute()->toString(); $event->setResponse(new RedirectResponse($url)); Loading @@ -122,7 +142,7 @@ class PasswordPolicyEventSubscriber implements EventSubscriberInterface { */ public static function getSubscribedEvents() { // @todo Evaluate if there is a better place to add this check. $events[KernelEvents::REQUEST][] = ['checkForUserPasswordExpiration']; $events[KernelEvents::REQUEST][] = ['checkForUserPasswordExpiration', 28]; return $events; } Loading