From: <gem...@li...> - 2011-11-03 10:55:47
|
Revision: 166 http://gemstracker.svn.sourceforge.net/gemstracker/?rev=166&view=rev Author: matijsdejong Date: 2011-11-03 10:55:39 +0000 (Thu, 03 Nov 2011) Log Message: ----------- Added creation of gems__users to patches.sql Concluded #36: _initProject now returns Gems_Project_ProjectSettings object, this can be overrule on a per project basis Redefined all project variables to Gems_Project_ProjectSettings Modified Paths: -------------- trunk/library/changelog.txt trunk/library/classes/Gems/Default/MailJobAction.php trunk/library/classes/Gems/Pdf.php trunk/library/classes/Gems/Tracker/Token/TokenLibrary.php trunk/library/classes/Gems/User/ProjectSuperUser.php trunk/library/classes/Gems/User/UserLoader.php trunk/library/classes/Gems/Util/Localized.php trunk/library/classes/Gems/Util.php trunk/library/classes/GemsEscort.php trunk/library/configs/db/patches.sql Added Paths: ----------- trunk/library/classes/Gems/Project/ProjectSettings.php Modified: trunk/library/changelog.txt =================================================================== --- trunk/library/changelog.txt 2011-11-02 12:34:57 UTC (rev 165) +++ trunk/library/changelog.txt 2011-11-03 10:55:39 UTC (rev 166) @@ -1,7 +1,7 @@ Important changes from 1.4.3 => 1.5 ============================================================ The table gems__staff is split into gems__staff and gems__user with all login data in gems__users -Passwords should be set with a project.ini->salt +Passwords should be set with a project.ini->salt. Salt is now a required project setting! MailController is now called MailTemplateController EmailController is now called CronController (with stub for compatibility) Modified: trunk/library/classes/Gems/Default/MailJobAction.php =================================================================== --- trunk/library/classes/Gems/Default/MailJobAction.php 2011-11-02 12:34:57 UTC (rev 165) +++ trunk/library/classes/Gems/Default/MailJobAction.php 2011-11-03 10:55:39 UTC (rev 166) @@ -48,11 +48,10 @@ { /** * - * @var ArrayObject + * @var Gems_Project_ProjectSettings */ public $project; - /** * The automatically filtered result * Modified: trunk/library/classes/Gems/Pdf.php =================================================================== --- trunk/library/classes/Gems/Pdf.php 2011-11-02 12:34:57 UTC (rev 165) +++ trunk/library/classes/Gems/Pdf.php 2011-11-03 10:55:39 UTC (rev 166) @@ -4,7 +4,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 @@ -15,7 +15,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 @@ -62,7 +62,7 @@ /** * - * @var ArrayObject + * @var Gems_Project_ProjectSettings */ protected $project; Added: trunk/library/classes/Gems/Project/ProjectSettings.php =================================================================== --- trunk/library/classes/Gems/Project/ProjectSettings.php (rev 0) +++ trunk/library/classes/Gems/Project/ProjectSettings.php 2011-11-03 10:55:39 UTC (rev 166) @@ -0,0 +1,149 @@ +<?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 <COPYRIGHT HOLDER> 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 Project + * @author Matijs de Jong <mj...@ma...> + * @copyright Copyright (c) 2011 Erasmus MC + * @license New BSD License + * @version $Id$ + */ + +/** + * Class that extends Array object to add Gems specific functions. + * + * @package Gems + * @subpackage Project + * @copyright Copyright (c) 2011 Erasmus MC + * @license New BSD License + * @since Class available since version 1.5 + */ +class Gems_Project_ProjectSettings extends ArrayObject +{ + /** + * Array of required keys. Give a string value for root keys + * or name => array() values for required subs keys. + * + * Deeper levels are not supported at the moment. + * + * @see checkRequiredValues() + * + * @var array + */ + protected $requiredKeys = array( + 'css' => array('gems'), + 'locale' => array('default'), + 'salt', + ); + + /** + * Creates the object and checks for required values. + * + * @param mixed $array + */ + public function __construct($array) + { + // Convert to array when needed + if ($array instanceof Zend_Config) { + $array = $array->toArray(); + } elseif ($array instanceof ArrayObject) { + $array = $array->getArrayCopy(); + } elseif (! is_array($array)) { + $array = (array) $array; + } + + parent::__construct($array, ArrayObject::ARRAY_AS_PROPS); + + $this->checkRequiredValues(); + } + + /** + * This function checks for the required project settings. + * + * Overrule this function or the $requiredParameters to add extra required settings. + * + * @see $requiredParameters + * + * @return void + */ + protected function checkRequiredValues() + { + $missing = array(); + foreach ($this->requiredKeys as $key => $names) { + if (is_array($names)) { + if (! ($this->offsetExists($key) && $this->offsetGet($key))) { + $subarray = array(); + } else { + $subarray = $this->offsetGet($key); + } + foreach ($names as $name) { + if (! isset($subarray[$name])) { + $missing[] = $key . '.' . $name; + } + } + } else { + if (! ($this->offsetExists($names) && $this->offsetGet($names))) { + $missing[] = $names; + } + } + } + + if ($missing) { + if (count($missing) == 1) { + $error = sprintf("Missing required project setting: '%s'.", reset($missing)); + } else { + $error = sprintf("Missing required project settings: '%s'.", implode("', '", $missing)); + } + throw new Gems_Exception_Coding($error); + } + + if (! ($this->offsetExists('name') && $this->offsetGet('name'))) { + $this->offsetSet('name', GEMS_PROJECT_NAME); + } + + $this->offsetSet('multiLocale', isset($project->locales) && (count($project->locales) > 1)); + } + + /** + * Returns a salted hash on the + * + * @param string $value The value to hash + * @return string The salted hash as a 32-character hexadecimal number. + */ + public function getValueHash($value) + { + $salt = $this->offsetExists('salt') ? $this->offsetGet('salt') : ''; + + if (false === strpos($salt, '%s')) { + return md5(sprintf($salt, $value), false); + } else { + return md5($salt . $value, false); + } + } +} Modified: trunk/library/classes/Gems/Tracker/Token/TokenLibrary.php =================================================================== --- trunk/library/classes/Gems/Tracker/Token/TokenLibrary.php 2011-11-02 12:34:57 UTC (rev 165) +++ trunk/library/classes/Gems/Tracker/Token/TokenLibrary.php 2011-11-03 10:55:39 UTC (rev 166) @@ -53,7 +53,7 @@ /** * - * @var ArrayObject + * @var Gems_Project_ProjectSettings */ protected $project; Modified: trunk/library/classes/Gems/User/ProjectSuperUser.php =================================================================== --- trunk/library/classes/Gems/User/ProjectSuperUser.php 2011-11-02 12:34:57 UTC (rev 165) +++ trunk/library/classes/Gems/User/ProjectSuperUser.php 2011-11-03 10:55:39 UTC (rev 166) @@ -50,7 +50,7 @@ /** * - * @var ArrayObject + * @var Gems_Project_ProjectSettings */ protected $project; Modified: trunk/library/classes/Gems/User/UserLoader.php =================================================================== --- trunk/library/classes/Gems/User/UserLoader.php 2011-11-02 12:34:57 UTC (rev 165) +++ trunk/library/classes/Gems/User/UserLoader.php 2011-11-03 10:55:39 UTC (rev 166) @@ -55,7 +55,7 @@ /** * - * @var ArrayObject + * @var Gems_Project_ProjectSettings */ protected $project; Modified: trunk/library/classes/Gems/Util/Localized.php =================================================================== --- trunk/library/classes/Gems/Util/Localized.php 2011-11-02 12:34:57 UTC (rev 165) +++ trunk/library/classes/Gems/Util/Localized.php 2011-11-03 10:55:39 UTC (rev 166) @@ -54,7 +54,7 @@ /** * - * @var ArrayObject + * @var Gems_Project_ProjectSettings */ protected $project; Modified: trunk/library/classes/Gems/Util.php =================================================================== --- trunk/library/classes/Gems/Util.php 2011-11-02 12:34:57 UTC (rev 165) +++ trunk/library/classes/Gems/Util.php 2011-11-03 10:55:39 UTC (rev 166) @@ -73,7 +73,7 @@ /** * - * @var ArrayObject + * @var Gems_Project_ProjectSettings */ protected $project; Modified: trunk/library/classes/GemsEscort.php =================================================================== --- trunk/library/classes/GemsEscort.php 2011-11-02 12:34:57 UTC (rev 165) +++ trunk/library/classes/GemsEscort.php 2011-11-03 10:55:39 UTC (rev 166) @@ -329,29 +329,18 @@ * * Use $this->project to access afterwards * - * @return ArrayObject + * @return Gems_Project_ProjectSettings */ protected function _initProject() { - $project = $this->includeProjectFile('project.ini'); + $projectArray = $this->includeFile(APPLICATION_PATH . '/configs/project'); - if (false === $project) { - $project['css']['gems'] = 'gems.css'; - $project['version'] = '0.0'; - $project['locale']['default'] = 'en'; - $project['locales']['en'] = 'en'; + if ($projectArray instanceof Gems_Project_ProjectSettings) { + $project = $projectArray; + } else { + $project = $this->createProjectClass('Project_ProjectSettings', $projectArray); } - if (! array_key_exists('name', $project)) { - $project['name'] = GEMS_PROJECT_NAME; - } - - if (is_array($project)) { - $project = new ArrayObject($project, ArrayObject::ARRAY_AS_PROPS); - } - - $project->multiLocale = isset($project->locales) && (count($project->locales) > 1); - return $project; } @@ -1228,7 +1217,7 @@ * @param string $fileName A filename in the include path * @return mixed false if nothing was returned */ - public function includeFile($fileName) + protected function includeFile($fileName) { $extension = pathinfo($fileName, PATHINFO_EXTENSION); @@ -1268,36 +1257,6 @@ return false; } - /** - * Searches and loads ini, xml, php or inc file in application/configs and project/configs. - * - * When no extension is specified the system looks for a file with the right extension. - * - * .php and .inc files run within the context of this object and thus can access all - * $this-> variables and functions. - * - * @param string $fileName_args One or more filenames, looks for the first to return a value - * @return mixed false if nothing was returned - */ - public function includeProjectFile($fileName_args) - { - foreach (func_get_args() as $fileName) { - // First check in the project configs directory - $result = $this->includeFile(APPLICATION_PATH . '/configs/' . $fileName); - - if (! $result) { - // Then check in the gems configs directory - $result = $this->includeFile(GEMS_LIBRARY_DIR . '/configs/' . $fileName); - } - - if ($result) { - return $result; - } - } - - return false; - } - public function loadLoginInfo($userName) { /** @@ -1344,13 +1303,17 @@ } } + /** + * Return a hashed of the string. + * + * @param string $name Optional name, is here for ModelAbstract setOnSave compatibility + * @param string $value The value to hash. + * @param boolean $new Optional is new, is here for ModelAbstract setOnSave compatibility + * @return string The salted hash as a 32-character hexadecimal number. + */ public function passwordHash($name, $value, $new) { - if (isset($this->project->salt)) { - return md5($this->project->salt . $value, false); - } else { - return md5($value, false); - } + return $this->project->getValueHash($value); } /** Modified: trunk/library/configs/db/patches.sql =================================================================== --- trunk/library/configs/db/patches.sql 2011-11-02 12:34:57 UTC (rev 165) +++ trunk/library/configs/db/patches.sql 2011-11-03 10:55:39 UTC (rev 166) @@ -218,6 +218,35 @@ CHANGE `grp_valid_for_unit` `grp_valid_for_unit` CHAR(1) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT 'D'; -- PATCH: New user login structure +CREATE TABLE if not exists gems__users ( + gsu_id_user bigint unsigned not null, + gsu_id_organization bigint not null references gems__organizations (gor_id_organization), + + gsu_login varchar(30) CHARACTER SET 'utf8' COLLATE 'utf8_general_ci' not null, + + gsu_user_class varchar(30) CHARACTER SET 'utf8' COLLATE 'utf8_general_ci' not null, + gsu_active boolean not null default 1, + + -- Common fields for standard 'store password in Gems' logins + -- Not every gsu_user_class will use them + gsu_password varchar(32) CHARACTER SET 'utf8' COLLATE 'utf8_general_ci' null, + gsu_failed_logins int(11) unsigned not null default 0, + gsu_last_failed timestamp null, + gsu_reset_key varchar(64) CHARACTER SET 'utf8' COLLATE 'utf8_general_ci' null, + gsu_reset_requested timestamp null, + gsu_reset_required boolean not null default 0, + + gsu_changed timestamp not null default current_timestamp on update current_timestamp, + gsu_changed_by bigint unsigned not null, + gsu_created timestamp not null, + gsu_created_by bigint unsigned not null, + + PRIMARY KEY (gsu_id_user, gsu_id_organization), + UNIQUE (gsu_login, gsu_id_organization) + ) + ENGINE=InnoDB + CHARACTER SET 'utf8' COLLATE 'utf8_general_ci'; + INSERT INTO gems__users (gsu_id_user, gsu_login, gsu_id_organization, gsu_user_class, gsu_active, gsu_password, gsu_failed_logins, gsu_last_failed, gsu_reset_key, gsu_reset_requested, gsu_reset_required, gsu_changed, gsu_changed_by, gsu_created, gsu_created_by) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |