diff --git a/application/modules/opac/controllers/AuthController.php b/application/modules/opac/controllers/AuthController.php index f8c49e228f4271b341b3248baec326fd5fb15264..7cd549d522242c32a3b1c15bb10b557c3692e7c8 100644 --- a/application/modules/opac/controllers/AuthController.php +++ b/application/modules/opac/controllers/AuthController.php @@ -81,6 +81,8 @@ class AuthController extends Zend_Controller_Action $error = (int)$this->_getParam('error'); $viewRenderer = $this->getHelper('ViewRenderer'); $viewRenderer->setLayoutScript('module.phtml'); + $redirect = $this->_getParam('redirect', $this->_request->getPost('redirect')); + $this->view->redirect = $redirect; $service_cas_server=$this->_request->getPost('service'); if (strlen($this->_getParam('service'))>0) { @@ -101,9 +103,10 @@ class AuthController extends Zend_Controller_Action if (strlen($service_cas_server)>1) return; - if (isset($_SESSION["abonne_redirect"])) { + if ($redirect) { + $this->getHelper('ViewRenderer')->setNoRender(); $this->getResponse()->setHeader('Content-Type', 'text/html;charset=utf-8'); - $this->getResponse()->setBody("<script>window.location.replace('" .$_SESSION["abonne_redirect"] . "');</script>"); + $this->getResponse()->setBody("<script>window.location.replace('" .urldecode($redirect). "');</script>"); return; } diff --git a/application/modules/opac/controllers/PanierController.php b/application/modules/opac/controllers/PanierController.php index 471c421daa317789cc3c463a3873f6a5e4e0fec3..e013cce9033e513eb3f34de02676d603e9184602 100644 --- a/application/modules/opac/controllers/PanierController.php +++ b/application/modules/opac/controllers/PanierController.php @@ -23,16 +23,16 @@ class PanierController extends Zend_Controller_Action { use Trait_Translator; private $_user = null; // User connecté (auth) - function init() { + function preDispatch() { if ('ajout-ajax' == $this->_getParam('action')) return; - if (!$this->_user = Class_Users::getIdentity()) { - $_SESSION["abonne_redirect"]=$this->_request->REQUEST_URI; - $this->_redirect('opac/auth/login'); + if (!$this->_user = Class_Users::getIdentity()) { + $this->_forward('login', 'auth', 'opac', ['redirect' => $this->_request->REQUEST_URI]); } } + function indexAction() { $id_panier_courant = $this->_getParam("id_panier", 0); $panier_courant = Class_PanierNotice::find($id_panier_courant); diff --git a/application/modules/opac/views/scripts/auth/login.phtml b/application/modules/opac/views/scripts/auth/login.phtml index 2eebb28b829cf0c43cfa35a2338c32651420bd04..ffb6d3cb4767a2b27ccdaf1573927edbd85043b6 100644 --- a/application/modules/opac/views/scripts/auth/login.phtml +++ b/application/modules/opac/views/scripts/auth/login.phtml @@ -35,7 +35,11 @@ </td> </tr> </table> - <?php echo $this->bouton('type=V', 'form=form_login'); ?> + <?php + if ($this->redirect) + echo '<input type="hidden" name="redirect" value="'.$this->redirect.'">'; + echo $this->bouton('type=V', 'form=form_login'); + ?> </form> <?php if ($this->message) {?> diff --git a/tests/application/modules/opac/controllers/AuthControllerTest.php b/tests/application/modules/opac/controllers/AuthControllerTest.php index 5fd55a2b06b3a4687b78209242eab2fd4006589e..fb85b27f83de805a33213b7eac87a5b949cf563a 100644 --- a/tests/application/modules/opac/controllers/AuthControllerTest.php +++ b/tests/application/modules/opac/controllers/AuthControllerTest.php @@ -324,6 +324,20 @@ class AuthControllerNobodyLoggedTest extends PortailWithOneLoginModuleTestCase { public function pageShouldBeHtml5Valid() { $this->assertHTML5($this->_response->getBody()); } + + + /** @test */ + public function pageShouldNotContainsRedirectInput() { + $this->assertNotXPath('//input[@name="redirect"]'); + } + + + /** @test */ + public function withRedirectParamPageShouldContainsRedirectInput() { + $this->bootstrap(); + $this->dispatch('/opac/auth/login/redirect/'.urlencode('/opac/paniers')); + $this->assertXPath('//input[@name="redirect"][@value="/opac/paniers"]'); + } } @@ -507,6 +521,26 @@ class AuthControllerPostSimpleSuccessfulTest extends AuthControllerPostSimpleSuc +class AuthControllerPostSimpleSuccessfulWithRedirectTest extends AuthControllerPostSimpleSuccessfulTestCase { + public function setUp() { + parent::setUp(); + + $this->postDispatch('/opac/auth/login', + ['username' => 'foo', + 'password' => 'bar', + 'redirect' => '/opac/paniers']); + } + + + /** @test */ + public function responseShouldBeAJSThatRedirectsToPaniers() { + $this->assertXPathContentContains('//script', 'replace(\'/opac/paniers\'', $this->_response->getBody()); + } +} + + + + class AuthControllerPostSuccessfulFromCASClientTest extends AuthControllerPostSimpleSuccessfulTestCase { public function setUp() { parent::setUp(); diff --git a/tests/application/modules/opac/controllers/PanierControllerTest.php b/tests/application/modules/opac/controllers/PanierControllerTest.php index baece07e17dda481b6866025d2d65cb79cfe63f6..c8fdb25b22a4cd1b6da1e46400108a1f9665169f 100644 --- a/tests/application/modules/opac/controllers/PanierControllerTest.php +++ b/tests/application/modules/opac/controllers/PanierControllerTest.php @@ -601,6 +601,23 @@ class PanierControllerAjoutAjaxNotLoggedTest extends PanierControllerTestCase { +class PanierControllerNotLoggedTest extends PanierControllerTestCase { + public function setUp() { + parent::setUp(); + ZendAfi_Auth::getInstance()->getStorage()->clear(); + $this->dispatch('/panier/index',true); + } + + + /** @test */ + public function responseShouldRenderLoginForm() { + $this->assertXPath('//input[@name="username"]'); + } +} + + + + class PanierControllerAjoutAjaxLoggedManonWithoutPanierTest extends PanierControllerTestCase { protected $_xpath, $_response;