php Laminas框架布线问题

mwngjboj  于 2023-09-29  发布在  PHP
关注(0)|答案(1)|浏览(116)

我目前正在开发一个PHP Laminas Framework应用程序,我遇到了一个路由问题。
情况是这样的:当用户尝试登录时,如果他们的密码已过期,他们将自动重定向到' /password-reset '路由。用户成功更新密码后,他们应该被重定向到' /login '路由。但是,即使登录表单正确显示,URL仍然是“/password-reset”。
如何处理和解决此路由问题?

编码

  • 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'
                    ]
                ]
            ],

密码过期检查并重定向到loginAction()中的密码重置页面

if ($passwordExpiryDate['passwordExpiryDate'] && $currentDate >= $passwordExpiryDate['passwordExpiryDate']) {
                return $this->redirect()->toRoute('password-reset');
            } else {
                // login
                $learner = $service->login($data['identity'], $data['password']);
            }

密码重置操作

// 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');
l7mqbcuq

l7mqbcuq1#

login的路由定义是什么样的?
(我对Laminas一无所知,但也许这些额外的信息会帮助其他人解决你的问题。

相关问题