From: <gem...@li...> - 2012-03-19 18:34:52
|
Revision: 555 http://gemstracker.svn.sourceforge.net/gemstracker/?rev=555&view=rev Author: matijsdejong Date: 2012-03-19 18:34:45 +0000 (Mon, 19 Mar 2012) Log Message: ----------- Moving login form from IndexAction.php Moving away from array values in authenticate simplified layoutSwitch Modified Paths: -------------- trunk/library/classes/Gems/Auth/Adapter/Callback.php trunk/library/classes/Gems/Default/IndexAction.php trunk/library/classes/Gems/Form.php trunk/library/classes/Gems/Project/Layout/MultiLayoutInterface.php trunk/library/classes/Gems/User/DbUserDefinitionAbstract.php trunk/library/classes/Gems/User/NoLoginDefinition.php trunk/library/classes/Gems/User/OldStaffUserDefinition.php trunk/library/classes/Gems/User/ProjectUserDefinition.php trunk/library/classes/Gems/User/RadiusUserDefinition.php trunk/library/classes/Gems/User/User.php trunk/library/classes/Gems/User/UserDefinitionInterface.php trunk/library/classes/Gems/User/UserLoader.php trunk/library/classes/Gems/Util/DbLookup.php trunk/library/classes/GemsEscort.php Added Paths: ----------- trunk/library/classes/Gems/User/Form/ trunk/library/classes/Gems/User/Form/LoginForm.php Modified: trunk/library/classes/Gems/Auth/Adapter/Callback.php =================================================================== --- trunk/library/classes/Gems/Auth/Adapter/Callback.php 2012-03-16 15:26:05 UTC (rev 554) +++ trunk/library/classes/Gems/Auth/Adapter/Callback.php 2012-03-19 18:34:45 UTC (rev 555) @@ -75,7 +75,7 @@ * @param string $identity The identity to use * @param array $params Array of parameters needed for the callback */ - public function __construct($callback, $identity, $params) + public function __construct($callback, $identity, $params = array()) { $this->_callback = $callback; $this->_identity = $identity; Modified: trunk/library/classes/Gems/Default/IndexAction.php =================================================================== --- trunk/library/classes/Gems/Default/IndexAction.php 2012-03-16 15:26:05 UTC (rev 554) +++ trunk/library/classes/Gems/Default/IndexAction.php 2012-03-19 18:34:45 UTC (rev 555) @@ -139,22 +139,39 @@ /** * Returns a login form * - * @param boolean $showTokenButton Optional, show 'Ask token' button, $this->showTokenButton is used when not specified - * @param boolean $showPasswordLostButton Optional, show 'Lost password' button, $this->showPasswordLostButton is used when not specified + * @param boolean $showToken Optional, show 'Ask token' button, $this->showTokenButton is used when not specified + * @param boolean $showPasswordLost Optional, show 'Lost password' button, $this->showPasswordLostButton is used when not specified * @return Gems_Form */ - protected function _getLoginForm($showTokenButton = null, $showPasswordLostButton = null) + protected function _getLoginForm($showToken = null, $showPasswordLost = null) { - $form = $this->_getBasicForm($this->_('Login to %s application')); + $args = MUtil_Ra::args(func_get_args(), + array( + 'showToken' => 'is_boolean', + 'showPasswordLost' => 'is_boolean', + 'description' => 'is_string', + ), + array( + 'showToken' => $this->showTokenButton, + 'showPasswordLost' => $this->showPasswordLostButton, + 'description' => $this->_('Login to %s application'), + 'labelWidthFactor' => $this->labelWidthFactor, + )); + + Gems_Html::init(); + + return $this->loader->getUserLoader()->getLoginForm($args); + + $form = $this->_getBasicForm(); $form->addElement($this->_getOrganizationElement()); $form->addElement($this->_getUserLoginElement()); $form->addElement($this->_getPasswordElement()); $form->addElement($this->_getSubmitButton($this->_('Login'))); - if (null === $showTokenButton ? $this->showTokenButton : $showTokenButton) { + if (null === $showToken ? $this->showTokenButton : $showToken) { $form->addElement($this->_getAskTokenLinkElement()); } - if (null === $showPasswordLostButton ? $this->showPasswordLostButton : $showPasswordLostButton) { + if (null === $showPasswordLost ? $this->showPasswordLostButton : $showPasswordLost) { $form->addElement($this->_getResetLinkElement()); } @@ -309,30 +326,6 @@ { $request = $this->getRequest(); - /** - * @@TODO: Start block to move to Gems_User_User->getCurrentOrganizationId() - * - * At that place the cookie is read, but this could be changed to use url like here - * or maybe referrer, ip-range, get-param etc. - */ - // Allow layout switching based on request base url - if ($this->escort instanceof Gems_Project_Layout_MultiLayoutInterface) { - $hostUrl = $this->escort->loader->getUtil()->getCurrentURI(); - - // MUtil_Echo::track($hostUrl); - - $organizationId = $this->util->getDbLookup()->getOrganizationForUrl($hostUrl); - - if ($organizationId) { - $user = $this->escort->getLoader()->getUserLoader()->getCurrentUser(); - $user->setCurrentOrganization($organizationId); - $this->escort->layoutSwitch($request); - } - } - /** - * End block to move to Gems_User_User->getCurrentOrganizationId() - */ - $form = $this->_getLoginForm(); if ($request->isPost()) { @@ -360,7 +353,7 @@ } // */ /** - * Fix current locale / organization in cookies + * Fix current locale in cookies */ Gems_Cookies::setLocale($user->getLocale(), $this->basepath->getBasePath()); Modified: trunk/library/classes/Gems/Form.php =================================================================== --- trunk/library/classes/Gems/Form.php 2012-03-16 15:26:05 UTC (rev 554) +++ trunk/library/classes/Gems/Form.php 2012-03-19 18:34:45 UTC (rev 555) @@ -40,7 +40,7 @@ * @copyright Copyright (c) 2011 Erasmus MC * @license New BSD License */ -class Gems_Form extends MUtil_Form +class Gems_Form extends MUtil_Form implements MUtil_Registry_TargetInterface { /** * This variable holds all the stylesheets attached to this form @@ -116,15 +116,75 @@ $this->_css[$file] = $media; } - public function getCss() { + /** + * Allows the loader to set resources. + * + * @param string $name Name of resource to set + * @param mixed $resource The resource. + * @return boolean True if $resource was OK + */ + public function answerRegistryRequest($name, $resource) + { + if (MUtil_Registry_Source::$verbose) { + MUtil_Echo::r('Resource set: ' . get_class($this) . '->' . __FUNCTION__ . + '("' . $name . '", ' . + (is_object($resource) ? get_class($resource) : gettype($resource)) . ')'); + } + $this->$name = $resource; + + return true; + } + + /** + * Should be called after answering the request to allow the Target + * to check if all required registry values have been set correctly. + * + * @return boolean False if required values are missing. + */ + public function checkRegistryRequestsAnswers() + { + return true; + } + + /** + * Filters the names that should not be requested. + * + * Can be overriden. + * + * @param string $name + * @return boolean + */ + protected function filterRequestNames($name) + { + return '_' !== $name[0]; + } + + public function getCss() + { return $this->_css; } - public function getAutoSubmit() { + public function getAutoSubmit() + { return $this->_autosubmit; } /** + * Allows the loader to know the resources to set. + * + * Returns those object variables defined by the subclass but not at the level of this definition. + * + * Can be overruled. + * + * @return array of string names + */ + public function getRegistryRequests() + { + // MUtil_Echo::track(array_filter(array_keys(get_object_vars($this)), array($this, 'filterRequestNames'))); + return array_filter(array_keys(get_object_vars($this)), array($this, 'filterRequestNames')); + } + + /** * Is this a form that autosubmits? * * @return boolean Modified: trunk/library/classes/Gems/Project/Layout/MultiLayoutInterface.php =================================================================== --- trunk/library/classes/Gems/Project/Layout/MultiLayoutInterface.php 2012-03-16 15:26:05 UTC (rev 554) +++ trunk/library/classes/Gems/Project/Layout/MultiLayoutInterface.php 2012-03-19 18:34:45 UTC (rev 555) @@ -62,7 +62,7 @@ /** * Performs the actual switch of the layout * - * @param Zend_Controller_Request_Abstract $request + * @param string $style Style, when null derived from request */ - public function layoutSwitch(Zend_Controller_Request_Abstract $request); + public function layoutSwitch($style = null); } \ No newline at end of file Modified: trunk/library/classes/Gems/User/DbUserDefinitionAbstract.php =================================================================== --- trunk/library/classes/Gems/User/DbUserDefinitionAbstract.php 2012-03-16 15:26:05 UTC (rev 554) +++ trunk/library/classes/Gems/User/DbUserDefinitionAbstract.php 2012-03-19 18:34:45 UTC (rev 555) @@ -120,18 +120,26 @@ return false; } - public function getAuthAdapter($formValues) + /** + * Returns an initialized Zend_Auth_Adapter_Interface + * + * @param string $username + * @param int $organizationId + * @param string $password + * @return Zend_Auth_Adapter_Interface + */ + public function getAuthAdapter($username, $organizationId, $password) { $adapter = new Zend_Auth_Adapter_DbTable($this->db, 'gems__user_passwords', 'gul_login', 'gup_password'); - $pwd_hash = $this->hashPassword($formValues['password']); + $pwd_hash = $this->hashPassword($password); $select = $adapter->getDbSelect(); $select->join('gems__user_logins', 'gup_id_user = gul_id_user', array()) ->where('gul_can_login = 1') - ->where('gul_id_organization = ?', $formValues['organization']); + ->where('gul_id_organization = ?', $organizationId); - $adapter->setIdentity($formValues['userlogin']) + $adapter->setIdentity($username) ->setCredential($pwd_hash); return $adapter; @@ -185,7 +193,7 @@ $result = array( 'user_active' => false, 'user_role' => 'nologin', - ); + ); } return $result; Property changes on: trunk/library/classes/Gems/User/Form ___________________________________________________________________ Added: bugtraq:url + http://survey.erasmusmc.nl/support/mantis/view.php?id=%BUGID% Added: bugtraq:logregex + #(\d+) Added: trunk/library/classes/Gems/User/Form/LoginForm.php =================================================================== --- trunk/library/classes/Gems/User/Form/LoginForm.php (rev 0) +++ trunk/library/classes/Gems/User/Form/LoginForm.php 2012-03-19 18:34:45 UTC (rev 555) @@ -0,0 +1,460 @@ +<?php + +/** + * Copyright (c) 2012, Erasmus MC + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of Erasmus MC nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * + * @package Gems + * @subpackage User + * @author Matijs de Jong <mj...@ma...> + * @copyright Copyright (c) 2012 Erasmus MC + * @license New BSD License + * @version $id: LoginForm.php 203 2012-01-01t 12:51:32Z matijs $ + */ + +/** + * + * + * @package Gems + * @subpackage User + * @copyright Copyright (c) 2012 Erasmus MC + * @license New BSD License + * @since Class available since version 1.5 + */ +class Gems_User_Form_LoginForm extends Gems_Form +{ + /** + * The field name for the lost password element. + * + * @var string + */ + protected $_lostPasswordFieldName = 'lost_password'; + + /** + * The field name for the organization element. + * + * @var string + */ + protected $_organizationFieldName = 'organization'; + + + /** + * When true the organization was derived from the the url + * + * @var boolean + */ + protected $_organizationFromUrl = false; + + /** + * The field name for the password element. + * + * @var string + */ + protected $_passwordFieldName = 'password'; + + /** + * The field name for the submit element. + * + * @var string + */ + protected $_submitFieldName = 'button'; + + /** + * The field name for the token element. + * + * @var string + */ + protected $_tokenFieldName = 'token_link'; + + /** + * The field name for the username element. + * + * @var string + */ + protected $_usernameFieldName = 'userlogin'; + + /** + * When true all elements are loaded after initiation. + * + * @var boolean + */ + protected $loadDefault = true; + + /** + * + * @var Gems_Loader + */ + protected $loader; + + /** + * For small numbers of organizations a multiline selectbox will be nice. This + * setting handles how many lines will display at once. Use 1 for the normal + * dropdown selectbox + * + * @var int + */ + protected $organizationMaxLines = 6; + + /** + * + * @var Zend_Controller_Request_Abstract + */ + protected $request; + + /** + * The default behaviour for showing a lost password button + * + * @var boolean + */ + protected $showPasswordLost = true; + + /** + * The default behaviour for showing an 'ask token' button + * + * @var boolean + */ + protected $showToken = true; + + /** + * + * @var Zend_Translate + */ + protected $translate; + + /** + * + * @var Zend_Util + */ + protected $util; + + /** + * Should be called after answering the request to allow the Target + * to check if all required registry values have been set correctly. + * + * @return boolean False if required values are missing. + */ + public function checkRegistryRequestsAnswers() + { + if ($this->loadDefault) { + $this->loadDefaultElements(); + } + + return true; + } + + /** + * Returns the organization id that should currently be used for this form. + * + * @return int Returns the current organization id, if any + */ + public function getCurrentOrganizationId() + { + // Url determines organization first. + $uri = $this->util->getCurrentURI(); + // MUtil_Echo::track($uri); + + if ($orgId = $this->util->getDbLookup()->getOrganizationForUrl($uri)) { + $this->_organizationFromUrl = true; + $this->loader->getCurrentUser()->setCurrentOrganization($orgId); + return $orgId; + } + + $request = $this->getRequest(); + if ($request->isPost() && ($orgId = $request->getParam($this->_organizationFieldName))) { + return $orgId; + } + + return $this->loader->getCurrentUser()->getCurrentOrganizationId(); + } + + /** + * Returns a list with the organizations the user can select for login. + * + * @return array orgId => Name + */ + public function getLoginOrganizations() + { + return $this->util->getDbLookup()->getOrganizationsForLogin(); + } + + /** + * Returns/sets a link to the reset password page + * + * @return MUtil_Form_Element_Html + */ + public function getLostPasswordElement() + { + $element = $this->getElement($this->_lostPasswordFieldName); + + if (! $element) { + // Reset password + $element = new MUtil_Form_Element_Html($this->_lostPasswordFieldName); + // $element->br(); + $element->a(array('controller' => 'index', 'action' => 'resetpassword'), $this->translate->_('Lost password'), array('class' => 'actionlink')); + + $this->addElement($element); + } + + return $element; + } + + /** + * Returns/sets an element for determining / selecting the organization. + * + * @return Zend_Form_Element_Xhtml + */ + public function getOrganizationElement() + { + $element = $this->getElement($this->_organizationFieldName); + $orgId = $this->getCurrentOrganizationId(); + $orgs = $this->getLoginOrganizations(); + $hidden = $this->_organizationFromUrl || (count($orgs) < 2); + + if ($hidden) { + if (! $element instanceof Zend_Form_Element_Hidden) { + $element = new Zend_Form_Element_Hidden($this->_organizationFieldName); + + $this->addElement($element); + } + + if (! $this->_organizationFromUrl) { + $orgIds = array_keys($orgs); + $orgId = reset($orgIds); + } + + } elseif (! $element instanceof Zend_Form_Element_Select) { + $element = new Zend_Form_Element_Select($this->_organizationFieldName); + $element->setLabel($this->translate->_('Organization')); + $element->setRequired(true); + $element->setMultiOptions($orgs); + + if ($this->organizationMaxLines > 1) { + $element->setAttrib('size', max(count($orgs) + 1, $this->organizationMaxLines)); + } + $this->addElement($element); + + } + $element->setValue($orgId); + + return $element; + } + + /** + * Returns/sets a password element. + * + * @return Zend_Form_Element_Password + */ + public function getPasswordElement() + { + $element = $this->getElement($this->_passwordFieldName); + + if (! $element) { + // Veld password + $element = new Zend_Form_Element_Password($this->_passwordFieldName); + $element->setLabel($this->translate->_('Password')); + $element->setAttrib('size', 10); + $element->setAttrib('maxlength', 20); + $element->setRequired(true); + + $this->addElement($element); + } + + return $element; + } + + /** + * Return the Request object + * + * @return Zend_Controller_Request_Abstract + */ + public function getRequest() + { + if (! $this->request) { + $this->request = Zend_Controller_Front::getInstance()->getRequest(); + } + return $this->request; + } + + /** + * Returns/sets a submit button. + * + * @param string $label + * @return Zend_Form_Element_Submit + */ + public function getSubmitButton($label = null) + { + $element = $this->getElement($this->_submitFieldName); + + if (! $element) { + // Submit knop + $element = new Zend_Form_Element_Submit($this->_submitFieldName); + $element->setLabel(null === $label ? $this->translate->_('Login') : $label); + $element->setAttrib('class', 'button'); + + $this->addElement($element); + } + + return $element; + } + + /** + * Returns/sets a link for the token input page. + * + * @return MUtil_Form_Element_Html + */ + public function getTokenElement() + { + $element = $this->getElement($this->_tokenFieldName); + + if (! $element) { + // Veld token + $element = new MUtil_Form_Element_Html($this->_tokenFieldName); + // $element->br(); + $element->a(array('controller' => 'ask', 'action' => 'token'), $this->translate->_('Enter your token...'), array('class' => 'actionlink')); + + $this->addElement($element); + } + + return $element; + } + + /** + * Returns/sets a login name element. + * + * @return Zend_Form_Element_Text + */ + public function getUserNameElement() + { + $element = $this->getElement($this->_usernameFieldName); + + if (! $element) { + // Veld inlognaam + $element = new Zend_Form_Element_Text($this->_usernameFieldName); + $element->setLabel($this->translate->_('Username')); + $element->setAttrib('size', 10); + $element->setAttrib('maxlength', 20); + $element->setRequired(true); + + $this->addElement($element); + } + + return $element; + } + + /** + * The function that determines the element load order + * + * @return Gems_User_Form_LoginForm (continuation pattern) + */ + public function loadDefaultElements() + { + $this->getOrganizationElement(); + $this->getUserNameElement(); + $this->getPasswordElement(); + $this->getSubmitButton(); + + if ($this->showPasswordLost) { + $this->getLostPasswordElement(); + } + if ($this->showToken) { + $this->getTokenElement(); + } + + return $this; + } + + /** + * When true all elements are loaded after initiation. + * + * Enables loading of parameter through Zend_Form::__construct() + * + * @param boolean $loadDefault + * @return Gems_User_Form_LoginForm (continuation pattern) + */ + public function setLoadDefault($loadDefault = true) + { + $this->loadDefault = $loadDefault; + + return $this; + } + + /** + * For small numbers of organizations a multiline selectbox will be nice. This + * setting handles how many lines will display at once. Use 1 for the normal + * dropdown selectbox + * + * Enables loading of parameter through Zend_Form::__construct() + * + * @param int $organizationMaxLines + * @return Gems_User_Form_LoginForm (continuation pattern) + */ + public function setOrganizationMaxLines($organizationMaxLines) + { + $this->organizationMaxLines = $organizationMaxLines; + + return $this; + } + + /** + * The behaviour for showing a lost password button + * + * Enables loading of parameter through Zend_Form::__construct() + * + * @param boolean $showPasswordLost + * @return Gems_User_Form_LoginForm (continuation pattern) + */ + public function setShowPasswordLost($showPasswordLost = true) + { + $this->showPasswordLost = $showPasswordLost; + + return $this; + } + + /** + * The default behaviour for showing an 'ask token' button + * + * Enables loading of parameter through Zend_Form::__construct() + * + * @param boolean $showToken + * @return Gems_User_Form_LoginForm (continuation pattern) + */ + public function setShowToken($showToken = true) + { + $this->showToken = $showToken; + + return $this; + } + + /** + * True when this form was submitted. + * + * @return boolean + */ + public function wasSubmitted() + { + return $this->getSubmitButton()->isChecked(); + } +} Modified: trunk/library/classes/Gems/User/NoLoginDefinition.php =================================================================== --- trunk/library/classes/Gems/User/NoLoginDefinition.php 2012-03-16 15:26:05 UTC (rev 554) +++ trunk/library/classes/Gems/User/NoLoginDefinition.php 2012-03-19 18:34:45 UTC (rev 555) @@ -46,14 +46,27 @@ */ class Gems_User_NoLoginDefinition extends Gems_User_UserDefinitionAbstract { - public function alwaysFalse($params) + /** + * Helper method for the case a user tries to authenticate while he is inactive + * + * @return boolean + */ + public function alwaysFalse() { return false; } - public function getAuthAdapter($formValues) + /** + * Returns an initialized Zend_Auth_Adapter_Interface + * + * @param string $username + * @param int $organizationId + * @param string $password + * @return Zend_Auth_Adapter_Interface + */ + public function getAuthAdapter($username, $organizationId, $password) { - $adapter = new Gems_Auth_Adapter_Callback(array($this,'alwaysFalse'), $formValues['userlogin'], $formValues); + $adapter = new Gems_Auth_Adapter_Callback(array($this,'alwaysFalse'), $username); return $adapter; } Modified: trunk/library/classes/Gems/User/OldStaffUserDefinition.php =================================================================== --- trunk/library/classes/Gems/User/OldStaffUserDefinition.php 2012-03-16 15:26:05 UTC (rev 554) +++ trunk/library/classes/Gems/User/OldStaffUserDefinition.php 2012-03-19 18:34:45 UTC (rev 555) @@ -119,17 +119,25 @@ } } - public function getAuthAdapter($formValues) + /** + * Returns an initialized Zend_Auth_Adapter_Interface + * + * @param string $username + * @param int $organizationId + * @param string $password + * @return Zend_Auth_Adapter_Interface + */ + public function getAuthAdapter($username, $organizationId, $password) { $adapter = new Zend_Auth_Adapter_DbTable(null, 'gems__staff', 'gsf_login', 'gsf_password'); - $pwd_hash = $this->hashPassword($formValues['password']); + $pwd_hash = $this->hashPassword($password); $select = $adapter->getDbSelect(); $select->where('gsf_active = 1') - ->where('gsf_id_organization = ?', $formValues['organization']); + ->where('gsf_id_organization = ?', $organizationId); - $adapter->setIdentity($formValues['userlogin']) + $adapter->setIdentity($username) ->setCredential($pwd_hash); return $adapter; Modified: trunk/library/classes/Gems/User/ProjectUserDefinition.php =================================================================== --- trunk/library/classes/Gems/User/ProjectUserDefinition.php 2012-03-16 15:26:05 UTC (rev 554) +++ trunk/library/classes/Gems/User/ProjectUserDefinition.php 2012-03-19 18:34:45 UTC (rev 555) @@ -52,9 +52,17 @@ */ protected $project; - public function getAuthAdapter($formValues) + /** + * Returns an initialized Zend_Auth_Adapter_Interface + * + * @param string $username + * @param int $organizationId + * @param string $password + * @return Zend_Auth_Adapter_Interface + */ + public function getAuthAdapter($username, $organizationId, $password) { - $adapter = new Gems_Auth_Adapter_Callback(array($this->project,'checkSuperAdminPassword'), $formValues['userlogin'], array($formValues['password'])); + $adapter = new Gems_Auth_Adapter_Callback(array($this->project,'checkSuperAdminPassword'), $username, array($password)); return $adapter; } Modified: trunk/library/classes/Gems/User/RadiusUserDefinition.php =================================================================== --- trunk/library/classes/Gems/User/RadiusUserDefinition.php 2012-03-16 15:26:05 UTC (rev 554) +++ trunk/library/classes/Gems/User/RadiusUserDefinition.php 2012-03-19 18:34:45 UTC (rev 555) @@ -2,7 +2,7 @@ /** * Copyright (c) 2011, Erasmus MC * All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright @@ -13,7 +13,7 @@ * * Neither the name of Erasmus MC nor the * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE @@ -24,7 +24,7 @@ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * + * * @package Gems * @subpackage User * @copyright Copyright (c) 2011 Erasmus MC @@ -128,17 +128,20 @@ /** * Returns an initialized Zend_Auth_Adapter_Interface * + * @param string $username + * @param int $organizationId + * @param string $password * @return Zend_Auth_Adapter_Interface */ - public function getAuthAdapter($formValues) + public function getAuthAdapter($username, $organizationId, $password) { //Ok hardcoded for now this needs to be read from the userdefinition - $configData = $this->loadConfig(array('gor_id_organization' => $formValues['organization'])); + $configData = $this->loadConfig(array('gor_id_organization' => $organizationId)); $config = array('ip' => $configData['grcfg_ip'], 'authenticationport' => $configData['grcfg_port'], 'sharedsecret' => $configData['grcfg_secret']); - + //Unset empty foreach($config as $key=>$value) { if (empty($value)) { @@ -147,8 +150,8 @@ } $adapter = new Gems_User_Adapter_Radius($config); - $adapter->setIdentity($formValues['userlogin']) - ->setCredential($formValues['password']); + $adapter->setIdentity($username) + ->setCredential($password); return $adapter; } @@ -243,7 +246,7 @@ * * For now these will be added in the organization dialog as most of the time the config * will be organization specific. To be extended when needed - * + * * @return boolean */ public function hasConfig() @@ -274,7 +277,7 @@ public function loadConfig($data) { $model = $this->getConfigModel(); - + $newData = $model->loadFirst(array('grcfg_id_organization'=>$data['gor_id_organization'])); $newData['grcfg_id_organization'] = $data['gor_id_organization']; Modified: trunk/library/classes/Gems/User/User.php =================================================================== --- trunk/library/classes/Gems/User/User.php 2012-03-16 15:26:05 UTC (rev 554) +++ trunk/library/classes/Gems/User/User.php 2012-03-19 18:34:45 UTC (rev 555) @@ -87,6 +87,12 @@ protected $definition; /** + * + * @var Zend_Controller_Request_Abstract + */ + protected $request; + + /** * Required * * @var Zend_Session_Namespace @@ -230,10 +236,9 @@ /** * Helper method for the case a user tries to authenticate while he is inactive * - * @param array $params * @return boolean */ - public function alwaysFalse($params) + public function alwaysFalse() { return false; } @@ -252,9 +257,9 @@ $formValues['organization'] = $this->getBaseOrganizationId(); if ($this->isActive()) { - $adapter = $this->definition->getAuthAdapter($formValues); + $adapter = $this->definition->getAuthAdapter($formValues['userlogin'], $formValues['organization'], $formValues['password']); } else { - $adapter = new Gems_Auth_Adapter_Callback(array($this,'alwaysFalse'), $formValues['userlogin'], $formValues); + $adapter = new Gems_Auth_Adapter_Callback(array($this,'alwaysFalse'), $formValues['userlogin']); } $authResult = $auth->authenticate($adapter, $formValues); @@ -397,8 +402,8 @@ $orgId = $this->_getVar('user_organization_id'); //If not set, read it from the cookie - if ($this->isCurrentUser() && is_null($orgId)) { - $orgId = Gems_Cookies::getOrganization(Zend_Controller_Front::getInstance()->getRequest()); + if ($this->isCurrentUser() && (null === $orgId)) { + $orgId = Gems_Cookies::getOrganization($this->getRequest()); } return $orgId; } @@ -591,6 +596,19 @@ } /** + * Return the Request object + * + * @return Zend_Controller_Request_Abstract + */ + public function getRequest() + { + if (! $this->request) { + $this->request = Zend_Controller_Front::getInstance()->getRequest(); + } + return $this->request; + } + + /** * Returns the current user role. * * @return string @@ -871,6 +889,15 @@ // End depreciation warning if ($this->isCurrentUser()) { + if (! Gems_Cookies::setOrganization($organizationId, $this->basepath->getBasePath())) { + throw new Exception($this->translate->_('Cookies must be enabled for this site.')); + } + + $escort = GemsEscort::getInstance(); + if ($escort instanceof Gems_Project_Layout_MultiLayoutInterface) { + $escort->layoutSwitch($organization->getStyle()); + } + // Now update the requestcache to change the oldOrgId to the new orgId // Don't do it when the oldOrgId doesn't match if ($requestCache = $this->session->requestCache) { @@ -894,10 +921,6 @@ $this->session->requestCache = $requestCache; } } - - if (! Gems_Cookies::setOrganization($organizationId, $this->basepath->getBasePath())) { - throw new Exception($this->translate->_('Cookies must be enabled for this site.')); - } } } Modified: trunk/library/classes/Gems/User/UserDefinitionInterface.php =================================================================== --- trunk/library/classes/Gems/User/UserDefinitionInterface.php 2012-03-16 15:26:05 UTC (rev 554) +++ trunk/library/classes/Gems/User/UserDefinitionInterface.php 2012-03-19 18:34:45 UTC (rev 555) @@ -80,9 +80,12 @@ /** * Returns an initialized Zend_Auth_Adapter_Interface * + * @param string $username + * @param int $organizationId + * @param string $password * @return Zend_Auth_Adapter_Interface */ - public function getAuthAdapter($formValues); + public function getAuthAdapter($username, $organizationId, $password); /** * Return a password reset key Modified: trunk/library/classes/Gems/User/UserLoader.php =================================================================== --- trunk/library/classes/Gems/User/UserLoader.php 2012-03-16 15:26:05 UTC (rev 554) +++ trunk/library/classes/Gems/User/UserLoader.php 2012-03-19 18:34:45 UTC (rev 555) @@ -208,6 +208,25 @@ } /** + * Returns a login form + * + * @param mixed $args_array MUtil_Ra::args array for LoginForm initiation. + * @return Gems_User_Form_LoginForm + */ + public function getLoginForm($args_array) + { + $args = MUtil_Ra::args(func_get_args()); + + if (isset($args['description'])) { + $args['description'] = sprintf($args['description'], $this->project->getName()); + } + + $form = $this->_loadClass('Form_LoginForm', true, array($args)); + + return $form; + } + + /** * Returns an organization object, initiated from the database or from * self::$_noOrganization when the database does not yet exist. * Modified: trunk/library/classes/Gems/Util/DbLookup.php =================================================================== --- trunk/library/classes/Gems/Util/DbLookup.php 2012-03-16 15:26:05 UTC (rev 554) +++ trunk/library/classes/Gems/Util/DbLookup.php 2012-03-19 18:34:45 UTC (rev 555) @@ -250,6 +250,7 @@ $organizations = $this->db->fetchPairs('SELECT gor_id_organization, gor_name FROM gems__organizations WHERE gor_active=1 AND gor_has_login=1 ORDER BY gor_name'); } catch (Exception $e) { try { + // 1.4 fallback $organizations = $this->db->fetchPairs('SELECT gor_id_organization, gor_name FROM gems__organizations WHERE gor_active=1 ORDER BY gor_name'); } catch (Exception $e) { $organizations = array(); @@ -278,7 +279,7 @@ return $organizations; } - + /** * Returns the organization * @param string $url @@ -287,7 +288,8 @@ public function getOrganizationForUrl($url) { try { - return $this->db->fetchOne("SELECT gor_id_organization FROM gems__organizations WHERE gor_active=1 AND gor_url_base = ?", $url); + $url = trim($this->db->quote($url), "'"); + return $this->db->fetchOne("SELECT gor_id_organization FROM gems__organizations WHERE gor_active=1 AND CONCAT(' ', gor_url_base, ' ') LIKE '% $url %'"); } catch (Exception $e) { return null; } Modified: trunk/library/classes/GemsEscort.php =================================================================== --- trunk/library/classes/GemsEscort.php 2012-03-16 15:26:05 UTC (rev 554) +++ trunk/library/classes/GemsEscort.php 2012-03-19 18:34:45 UTC (rev 555) @@ -1398,7 +1398,7 @@ public function prepareController() { if ($this instanceof Gems_Project_Layout_MultiLayoutInterface) { - $this->layoutSwitch($this->request); + $this->layoutSwitch(); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |