From: <gem...@li...> - 2012-04-20 07:26:07
|
Revision: 626 http://gemstracker.svn.sourceforge.net/gemstracker/?rev=626&view=rev Author: mennodekker Date: 2012-04-20 07:25:56 +0000 (Fri, 20 Apr 2012) Log Message: ----------- Final merge for 1.5.3 release Merged revision(s) 620-625 from trunk: When only one organization, the default value was not set, result was that superadmin could not even login anymore (that failure should still be fixed) ........ If you don't use it anymore, why not remove it ........ And some more cleanup ........ User gets clearer message from program after changing an item (if specified at action level) ........ Bug fix where tracks where shown multiple times if a user belonged to multiple organizations Code commented out meant for 1.5.4 ........ Prevent adding the same element multiple times, should not be a problem but this is cleaner ........ Modified Paths: -------------- tags/1.5.3-rc2/library/classes/Gems/Controller/ModelSnippetActionAbstract.php tags/1.5.3-rc2/library/classes/Gems/Snippets/ModelFormSnippetAbstract.php tags/1.5.3-rc2/library/classes/Gems/Tracker/Model/RespondentTrackModel.php tags/1.5.3-rc2/library/classes/Gems/Tracker/Token.php tags/1.5.3-rc2/library/classes/Gems/User/Form/OrganizationFormAbstract.php tags/1.5.3-rc2/library/classes/Gems/User/User.php tags/1.5.3-rc2/library/configs/db/patches.sql tags/1.5.3-rc2/library/configs/db/tables/gems__tokens.200.sql Removed Paths: ------------- tags/1.5.3-rc2/library/classes/Gems/Auth.php Property Changed: ---------------- tags/1.5.3-rc2/ tags/1.5.3-rc2/library/ Property changes on: tags/1.5.3-rc2 ___________________________________________________________________ Modified: svn:mergeinfo - /branches/1.5.0-pulse:306-430,467 /branches/1.5.x:426-455,458-472,475-481 /tags/1.5.0beta1:305 /tags/1.5.1:485,489,509-510 + /branches/1.5.0-pulse:306-430,467 /branches/1.5.x:426-455,458-472,475-481 /tags/1.5.0beta1:305 /tags/1.5.1:485,489,509-510 /trunk:620-625 Property changes on: tags/1.5.3-rc2/library ___________________________________________________________________ Modified: svn:mergeinfo - /branches/1.5.0-pulse/library:306-344,346,467 /branches/1.5.x/library:426-455,458-472,475-481 /branches/newUser:113-150 /branches/newUser2:175-207 /branches/userloader:259-324 /tags/1.5.0beta1/library:305 /tags/1.5.1/library:485,489,509-510,534 + /branches/1.5.0-pulse/library:306-344,346,467 /branches/1.5.x/library:426-455,458-472,475-481 /branches/newUser:113-150 /branches/newUser2:175-207 /branches/userloader:259-324 /tags/1.5.0beta1/library:305 /tags/1.5.1/library:485,489,509-510,534 /trunk/library:620-625 Deleted: tags/1.5.3-rc2/library/classes/Gems/Auth.php =================================================================== --- tags/1.5.3-rc2/library/classes/Gems/Auth.php 2012-04-20 07:16:35 UTC (rev 625) +++ tags/1.5.3-rc2/library/classes/Gems/Auth.php 2012-04-20 07:25:56 UTC (rev 626) @@ -1,251 +0,0 @@ -<?php - -/** - * 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 - * 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. - * - * @version $Id$ - * @package Gems - * @subpackage Auth - * @copyright Copyright (c) 2011 Erasmus MC - * @license New BSD License - */ - -/** - * Extension to the Zend_Auth framework in order to plug in extra features - * - * It adds translation to Zend_Auth_Result and performs the failed_login check with delay - * after a previous failed attempt. - * - * @author Menno Dekker - * @filesource - * @package Gems - * @subpackage Auth - */ -class Gems_Auth extends Zend_Auth -{ - /** - * Error constants - * - * These must be numeric constants smaller than zero for - * Zend_Auth_Result to work. - */ - const ERROR_DATABASE_NOT_INSTALLED = -11; - const ERROR_PASSWORD_DELAY = -12; - - /** - * @var array Message templates - */ - protected $_messageTemplates = array( - self::ERROR_DATABASE_NOT_INSTALLED => 'Installation not complete! Login is not yet possible!', - self::ERROR_PASSWORD_DELAY => 'Your account is temporarily blocked, please wait %s seconds', - ); - - /** - * Exponent to use when calculating delay - * @var int - */ - protected $_delayFactor = 4; - - /** - * @var Zend_Db_Table_Adapter - */ - public $db; - - public function __construct($db = null) - { - /** - * Check for an adapter being defined. if not, fetch the default adapter. - */ - if ($db === null) { - $this->db = Zend_Db_Table_Abstract::getDefaultAdapter(); - if (null === $this->db) { - require_once 'Zend/Validate/Exception.php'; - throw new Zend_Validate_Exception('No database adapter present'); - } - } else { - $this->db = $db; - } - } - - private function _error($code, $value1 = null, $value2 = null) - { - $messages = func_get_args(); - // array_splice($messages, 0, 1, $this->_messageTemplates[$code]); - $messages[0] = $this->_messageTemplates[$code]; - return new Zend_Auth_Result($code, null, (array) $messages); - } - - /** - * Authenticates against the supplied adapter - * - * @param Zend_Auth_Adapter_Interface $adapter - * @param array $formValues We need information not in the adapter. - * @return Zend_Auth_Result - */ - public function authenticate(Zend_Auth_Adapter_Interface $adapter, array $formValues = null) - { - try { - $remaining = 0; - $login_name = $formValues['userlogin']; - $organization = $formValues['organization']; - $sql = "SELECT gula_failed_logins, gula_last_failed FROM gems__user_login_attempts WHERE gula_login = ? AND gula_id_organization = ?"; - $values = $this->db->fetchRow($sql, array($login_name, $organization)); - - if (! $values) { - $values = array(); - $values['gula_login'] = $login_name; - $values['gula_id_organization'] = $organization; - $values['gula_failed_logins'] = 0; - $values['gula_last_failed'] = null; - - } elseif ($values['gula_failed_logins'] > 0) { - // Get the datetime - $last = new MUtil_Date($values['gula_last_failed'], Zend_Date::ISO_8601); - - // How long to wait until we can ignore the previous failed attempt - $delay = pow($values['gula_failed_logins'], GemsEscort::getInstance()->project->getAccountDelayFactor()); - - if (abs($last->diffSeconds()) <= $delay) { - // Response gets slowly slower - $sleepTime = min($values['gula_failed_logins'], 10); - sleep($sleepTime); - $remaining = $delay - abs($last->diffSeconds()) - $sleepTime; - if ($remaining>0) { - $result = $this->_error(self::ERROR_PASSWORD_DELAY, $remaining); - } - } - } - } catch (Zend_Db_Exception $e) { - // Fall through as this does not work if the database upgrade did not run - // MUtil_Echo::r($e); - } - - // We only forward to auth adapter when we have no timeout to prevent hammering the auth system - if (! isset($result) ) { - $result = parent::authenticate($adapter); - } - - if ($result->isValid()) { - $values['gula_failed_logins'] = 0; - $values['gula_last_failed'] = null; - } else { - if ($values['gula_failed_logins']) { - // Only increment when we have no password delay as the right password - // will not be accepted when we are in the delay. Can not check on the error - // code as it will be set to 'uncategorized' => -4 - if ($remaining>0) { - $values['gula_failed_logins'] += 1; - $values['gula_last_failed'] = new Zend_Db_Expr('CURRENT_TIMESTAMP'); - } - } else { - $values['gula_failed_logins'] = 1; - $values['gula_last_failed'] = new Zend_Db_Expr('CURRENT_TIMESTAMP'); - } - $values['gula_failed_logins'] = max($values['gula_failed_logins'], 1); - } - - try { - if (isset($values['gula_login'])) { - $this->db->insert('gems__user_login_attempts', $values); - } else { - $where = $this->db->quoteInto('gula_login = ? AND ', $login_name); - $where .= $this->db->quoteInto('gula_id_organization = ?', $organization); - $this->db->update('gems__user_login_attempts', $values, $where); - } - } catch (Zend_Db_Exception $e) { - // Fall through as this does not work if the database upgrade did not run - // MUtil_Echo::r($e); - } - - //Now localize - $result = $this->localize($result); - - return $result; - } - - /** - * Returns an instance of Gems_Auth - * - * Singleton pattern implementation - * - * @return Gems_Auth Provides a fluent interface - */ - public static function getInstance() - { - if (null === self::$_instance) { - self::$_instance = new self(); - } - - return self::$_instance; - } - - /** - * Perform translation on an error message - * - * To make them showup in the .PO files, add the most common messages to - * \library\Gems\languages\FakeTranslation.php - * The first element in the message array is translated, while the following messages are - * treated as sprintf parameters. - * - * @param Zend_Auth_Result $result - * @return Zend_Auth_Result - */ - public function localize($result) - { - $translate = GemsEscort::getInstance()->translate; - $code = $result->getCode(); - $identity = $result->getIdentity(); - $messages = $result->getMessages(); - - //Shift the first message off, this is the one to translate - $message = $translate->_(array_shift($messages)); - - /** - * Now give a default message for some default error codes. This has the - * positive side effect that we can remove some lines from FakeTranslations - */ - switch ($code) { - case Zend_Auth_Result::FAILURE_CREDENTIAL_INVALID: - // $message = $translate->_('Wrong password.'); - // break; - case Zend_Auth_Result::FAILURE_IDENTITY_NOT_FOUND: - $message = $translate->_('Combination of organization, username and password not found.'); - break; - } - - // Recombine with the others if any, they will be treated as params - if (count($messages)) { - $messages = array_merge((array) $message, (array) $messages); - - //Now do a sprintf if we have 1 or more params - $messages = call_user_func_array('sprintf', $messages); - } else { - $messages = array($message); - } - - return new Zend_Auth_Result($code, $identity, (array) $messages); - } -} \ No newline at end of file Modified: tags/1.5.3-rc2/library/classes/Gems/Controller/ModelSnippetActionAbstract.php =================================================================== --- tags/1.5.3-rc2/library/classes/Gems/Controller/ModelSnippetActionAbstract.php 2012-04-20 07:16:35 UTC (rev 625) +++ tags/1.5.3-rc2/library/classes/Gems/Controller/ModelSnippetActionAbstract.php 2012-04-20 07:25:56 UTC (rev 626) @@ -139,7 +139,8 @@ */ public function createAction() { - $this->createEditParameters['formTitle'] = $this->getCreateTitle(); + $this->createEditParameters['formTitle'] = $this->getCreateTitle(); + $this->createEditParameters['topicCallable'] = array($this, 'getTopic'); parent::createAction(); } @@ -160,7 +161,8 @@ */ public function editAction() { - $this->createEditParameters['formTitle'] = $this->getEditTitle(); + $this->createEditParameters['formTitle'] = $this->getEditTitle(); + $this->createEditParameters['topicCallable'] = array($this, 'getTopic'); parent::editAction(); } Modified: tags/1.5.3-rc2/library/classes/Gems/Snippets/ModelFormSnippetAbstract.php =================================================================== --- tags/1.5.3-rc2/library/classes/Gems/Snippets/ModelFormSnippetAbstract.php 2012-04-20 07:16:35 UTC (rev 625) +++ tags/1.5.3-rc2/library/classes/Gems/Snippets/ModelFormSnippetAbstract.php 2012-04-20 07:25:56 UTC (rev 626) @@ -71,6 +71,13 @@ protected $formTitle; /** + * When set getTopic uses this function instead of parent class. + * + * @var callable + */ + protected $topicCallable; + + /** * Required * * @var Gems_Menu @@ -181,4 +188,19 @@ return sprintf($this->_('Edit %s'), $this->getTopic()); } } + + /** + * Helper function to allow generalized statements about the items in the model to used specific item names. + * + * @param int $count + * @return $string + */ + public function getTopic($count = 1) + { + if (is_callable($this->topicCallable)) { + return call_user_func($this->topicCallable, $count); + } else { + return parent::getTopic($count); + } + } } Modified: tags/1.5.3-rc2/library/classes/Gems/Tracker/Model/RespondentTrackModel.php =================================================================== --- tags/1.5.3-rc2/library/classes/Gems/Tracker/Model/RespondentTrackModel.php 2012-04-20 07:16:35 UTC (rev 625) +++ tags/1.5.3-rc2/library/classes/Gems/Tracker/Model/RespondentTrackModel.php 2012-04-20 07:25:56 UTC (rev 626) @@ -64,7 +64,7 @@ { parent::__construct('surveys', 'gems__respondent2track', 'gr2t'); $this->addTable('gems__respondents', array('gr2t_id_user' => 'grs_id_user')); - $this->addTable('gems__respondent2org', array('gr2t_id_user' => 'gr2o_id_user')); + $this->addTable('gems__respondent2org', array('gr2t_id_user' => 'gr2o_id_user', 'gr2t_id_organization' => 'gr2o_id_organization')); $this->addTable('gems__tracks', array('gr2t_id_track' => 'gtr_id_track')); $this->addTable('gems__reception_codes', array('gr2t_reception_code' => 'grc_id_reception_code')); $this->addLeftTable('gems__staff', array('gr2t_created_by' => 'gsf_id_user')); Modified: tags/1.5.3-rc2/library/classes/Gems/Tracker/Token.php =================================================================== --- tags/1.5.3-rc2/library/classes/Gems/Tracker/Token.php 2012-04-20 07:16:35 UTC (rev 625) +++ tags/1.5.3-rc2/library/classes/Gems/Tracker/Token.php 2012-04-20 07:25:56 UTC (rev 626) @@ -888,7 +888,8 @@ $values['gto_start_time'] = new Zend_Db_Expr('CURRENT_TIMESTAMP'); $values['gto_in_source'] = 1; } - $values['gto_by'] = $userId; + $values['gto_by'] = $userId; + // 1.5.4 $values['gto_return_url'] = $_SERVER["HTTP_REFERER"]; $this->_updateToken($values, $userId); Modified: tags/1.5.3-rc2/library/classes/Gems/User/Form/OrganizationFormAbstract.php =================================================================== --- tags/1.5.3-rc2/library/classes/Gems/User/Form/OrganizationFormAbstract.php 2012-04-20 07:16:35 UTC (rev 625) +++ tags/1.5.3-rc2/library/classes/Gems/User/Form/OrganizationFormAbstract.php 2012-04-20 07:25:56 UTC (rev 626) @@ -151,8 +151,6 @@ if ($hidden) { if (! $element instanceof Zend_Form_Element_Hidden) { $element = new Zend_Form_Element_Hidden($this->organizationFieldName); - - $element->setValue($orgId); $this->addElement($element); } @@ -161,6 +159,8 @@ $orgId = reset($orgIds); } + $element->setValue($orgId); + } elseif (! $element instanceof Zend_Form_Element_Select) { $element = new Zend_Form_Element_Select($this->organizationFieldName); $element->setLabel($this->translate->_('Organization')); Modified: tags/1.5.3-rc2/library/classes/Gems/User/User.php =================================================================== --- tags/1.5.3-rc2/library/classes/Gems/User/User.php 2012-04-20 07:16:35 UTC (rev 625) +++ tags/1.5.3-rc2/library/classes/Gems/User/User.php 2012-04-20 07:25:56 UTC (rev 626) @@ -126,16 +126,7 @@ protected $userLoader; /** - * Use Zend_Auth for authentication * - * Warning: Zend_Auth contains only a partial ID of the current user, the base organization is missing - * - * @var boolean - */ - protected $useZendAuth = false; - - /** - * * @var Gems_Util */ protected $util; @@ -330,9 +321,6 @@ */ public function authenticate($password) { - if ($this->useZendAuth) { - $zendAuth = Zend_Auth::getInstance(); - } $auths = $this->loadAuthorizers($password); foreach ($auths as $result) { @@ -341,11 +329,7 @@ } if ($result instanceof Zend_Auth_Adapter_Interface) { - if ($this->useZendAuth) { - $result = $zendAuth->authenticate($result); - } else { - $result = $result->authenticate(); - } + $result = $result->authenticate(); } if ($result instanceof Zend_Auth_Result) { Modified: tags/1.5.3-rc2/library/configs/db/patches.sql =================================================================== --- tags/1.5.3-rc2/library/configs/db/patches.sql 2012-04-20 07:16:35 UTC (rev 625) +++ tags/1.5.3-rc2/library/configs/db/patches.sql 2012-04-20 07:25:56 UTC (rev 626) @@ -393,3 +393,7 @@ -- PATCH: make reset keys unique so we now whose key it is ALTER TABLE `gems__user_passwords` ADD UNIQUE KEY (gup_reset_key); ALTER TABLE `gems__staff` ADD UNIQUE KEY (gsf_reset_key); + +-- GEMS VERSION: 47 +-- PATCH: Add return url to tokens +-- ALTER TABLE gems__tokens ADD gto_return_url varchar(250) CHARACTER SET 'utf8' COLLATE 'utf8_general_ci' null default null AFTER gto_reception_code; Modified: tags/1.5.3-rc2/library/configs/db/tables/gems__tokens.200.sql =================================================================== --- tags/1.5.3-rc2/library/configs/db/tables/gems__tokens.200.sql 2012-04-20 07:16:35 UTC (rev 625) +++ tags/1.5.3-rc2/library/configs/db/tables/gems__tokens.200.sql 2012-04-20 07:25:56 UTC (rev 626) @@ -2,17 +2,17 @@ CREATE TABLE if not exists gems__tokens ( gto_id_token varchar(9) CHARACTER SET 'utf8' COLLATE 'utf8_general_ci' not null, - gto_id_respondent_track bigint unsigned not null + gto_id_respondent_track bigint unsigned not null references gems__respondent2track (gr2t_id_respondent_track), - gto_id_round bigint unsigned not null + gto_id_round bigint unsigned not null references gems__rounds (gro_id_round), -- non-changing fields calculated from previous two: - gto_id_respondent bigint unsigned not null + gto_id_respondent bigint unsigned not null references gems__respondents (grs_id_user), - gto_id_organization bigint unsigned not null + gto_id_organization bigint unsigned not null references gems__organizations (gor_id_organization), - gto_id_track bigint unsigned not null + gto_id_track bigint unsigned not null references gems__track (gtr_id_track), -- values initially filled from gems__rounds, but that may get different values later on @@ -25,14 +25,14 @@ -- real data gto_valid_from datetime, gto_valid_until datetime, - gto_mail_sent_date date, - gto_next_mail_date date, + gto_mail_sent_date date, + gto_next_mail_date date, - gto_start_time datetime, + gto_start_time datetime, gto_in_source boolean not null default 0, gto_by bigint(20) unsigned NULL, - gto_completion_time datetime, + gto_completion_time datetime, gto_duration_in_sec bigint(20) unsigned NULL, gto_followup_date date, -- depreciated gto_result varchar(20) CHARACTER SET 'utf8' COLLATE 'utf8_general_ci', @@ -41,6 +41,8 @@ gto_reception_code varchar(20) CHARACTER SET 'utf8' COLLATE 'utf8_general_ci' default 'OK' not null references gems__reception_codes (grc_id_reception_code), + -- gto_return_url varchar(250) CHARACTER SET 'utf8' COLLATE 'utf8_general_ci' null default null, + gto_changed timestamp not null default current_timestamp on update current_timestamp, gto_changed_by bigint unsigned not null, gto_created timestamp not null, This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |