I'm currently developing a PHP Laminas Framework application, and I've encountered a routing problem.
Here's the situation: When a user attempts to log in, if their password has expired, they're automatically redirected to the '/password-reset' route. After the user successfully updates their password, they should be redirected to the '/login' route. However, even though the login form is displayed correctly, the URL remains at '/password-reset'.
How can I address and resolve this routing issue?
codes
routes.php
// password reset route
'password-reset' => [
'type' => 'Literal',
'priority' => 9999,
'may_terminate' => true,
'options' => [
'route' => '/password-reset',
'defaults' => [
'controller' => 'Authentication\Controller\Authentication',
'action' => 'password-reset'
]
]
],
// login route
'login' => [
'type' => 'Segment',
'priority' => 9999,
'may_terminate' => true,
'options' => [
'route' => '/login[/:identity]',
'scheme' => 'https',
'constraints' => [
'identity' => '[[email protected]]*'
],
'defaults' => [
'controller' => 'Authentication\Controller\Authentication',
'action' => 'login'
]
]
],
Password expiry check and redirect to password reset page in loginAction()
if ($passwordExpiryDate['passwordExpiryDate'] && $currentDate >= $passwordExpiryDate['passwordExpiryDate']) {
return $this->redirect()->toRoute('password-reset');
} else {
// login
$learner = $service->login($data['identity'], $data['password']);
}
passwordResetAction
// get user email
$userEmail = $post['email'];
$learnerService = $this->learnerService();
$userId = $learnerService->getUserIdByEmail($userEmail);
// validate form
$data = $form->validate($post);
// change password and save
$user = $learnerService->changePassword($userId['userId'], $data);
// success
$message['success'] = $this->translate('Password reset successfully. Please return to the login page to continue.');
if (!$request->isXmlHttpRequest()) {
$this->flashMessenger()->addSuccessMessage($message['success']);
}
return $this->redirect()->toRoute('login');