From b8de551514d3f82eeb2f14f276141edd3c2198bc Mon Sep 17 00:00:00 2001
From: Tom Udding = $this->translate('You might be able to view this page by logging in') ?>
= $this->translate('Login') ?> diff --git a/module/User/config/module.config.php b/module/User/config/module.config.php index c614955c03..82f295ab15 100644 --- a/module/User/config/module.config.php +++ b/module/User/config/module.config.php @@ -45,10 +45,9 @@ 'login' => [ 'type' => Segment::class, 'options' => [ - 'route' => '/login[/:user_type][/to/:redirect_to]', + 'route' => '/login[/:user_type]', 'constraints' => [ 'user_type' => '(company|member)', - 'redirect_to' => '[a-zA-Z0-9\+\=]+', ], 'defaults' => [ 'action' => 'login', diff --git a/module/User/src/Controller/UserController.php b/module/User/src/Controller/UserController.php index 9498119ca4..936208cb60 100644 --- a/module/User/src/Controller/UserController.php +++ b/module/User/src/Controller/UserController.php @@ -12,8 +12,6 @@ use Laminas\Mvc\I18n\Translator; use Laminas\Mvc\Plugin\FlashMessenger\FlashMessenger; use Laminas\View\Model\ViewModel; -use User\Form\CompanyUserLogin as CompanyLoginForm; -use User\Form\UserLogin as UserLoginForm; use User\Permissions\NotAllowedException; use User\Service\AclService; use User\Service\User as UserService; @@ -44,18 +42,19 @@ public function loginAction(): Response|ViewModel } $userType = $this->params()->fromRoute('user_type'); - $redirectTo = $this->params()->fromRoute('redirect_to'); + $redirectTo = $this->params()->fromQuery('redirect_to'); + + if ('company' === $userType) { + $form = $this->userService->getCompanyUserLoginForm(); + } else { + $form = $this->userService->getUserLoginForm(); + } /** @var Request $request */ $request = $this->getRequest(); if ($request->isPost()) { - if ('company' === $userType) { - $form = $this->userService->getCompanyUserLoginForm(); - } else { - $form = $this->userService->getUserLoginForm(); - } - $form->setData($request->getPost()->toArray()); + if ($form->isValid()) { $data = $form->getData(); @@ -67,50 +66,30 @@ public function loginAction(): Response|ViewModel if (null !== $login) { return $this->redirect()->toUrl( - $this->decodeRedirect(empty($data['redirect']) ? $redirectTo : $data['redirect']), + $this->decodeRedirect($redirectTo), ); } } } + if (null === $redirectTo) { + $redirectTo = base64_encode( + $this->url()->fromRoute( + route: 'home', + options: ['force_canonical' => true], + ), + ); + } + return new ViewModel( [ - 'form' => $this->handleRedirect($userType, $redirectTo), + 'form' => $form, + 'redirectTo' => $redirectTo, 'userType' => $userType, ], ); } - private function handleRedirect( - string $userType, - ?string $referer, - ): CompanyLoginForm|UserLoginForm { - if ('company' === $userType) { - $form = $this->userService->getCompanyUserLoginForm(); - } else { - $form = $this->userService->getUserLoginForm(); - } - - if (null === $form->get('redirect')->getValue()) { - if (null !== $referer) { - $form->get('redirect')->setValue($referer); - - return $form; - } - - $form->get('redirect')->setValue( - base64_encode( - $this->url()->fromRoute( - route: 'home', - options: ['force_canonical' => true], - ), - ), - ); - } - - return $form; - } - /** * Decode the base64 encoded referer, if it is not valid always return the home page. */ diff --git a/module/User/src/Form/CompanyUserLogin.php b/module/User/src/Form/CompanyUserLogin.php index dcab1a300e..91b4f34265 100644 --- a/module/User/src/Form/CompanyUserLogin.php +++ b/module/User/src/Form/CompanyUserLogin.php @@ -8,7 +8,6 @@ use Laminas\Filter\StringTrim; use Laminas\Form\Element\Csrf; use Laminas\Form\Element\Email; -use Laminas\Form\Element\Hidden; use Laminas\Form\Element\Password; use Laminas\Form\Element\Submit; use Laminas\Form\Form; @@ -56,13 +55,6 @@ public function __construct( ], ); - $this->add( - [ - 'name' => 'redirect', - 'type' => Hidden::class, - ], - ); - $this->add( [ 'name' => 'security', diff --git a/module/User/src/Form/UserLogin.php b/module/User/src/Form/UserLogin.php index c78549d785..4781ff8327 100644 --- a/module/User/src/Form/UserLogin.php +++ b/module/User/src/Form/UserLogin.php @@ -7,7 +7,6 @@ use Laminas\Authentication\Result; use Laminas\Form\Element\Checkbox; use Laminas\Form\Element\Csrf; -use Laminas\Form\Element\Hidden; use Laminas\Form\Element\Password; use Laminas\Form\Element\Submit; use Laminas\Form\Element\Text; @@ -68,13 +67,6 @@ public function __construct( ], ); - $this->add( - [ - 'name' => 'redirect', - 'type' => Hidden::class, - ], - ); - $this->add( [ 'name' => 'security', diff --git a/module/User/view/partial/login/company.phtml b/module/User/view/partial/login/company.phtml index cb38778665..47f1215f79 100644 --- a/module/User/view/partial/login/company.phtml +++ b/module/User/view/partial/login/company.phtml @@ -9,6 +9,7 @@ use User\Form\CompanyUserLogin as CompanyUserLoginForm; /** * @var PhpRenderer|HelperTrait $this * @var CompanyUserLoginForm $form + * @var string $redirectTo */ $form->prepare(); @@ -17,10 +18,8 @@ $form->setAttribute( 'action', $this->url( 'user/login', - [ - 'user_type' => 'company', - 'redirect_to' => base64_encode($this->serverUrl(true)), - ], + ['user_type' => 'company'], + ['query' => ['redirect_to' => $redirectTo]], ), ); $form->setAttribute('method', 'post'); @@ -63,8 +62,6 @@ $form->setAttribute('class', 'form-horizontal'); - = $this->formInput($form->get('redirect')) ?> -