From 48bbf90570291a11e0a5f958fe4fef40db1340ff Mon Sep 17 00:00:00 2001
From: llaffont <llaffont@afi-sa.fr>
Date: Thu, 18 Sep 2014 11:50:18 +0200
Subject: [PATCH] authentification strategies are now the same as desktop
 version

---
 .../telephone/controllers/AuthController.php  | 35 +++++++++++++------
 library/ZendAfi/Form/NewsletterRegister.php   |  3 --
 .../opac/controllers/AuthControllerTest.php   |  2 +-
 .../controllers/AuthControllerTest.php        | 17 ++++-----
 .../controllers/CasServerControllerTest.php   | 14 ++++++--
 5 files changed, 45 insertions(+), 26 deletions(-)

diff --git a/application/modules/telephone/controllers/AuthController.php b/application/modules/telephone/controllers/AuthController.php
index 44132c8a933..c665b804b86 100644
--- a/application/modules/telephone/controllers/AuthController.php
+++ b/application/modules/telephone/controllers/AuthController.php
@@ -16,7 +16,7 @@
  *
  * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE
  * along with AFI-OPAC 2.0; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA 
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA
  */
 
 require_once ROOT_PATH.'application/modules/opac/controllers/AuthController.php';
@@ -35,24 +35,39 @@ class Telephone_AuthController extends AuthController {
 
 
 	public function loginAction() {
-		$this->_loginCommon('/abonne');
+		$this->view->preferences = Class_Profil::getCurrentProfil()->getCfgModulesPreferences('auth','login');
+		$redirect = $this->_getParam('redirect', '/abonne');
+		$this->view->redirect = $redirect;
+		$service = $this->_getParam('service','');
+		$this->view->service = $service;
+		$this->view->titre = $this->view->_('Connexion');
+
+		$strategy = Auth_Strategy_Abstract::strategyForController($this);
+		$strategy->setDefaultUrl($redirect);
+		$strategy->processLogin();
+		$this->_loginCommon();
 		$this->render('login-reservation');
 	}
 
 
-	public function loginReservationAction() {
-		$this->_loginCommon('/recherche/reservation');
-		$this->view->id_notice = $this->_getParam('id');
+	public function getRedirectDefaultUrl() {
+		return $this->_request->getParam('redirect','/abonne');
 	}
 
 
-
-	protected function _loginCommon($redirectUrl) {
+	public function loginReservationAction() {
 		if (Class_Users::getLoader()->hasIdentity()) {
-			$this->_redirect($redirectUrl);
+			$this->_redirect('/recherche/reservation');
 			return;
 		}
 
+		$this->_loginCommon();
+		$this->view->id_notice = $this->_getParam('id');
+	}
+
+
+
+	protected function _loginCommon() {
 		$form = $this->_getFormLogin();
 		if ($this->_request->isPost()) {
 			if (!($error = $this->_authenticate())) {
@@ -63,14 +78,14 @@ class Telephone_AuthController extends AuthController {
 			$this->_flashMessenger->addMessage($error);
 			$this->_redirect($this->view->url(), array('prependBase' => false));
 		}
-		
+
 		$this->view->error = $this->_flashMessenger->getMessages();
 		$this->view->form = $form;
 	}
 
 
 	protected function _getFormLogin() {
-		
+
 		$settings = array_merge(['identifiant_exemple' => $this->view->_('N° de carte'),
 														 'mot_de_passe_exemple' => $this->view->_('Mot de passe ou date de naissance')],
 														Class_Profil::getPortail()->getModuleAccueilPreferencesByType('LOGIN'));
diff --git a/library/ZendAfi/Form/NewsletterRegister.php b/library/ZendAfi/Form/NewsletterRegister.php
index 354044de128..22f6ec021c0 100644
--- a/library/ZendAfi/Form/NewsletterRegister.php
+++ b/library/ZendAfi/Form/NewsletterRegister.php
@@ -21,9 +21,6 @@
 
 
 class ZendAfi_Form_NewsletterRegister extends ZendAfi_Form {
-	use Trait_Translator;
-
-
 	public function init() {
 		parent::init();
 		$this
diff --git a/tests/application/modules/opac/controllers/AuthControllerTest.php b/tests/application/modules/opac/controllers/AuthControllerTest.php
index 41fbd8ca896..392a4135e57 100644
--- a/tests/application/modules/opac/controllers/AuthControllerTest.php
+++ b/tests/application/modules/opac/controllers/AuthControllerTest.php
@@ -1656,7 +1656,7 @@ class AuthControllerPostRegisterNewsletterDailyNewsTest extends AuthControllerNo
 
 	/** @test */
 	public function mailShouldContainsAccountMessage() {
-		$this->assertContains("Un compte vous a été créé automatiquement.\n\nCelui-ci vous permet de vous connecter en temps qu'invité et de vous désincrire de la newsletter.", $this->getSentMailContent());
+		$this->assertContains("Un compte vous a été créé automatiquement.", $this->getSentMailContent());
 	}
 
 
diff --git a/tests/application/modules/telephone/controllers/AuthControllerTest.php b/tests/application/modules/telephone/controllers/AuthControllerTest.php
index e0a3d5ceba0..ffb0e68113d 100644
--- a/tests/application/modules/telephone/controllers/AuthControllerTest.php
+++ b/tests/application/modules/telephone/controllers/AuthControllerTest.php
@@ -16,7 +16,7 @@
  *
  * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE
  * along with AFI-OPAC 2.0; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA 
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA
  */
 require_once 'TelephoneAbstractControllerTestCase.php';
 
@@ -64,12 +64,9 @@ class AuthControllerTelephoneBoiteLoginTest extends AuthControllerTelephoneWitho
 class AuthControllerTelephoneLoginTest extends AuthControllerTelephoneWithoutCommSIGBTestCase {
 	public function setUp() {
 		parent::setUp();
-		Class_Profil::getCurrentProfil()
-			->setCfgAccueil(array());
+		Class_Profil::getCurrentProfil()->setCfgAccueil([]);
 
-		Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Users')
-			->whenCalled('hasIdentity')
-			->answers(false);
+		ZendAfi_Auth::getInstance()->clearIdentity();
 
 		$this->dispatch('auth/login', true);
 	}
@@ -77,7 +74,7 @@ class AuthControllerTelephoneLoginTest extends AuthControllerTelephoneWithoutCom
 
 	/** @test */
 	public function pageShouldContainsLoginInput() {
-		$this->assertXPath('//form//input[@name="username"]');
+		$this->assertXPath('//form//input[@name="username"]', $this->_response->getBody());
 	}
 
 
@@ -92,7 +89,7 @@ class AuthControllerTelephoneLoginTest extends AuthControllerTelephoneWithoutCom
 class AuthControllerTelephoneLoginReservationTest extends AuthControllerTelephoneWithoutCommSIGBTestCase {
 	public function setUp() {
 		parent::setUp();
-		
+
 		$this->fixture('Class_Profil', [
 										 'id' => 1,
 										 'cfg_accueil' => [
@@ -107,7 +104,7 @@ class AuthControllerTelephoneLoginReservationTest extends AuthControllerTelephon
 																 'type_module' => 'LOGIN',
 																 'preferences' => ['identifiant_exemple' => 'identity',
 																									 'mot_de_passe_exemple' => 'password']]]]]);
-		
+
 		Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Users')
 			->whenCalled('hasIdentity')
 			->answers(false);
@@ -133,7 +130,7 @@ class AuthControllerTelephoneLoginReservationTest extends AuthControllerTelephon
 		$this->assertXPath('//form//input[@placeholder="identity"]',$this->_response->getBody());
 	}
 
-	
+
 	/** @test */
 	public function pageShouldContainsPlaceHollderPasswordIdentity() {
 		$this->assertXPath('//form//input[@placeholder="password"]', $this->_response->getBody());
diff --git a/tests/application/modules/telephone/controllers/CasServerControllerTest.php b/tests/application/modules/telephone/controllers/CasServerControllerTest.php
index 4a7506af44a..c88cc8f00c2 100644
--- a/tests/application/modules/telephone/controllers/CasServerControllerTest.php
+++ b/tests/application/modules/telephone/controllers/CasServerControllerTest.php
@@ -36,17 +36,27 @@ class Telephone_CasServerControllerTest extends TelephoneAbstractControllerTestC
 
 	/** @test */
 	public function requestWithValidTicketResponseShouldContainsValidXML() {
-		$this->dispatch('/opac/cas-server/validate?ticket='.md5(Zend_Session::getId().'300').'&service=http://test.com', true);
+		$this->dispatch('/telephone/cas-server/validate?ticket='.md5(Zend_Session::getId().'300').'&service=http://test.com', true);
 		$this->assertContains('<cas:user>300</cas:user>', $this->_response->getBody());
 	}
 
 
 	/** @test */
 	public function requestOnV10WithValidTicketResponseShouldContainsGeorges87364() {
-		$this->dispatch('/opac/cas-server-v10/validate?ticket='.md5(Zend_Session::getId().'300').'&service=http://test.com', true);
+		$this->dispatch('/telephone/cas-server-v10/validate?ticket='.md5(Zend_Session::getId().'300').'&service=http://test.com', true);
 		$this->assertContains('georges|87364', $this->_response->getBody());
 	}
 
+
+	/** @test */
+	public function loginOnCasOneZeroShouldRedirectToServiceWithTicket() {
+		$this->dispatch('/telephone/cas-server-v10/login?service=http://test.com', true);
+		$this->assertRedirectTo(
+			'http://test.com?ticket='.(new Class_CasTicket())->getTicketForCurrentUser(),
+			$this->getResponseLocation());
+	}
+
+
 }
 
 ?>
-- 
GitLab