From 9af222119c2259ac114c5f57dc4ebc08c18bea77 Mon Sep 17 00:00:00 2001 From: Patrick Barroca <pbarroca@sandbox.pergame.net> Date: Wed, 10 Feb 2016 17:48:25 +0100 Subject: [PATCH] rel #35272 : module configuration --- VERSIONS_WIP/35272 | 1 + .../admin/controllers/ModulesController.php | 20 +++- .../views/scripts/modules/auth-register.phtml | 4 + .../views/scripts/modules/auth_register.phtml | 26 ----- .../opac/controllers/AuthController.php | 40 ++++--- library/Class/Systeme/ModulesAppli.php | 43 +++---- .../Form/Configuration/AuthRegister.php | 110 ++++++++++++++++++ .../Form/Configuration/SearchResult.php | 3 +- .../controllers/ModulesControllerTest.php | 21 +++- .../opac/controllers/AuthControllerTest.php | 4 +- 10 files changed, 192 insertions(+), 80 deletions(-) create mode 100644 VERSIONS_WIP/35272 create mode 100644 application/modules/admin/views/scripts/modules/auth-register.phtml delete mode 100644 application/modules/admin/views/scripts/modules/auth_register.phtml create mode 100644 library/ZendAfi/Form/Configuration/AuthRegister.php diff --git a/VERSIONS_WIP/35272 b/VERSIONS_WIP/35272 new file mode 100644 index 00000000000..e0f67a886c6 --- /dev/null +++ b/VERSIONS_WIP/35272 @@ -0,0 +1 @@ + - ticket #35272 : Formulaire d'inscription : possibilité de paramétrer l'affichage des champs bibliothèque et numéro de carte \ No newline at end of file diff --git a/application/modules/admin/controllers/ModulesController.php b/application/modules/admin/controllers/ModulesController.php index eea626f7e69..2ba944397d4 100644 --- a/application/modules/admin/controllers/ModulesController.php +++ b/application/modules/admin/controllers/ModulesController.php @@ -44,8 +44,8 @@ class Admin_ModulesController extends ZendAfi_Controller_Action { public function preDispatch() { parent::preDispatch(); - if ($this->_request->getActionName()!='kiosque-change-data' && - $this->_request->getActionName()!='search-result') + if (!in_array($this->_request->getActionName(), + ['kiosque-change-data', 'search-result', 'auth-register'])) Zend_Layout::startMvc(); } @@ -97,10 +97,26 @@ class Admin_ModulesController extends ZendAfi_Controller_Action { public function authAction() { + if ('register' == $this->_getParam('action1')) + return $this->_forward('auth-register'); + return $this->_simpleAction('auth_'.$this->_getParam('action1')); } + public function authRegisterAction() { + $form = ZendAfi_Form_Configuration_AuthRegister::newConfigurationWith($this->preferences); + if ($this->_request->isPost() && $form->isValid($this->_request->getPost())) { + $datas = $form->getValues(); + unset($datas['submit']); + + return $this->updateEtRetour($datas); + } + + $this->view->form = $form; + } + + public function cmsAction() { return $this->_simpleAction(($this->_getParam('action1') == 'articleviewbydate') ? 'cms_articleviewbydate' : 'cms_all'); diff --git a/application/modules/admin/views/scripts/modules/auth-register.phtml b/application/modules/admin/views/scripts/modules/auth-register.phtml new file mode 100644 index 00000000000..a77ca805bea --- /dev/null +++ b/application/modules/admin/views/scripts/modules/auth-register.phtml @@ -0,0 +1,4 @@ +<center> + <h1><?php echo $this->_('Propriétés du module : %s', $this->titre_module); ?></h1> + <?php echo $this->renderForm($this->form); ?> +</center> diff --git a/application/modules/admin/views/scripts/modules/auth_register.phtml b/application/modules/admin/views/scripts/modules/auth_register.phtml deleted file mode 100644 index bc4491adc28..00000000000 --- a/application/modules/admin/views/scripts/modules/auth_register.phtml +++ /dev/null @@ -1,26 +0,0 @@ -<?php echo $this->render('modules/_debut.phtml');?> - -<br> -<fieldset> - <legend>Préférences</legend> - <table cellspacing="2"> - - <tr> - <td class="droite">Titre </td> - <td class="gauche"><input type="text" name="titre" size="40" value="<?php print($this->preferences["titre"]); ?>"></td> - </tr> - <tr> - <td class="droite">Texte d'aide </td> - <td class="gauche"><textarea cols="70" rows="5" name="register_help"><?php print($this->preferences["register_help"]); ?></textarea></td> - </tr> - <tr> - <td class="droite">Texte de confirmation </td> - <td class="gauche"><textarea cols="70" rows="5" name="register_confirm"><?php print($this->preferences["register_confirm"]); ?></textarea></td> - </tr> - - - </table> -</fieldset> - -<?php echo $this->render('modules/_fin.phtml');?> - diff --git a/application/modules/opac/controllers/AuthController.php b/application/modules/opac/controllers/AuthController.php index 64862e20875..069563fc7ef 100644 --- a/application/modules/opac/controllers/AuthController.php +++ b/application/modules/opac/controllers/AuthController.php @@ -206,33 +206,36 @@ class AuthController extends ZendAfi_Controller_Action { public function registerAction() { $this->view->preferences = Class_Profil::getCurrentProfil()->getCfgModulesPreferences('auth', 'register'); - if (Class_AdminVar::get('INTERDIRE_ENREG_UTIL')) + + if (Class_AdminVar::get('INTERDIRE_ENREG_UTIL')) { $this->_redirect('/'); + return; + } $this->view->form = ZendAfi_Form::newWithOptions(['action' => $this->view->url(['module'=>'opac', - 'controller'=>'auth', - 'action'=>'register'])]) + 'controller'=>'auth', + 'action'=>'register'])]) - ->addElement('text', 'login', ['label' => $this->view->_('Identifiant'), + ->addElement('text', 'login', ['label' => $this->_('Identifiant'), 'maxlength' => 20, 'required' => true, 'validators' => ['LoginExists']]) - ->addElement('password', 'mdp', ['label' => $this->view->_('Mot de passe'), + ->addElement('password', 'mdp', ['label' => $this->_('Mot de passe'), 'maxlength' => 15, 'required' => true]) - ->addElement('password', 'mdp2', ['label' => $this->view->_('Confirmez votre mot de passe'), + ->addElement('password', 'mdp2', ['label' => $this->_('Confirmez votre mot de passe'), 'maxlength' => 15, 'required' => true, 'validators' => [new ZendAfi_Validate_PasswordEquals('mdp')]]) - ->addElement('email', 'mail', ['label' => $this->view->_('E-mail'), + ->addElement('email', 'mail', ['label' => $this->_('E-mail'), 'maxlength' => 50, 'required' => true, 'validators' => ['MailExists']]) - ->addElement('email', 'mail2', ['label' => $this->view->_('Confirmez votre e-mail'), + ->addElement('email', 'mail2', ['label' => $this->_('Confirmez votre e-mail'), 'maxlength' => 50, 'required' => true, 'validators' => [new ZendAfi_Validate_MailEquals('mail')]]) @@ -241,24 +244,25 @@ class AuthController extends ZendAfi_Controller_Action { 'fields', ['legend' => '']) - ->addElement('captcha', 'captcha', array('captcha' => 'Image', - 'label' => $this->view->_('Recopiez le code'), - 'captchaOptions' => array('font' => PATH_FONTS.'/Vera.ttf', - 'imgDir' => PATH_CAPTCHA, - 'imgUrl' => URL_CAPTCHA))) + ->addElement('captcha', 'captcha', ['captcha' => 'Image', + 'label' => $this->_('Recopiez le code'), + 'captchaOptions' => ['font' => PATH_FONTS.'/Vera.ttf', + 'imgDir' => PATH_CAPTCHA, + 'imgUrl' => URL_CAPTCHA]]) ->addDisplayGroup(['captcha'], 'security', - ['legend' => $this->view->_('Sécurité'), + ['legend' => $this->_('Sécurité'), 'required' => true]) - ->addElement('submit','submit', ['label' => $this->view->_('Valider')]); + + ->addElement('submit','submit', ['label' => $this->_('Valider')]); - if ($this->_request->isPost() && $this->view->form->isValid($this->_request->getPost())) { - // recup _post + if ($this->_request->isPost() + && $this->view->form->isValid($this->_request->getPost())) { $data = ZendAfi_Filters_Post::filterStatic($this->_request->getPost()); $class_user = new Class_Users(); $data['cle'] = md5($data['mail']); - $ret=$class_user->registerUser($data); + $ret = $class_user->registerUser($data); // Affichage des erreurs if(isset($ret["error"])) { diff --git a/library/Class/Systeme/ModulesAppli.php b/library/Class/Systeme/ModulesAppli.php index 6b69a569e46..c895e1c0bcb 100644 --- a/library/Class/Systeme/ModulesAppli.php +++ b/library/Class/Systeme/ModulesAppli.php @@ -67,8 +67,8 @@ class Class_Systeme_ModulesAppli extends Class_Systeme_ModulesAbstract { 'popup_width' => 800, 'popup_height' => 700], 'register' => ['libelle' => 'Demande d\'inscription', - 'popup_width' => 710, - 'popup_height' => 290], + 'popup_width' => 800, + 'popup_height' => 700], 'lostpass' => ['libelle' => 'Mot de passe oublié', 'popup_width' => 710, 'popup_height' => 290]], @@ -280,35 +280,26 @@ class Class_Systeme_ModulesAppli extends Class_Systeme_ModulesAbstract { * @return int */ private function getDefautAuth($action) { - $ret = array(); - - switch ((string)$action) { - case "login": - $ret=array_merge(['barre_nav'=>'Connexion'], + if ('login' == $action) + return array_merge(['barre_nav' => 'Connexion'], (new Class_Systeme_ModulesAccueil_Login())->getDefaultValues()); - break; - case "register": - $ret["barre_nav"] = "S'inscrire"; // Barre de nav - $ret["titre"] = "Demande d'inscription"; // Titre de la boite - $ret["register_help"] = "Remplissez les champs ci-dessous\n" - ."Un mail de confirmation vous sera envoyé.\n" - ."Vous devrez cliquer sur le lien pour confirmer la création de votre compte."; // Texte d'aide - $ret["register_confirm"] = "Cher Internaute,<br />" - ."Merci pour votre inscription.<br />" - ."Pour vérifier l'adresse e-mail associée à votre compte, nous avons envoyé un courrier " - ."électronique à l'adresse indiquée. Pour activer votre compte, accédez à votre messagerie " - ."et cliquez sur le lien fourni dans le courrier de vérification."; - break; - case "lostpass": - $ret["barre_nav"] = "demande de mot de passe"; // Barre de nav - $ret["titre"] = "Mot de passe oublié"; // Titre de la boite - break; - } - return $ret; + if ('register' == $action) + return ['barre_nav' => 'S\'inscrire', + 'titre' => 'Demande d\'inscription', + 'register_help' => "Remplissez les champs ci-dessous\nUn mail de confirmation vous sera envoyé.\nVous devrez cliquer sur le lien pour confirmer la création de votre compte.", + 'register_confirm' => "Cher Internaute,<br />Merci pour votre inscription.<br />Pour vérifier l'adresse e-mail associée à votre compte, nous avons envoyé un courrier électronique à l'adresse indiquée. Pour activer votre compte, accédez à votre messagerie et cliquez sur le lien fourni dans le courrier de vérification.", + 'fields' => 'library:;card_number:', // nom_de_champs:[|optional|required] + ]; + if ('lostpass' == $action) + return ['barre_nav' => 'demande de mot de passe', + 'titre' => 'Mot de passe oublié']; + + return []; } + /** * @param type string * @return array diff --git a/library/ZendAfi/Form/Configuration/AuthRegister.php b/library/ZendAfi/Form/Configuration/AuthRegister.php new file mode 100644 index 00000000000..6b8c1771fbf --- /dev/null +++ b/library/ZendAfi/Form/Configuration/AuthRegister.php @@ -0,0 +1,110 @@ +<?php +/** + * Copyright (c) 2012-2014, Agence Française Informatique (AFI). All rights reserved. + * + * BOKEH is free software; you can redistribute it and/or modify + * it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by + * the Free Software Foundation. + * + * There are special exceptions to the terms and conditions of the AGPL as it + * is applied to this software (see README file). + * + * BOKEH is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU AFFERO GENERAL PUBLIC LICENSE for more details. + * + * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE + * along with BOKEH; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + + +class ZendAfi_Form_Configuration_AuthRegister extends ZendAfi_Form { + + public static function newConfigurationWith($conf) { + $form = new static(); + $form->populate($conf); + return $form; + } + + + public function init() { + parent::init(); + + $this + ->setAttrib('id', 'auth_register_conf') + + ->addElement('select', 'boite', + ['label' => $this->_('Style de boite'), + 'multiOptions' => (new Class_Profil_Templates(Class_Profil::getCurrentProfil()))->toArray()]) + + ->addElement('text', 'barre_nav', ['label' => $this->_('Texte du fil d\'ariane'), + 'size' => 25, + 'maxlength' => 30]) + + ->addDisplayGroup(['boite', 'barre_nav'], 'common', ['legend' => $this->_('Module')]) + + ->addElement('text', 'titre', ['label' => $this->_('Titre'), + 'size' => 40]) + + ->addElement('textarea', 'register_help', ['label' => $this->_('Texte d\'aide'), + 'cols' => 70, + 'rows' => 5]) + + ->addElement('textarea', 'register_confirm', ['label' => $this->_('Texte de confirmation'), + 'cols' => 70, + 'rows' => 5]) + + ->addDisplayGroup(['titre', 'register_help', 'register_confirm'], + 'prefs', + ['legend' => $this->_('Préférences')]) + + ->addElement('select', 'library', + ['label' => $this->_('Bibliothèque d\'inscription'), + 'multiOptions' => $this->_optionalFieldOptions()]) + + ->addElement('select', 'card_number', + ['label' => $this->_('N° de carte'), + 'multiOptions' => $this->_optionalFieldOptions()]) + + ->addDisplayGroup(['library', 'card_number'], 'options', ['legend' => $this->_('Champs optionnels')]) + + ->addElement('submit', 'submit', ['label' => $this->_('Valider'), + 'class' => 'bouton']) + + ->addDisplayGroup(['submit'], 'submit', ['legend' => '']) + ; + } + + + public function populate(array $datas) { + parent::populate($datas); + if (!array_key_exists('fields', $datas)) + return $this; + + foreach(explode(';', $datas['fields']) as $field) { + $parts = explode(':', $field); + if ($element = $this->getElement($parts[0])) + $element->setValue($parts[1]); + } + + return $this; + } + + + protected function _optionalFieldOptions() { + return ['' => $this->_('Non affiché'), + 'optional' => $this->_('Affiché et facultatif'), + 'required' => $this->_('Affiché et obligatoire')]; + } + + + public function getValues() { + $values = parent::getValues(); + $values['fields'] = 'library:' . $values['library'] . ';card_number:' . $values['card_number']; + unset($values['library'], $values['card_number']); + + return $values; + } +} \ No newline at end of file diff --git a/library/ZendAfi/Form/Configuration/SearchResult.php b/library/ZendAfi/Form/Configuration/SearchResult.php index 5a7839015e2..df54207a614 100644 --- a/library/ZendAfi/Form/Configuration/SearchResult.php +++ b/library/ZendAfi/Form/Configuration/SearchResult.php @@ -240,7 +240,8 @@ class ZendAfi_Form_Configuration_SearchResult extends ZendAfi_Form { ->addElement('submit', 'submit', - ['label' => $this->_('Valider')]); + ['label' => $this->_('Valider'), + 'class' => 'bouton']); } diff --git a/tests/application/modules/admin/controllers/ModulesControllerTest.php b/tests/application/modules/admin/controllers/ModulesControllerTest.php index ebd0d4520dc..c83631bfb71 100644 --- a/tests/application/modules/admin/controllers/ModulesControllerTest.php +++ b/tests/application/modules/admin/controllers/ModulesControllerTest.php @@ -374,30 +374,41 @@ class ModulesControllerRegisterConfigTest extends Admin_AbstractControllerTestCa /** @test */ - public function modulesAuthRegisterInputBarreNavShouldContainsSInscrire() { + public function barreNavShouldContainsSInscrire() { $this->assertXPath('//input[@name="barre_nav"][@value="S\'inscrire"]'); } /** @test */ - public function modulesAuthRegisterInputTitreShouldContainsDemandeDinscription() { + public function titreShouldContainsDemandeDinscription() { $this->assertXPath('//input[@type="text"][@name="titre"][@value="Demande d\'inscription"]'); } /** @test */ - public function modulesAuthRegisterTextareaRegisterHelpShouldContainsDefautMessage() { - + public function registerHelpShouldContainsDefautMessage() { $this->assertXPathContentContains('//textarea[@name="register_help"]', 'mail de confirmation'); } /** @test */ - public function modulesAuthRegisterTextareaRegisterConfirmShouldContainsDefautMessage() { + public function registerConfirmShouldContainsDefautMessage() { $this->assertXPathContentContains('//textarea[@name="register_confirm"]', 'Cher Internaute,'); } + + + /** @test */ + public function optionalLibraryShouldBePresent() { + $this->assertXPath('//select[@name="library"]'); + } + + + /** @test */ + public function optionalCardNumberShouldBePresent() { + $this->assertXPath('//select[@name="card_number"]'); + } } diff --git a/tests/application/modules/opac/controllers/AuthControllerTest.php b/tests/application/modules/opac/controllers/AuthControllerTest.php index 647a72889de..49799405e46 100644 --- a/tests/application/modules/opac/controllers/AuthControllerTest.php +++ b/tests/application/modules/opac/controllers/AuthControllerTest.php @@ -1255,13 +1255,13 @@ class AuthControllerNobodyLoggedAndRegistrationAllowedRegisterTest extends AuthC /** @test */ - public function H1ShouldContainsDemandDInscription() { + public function h1ShouldContainsDemandDInscription() { $this->assertXPathContentContains('//h1', 'Demande d\'inscription'); } /** @test */ - public function ParagraphRegisterHelpShouldContainsMailDeConfirmation() { + public function paragraphRegisterHelpShouldContainsMailDeConfirmation() { $this->assertXPathContentContains('//p', 'mail de confirmation'); } -- GitLab