From 4a1fe662cc7b10b946f92ffa4ecf7751ea9777c1 Mon Sep 17 00:00:00 2001
From: Bertrand GAUTHIER <bertrand.gauthier@unicaen.fr>
Date: Thu, 24 Jun 2021 11:16:46 +0200
Subject: [PATCH] =?UTF-8?q?[FIX]=20En=20cas=20de=20requete=20de=20connexio?=
 =?UTF-8?q?n=20alors=20que=20l'utilisateur=20est=20d=C3=A9j=C3=A0=20authen?=
 =?UTF-8?q?tifi=C3=A9,=20les=20query=20params=20'redirect'=20et=20'role'?=
 =?UTF-8?q?=20doivent=20etre=20pris=20en=20compte?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 src/UnicaenAuth/Controller/AuthController.php | 8 ++++++++
 src/UnicaenAuth/Service/UserContext.php       | 2 +-
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/src/UnicaenAuth/Controller/AuthController.php b/src/UnicaenAuth/Controller/AuthController.php
index 94cf493..30d2747 100644
--- a/src/UnicaenAuth/Controller/AuthController.php
+++ b/src/UnicaenAuth/Controller/AuthController.php
@@ -114,6 +114,14 @@ class AuthController extends AbstractActionController
     public function loginAction()
     {
         if ($this->zfcUserAuthentication()->hasIdentity()) {
+            $roleId = $this->params()->fromPost('role', $this->params()->fromQuery('role', false));
+            if ($roleId) {
+                $this->serviceUserContext->setSelectedIdentityRole($roleId);
+            }
+            if ($this->getRequestedRedirect()) {
+                $redirect = $this->redirectCallback;
+                return $redirect();
+            }
             return $this->redirect()->toRoute($this->moduleOptions->getLoginRedirectRoute());
         }
 
diff --git a/src/UnicaenAuth/Service/UserContext.php b/src/UnicaenAuth/Service/UserContext.php
index da6eb99..c1131c2 100644
--- a/src/UnicaenAuth/Service/UserContext.php
+++ b/src/UnicaenAuth/Service/UserContext.php
@@ -325,7 +325,7 @@ class UserContext extends AbstractService implements EventManagerAwareInterface
     {
         if ($role) {
             if (!$this->isRoleValid($role)) {
-                throw new RuntimeException("Rôle spécifié invalide.");
+                throw new RuntimeException("Rôle spécifié invalide : '$role'");
             }
             if ($role instanceof RoleInterface) {
                 $role = $role->getRoleId();
-- 
GitLab