|
From: <gem...@li...> - 2011-10-21 12:15:53
|
Revision: 123
http://gemstracker.svn.sourceforge.net/gemstracker/?rev=123&view=rev
Author: matijsdejong
Date: 2011-10-21 12:15:43 +0000 (Fri, 21 Oct 2011)
Log Message:
-----------
Saving last changes
Added Paths:
-----------
branches/newUser/classes/Gems/Model/UserModel.php
branches/newUser/classes/Gems/User/
branches/newUser/classes/Gems/User/ProjectSuperUser.php
branches/newUser/classes/Gems/User/UserAbstract.php
branches/newUser/classes/Gems/User/UserInterface.php
branches/newUser/classes/Gems/User/UserLoader.php
branches/newUser/configs/db/tables/gems__users.10.sql
Added: branches/newUser/classes/Gems/Model/UserModel.php
===================================================================
--- branches/newUser/classes/Gems/Model/UserModel.php (rev 0)
+++ branches/newUser/classes/Gems/Model/UserModel.php 2011-10-21 12:15:43 UTC (rev 123)
@@ -0,0 +1,117 @@
+<?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.
+ *
+ *
+ * @package Gems
+ * @subpackage Model
+ * @author Matijs de Jong <mj...@ma...>
+ * @copyright Copyright (c) 2011 Erasmus MC
+ * @license New BSD License
+ * @version $Id: Sample.php 203 2011-07-07 12:51:32Z matijs $
+ */
+
+/**
+ *
+ *
+ * @package Gems
+ * @subpackage Model
+ * @copyright Copyright (c) 2011 Erasmus MC
+ * @license New BSD License
+ * @since Class available since version 1.4.4
+ */
+class Gems_Model_UserModel extends Gems_Model_JoinModel
+{
+ /**
+ * The length of a user id.
+ *
+ * @var int
+ */
+ protected $userIdLen = 8;
+
+ /**
+ * Create a model that joins two or more tables
+ *
+ * @param string $name The name of the model
+ * @param string $secondTable The optional second base table for the model
+ * @param array $joinFields Array of source->dest primary keys for this join
+ * @param string $fieldPrefix Prefix to use for change fields (date/userid)
+ * @param bool $saveable Will changes to this table be saved
+ */
+ public function __construct($name, $secondTable = null, array $joinFields = null, $fieldPrefix = null, $saveable = null)
+ {
+ parent::__construct($name, 'gems__users', (null === $saveable ? $fieldPrefix : $saveable));
+
+ if ($fieldPrefix) {
+ Gems_Model::setChangeFieldsByPrefix($this, 'gsu');
+ }
+
+ if ($secondTable) {
+ $this->addTable($secondTable, $joinFields, $fieldPrefix, $saveable);
+ }
+ }
+
+ /**
+ * Finds a random unique user id.
+ *
+ * @return int
+ */
+ protected function _createUserId()
+ {
+ $max = $this->userIdLen;
+
+ do {
+ $out = mt_rand(1, 9);
+ for ($i = 1; $i < $this->userIdLen; $i++) {
+ $out .= mt_rand(0, 9);
+ }
+ // Make it a number
+ $out = intval($out);
+
+ } while ($this->db->fetchOne('SELECT gsu_id_user FROM gems__users WHERE gsu_id_user = ?', $out));
+
+ return $out;
+ }
+
+ /**
+ * Save a single model item.
+ *
+ * @param array $newValues The values to store for a single model item.
+ * @param array $filter If the filter contains old key values these are used
+ * to decide on update versus insert.
+ * @return array The values as they are after saving (they may change).
+ */
+ public function save(array $newValues, array $filter = null, array $saveTables = null)
+ {
+ if (! (isset($newValues['gsu_id_user']) && $newValues['gsu_id_user'])) {
+ // Load a new user id if needed
+ $newValues['gsu_id_user'] = $this->_createUserId();
+ }
+
+ parent::save($newValues, $filter, $saveTables);
+ }
+}
Property changes on: branches/newUser/classes/Gems/User
___________________________________________________________________
Added: bugtraq:url
+ http://survey.erasmusmc.nl/support/mantis/view.php?id=%BUGID%
Added: bugtraq:number
+ true
Added: bugtraq:logregex
+ #(\d+)
Added: branches/newUser/classes/Gems/User/ProjectSuperUser.php
===================================================================
--- branches/newUser/classes/Gems/User/ProjectSuperUser.php (rev 0)
+++ branches/newUser/classes/Gems/User/ProjectSuperUser.php 2011-10-21 12:15:43 UTC (rev 123)
@@ -0,0 +1,120 @@
+<?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.
+ *
+ *
+ * @package Gems
+ * @subpackage
+ * @author Matijs de Jong <mj...@ma...>
+ * @copyright Copyright (c) 2011 Erasmus MC
+ * @license New BSD License
+ * @version $Id: Sample.php 203 2011-07-07 12:51:32Z matijs $
+ */
+
+/**
+ *
+ *
+ * @package Gems
+ * @subpackage
+ * @copyright Copyright (c) 2011 Erasmus MC
+ * @license New BSD License
+ * @since Class available since version 1.4.4
+ */
+class Gems_User_ProjectSuperUser extends Gems_User_UserAbstract
+{
+ const MIN_PASSWORD_LENGTH = 10;
+
+ /**
+ * The role of this user.
+ *
+ * @var string
+ */
+ protected $_role = 'super';
+
+ /**
+ *
+ * @var ArrayObject
+ */
+ protected $project;
+
+ /**
+ *
+ * @var Gems_Util_Translated
+ */
+ protected $translated;
+
+ /**
+ * Check that the password is correct for this user.
+ *
+ * @param string $password Unencrypted password
+ * @return boolean
+ */
+ public function checkPassword($password)
+ {
+ if (isset($this->project->admin['pwd']) && ($this->project->admin['pwd'] == $password)) {
+ if (APPLICATION_ENV === 'production') {
+ if (strlen($string) < self::MIN_PASSWORD_LENGTH) {
+ throw new Gems_Exception(sprintf($this->translated->_('The password for the super user should be at least %s characters long on production systems.'), self::MIN_PASSWORD_LENGTH));
+ }
+ }
+
+ return true;
+ }
+
+ return false;
+ }
+
+ /**
+ * Returns true if the role of this user has the given privilege.
+ *
+ * @param string $privilege
+ * @return bool
+ */
+ public function hasPrivilege($privilege)
+ {
+ // Overloaded!!
+ //
+ // Return true also for any not 'nologin' privilege
+ return parent::hasPrivilege($privilege) || (! $this->acl) || (! $this->acl->isAllowed('nologin', null, $privilege));
+ }
+
+ /**
+ * Intialize the values for this user.
+ *
+ * Skipped when the user is the active user and is stored in the session.
+ *
+ * @param string $login_name
+ * @param int $organization Only used when more than one organization uses this $login_name
+ * @return boolean False when the object could not load.
+ */
+ protected function initVariables($login_name, $organization)
+ {
+ $this->setRole('super');
+ return true;
+ }
+
+}
Added: branches/newUser/classes/Gems/User/UserAbstract.php
===================================================================
--- branches/newUser/classes/Gems/User/UserAbstract.php (rev 0)
+++ branches/newUser/classes/Gems/User/UserAbstract.php 2011-10-21 12:15:43 UTC (rev 123)
@@ -0,0 +1,288 @@
+<?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.
+ *
+ *
+ * @package Gems
+ * @subpackage User
+ * @author Matijs de Jong <mj...@ma...>
+ * @copyright Copyright (c) 2011 Erasmus MC
+ * @license New BSD License
+ * @version $Id: Sample.php 203 2011-07-07 12:51:32Z matijs $
+ */
+
+/**
+ *
+ *
+ * @package Gems
+ * @subpackage User
+ * @copyright Copyright (c) 2011 Erasmus MC
+ * @license New BSD License
+ * @since Class available since version 1.4.4
+ */
+abstract class Gems_User_UserAbstract extends Gems_Registry_TargetAbstract implements Gems_User_UserInterface
+{
+ /**
+ *
+ * @var string
+ */
+ private $_login_name;
+
+ /**
+ *
+ * @var int
+ */
+ private $_organization_id;
+
+ /**
+ *
+ * @var mixed ArrayObject or Zend_Session_Namespace
+ */
+ private $_vars;
+
+ /**
+ *
+ * @var MUtil_Acl
+ */
+ protected $acl;
+
+ /**
+ * The escort session.
+ *
+ * For compatibility reasons only.
+ *
+ * @var Zend_Session_Namespace
+ */
+ protected $session;
+
+ /**
+ *
+ * @param string $login_name
+ * @param int $organization Only used when more than one organization uses this $login_name
+ */
+ public function __construct($login_name, $organization)
+ {
+ $this->_login_name = $login_name;
+ $this->_organization_id = $organization;
+ }
+
+ /**
+ * Returns the session namespace containing user data.
+ *
+ * @staticvar Zend_Session_Namespace $session
+ * @return Zend_Session_Namespace
+ */
+ private static function _getSessionStore()
+ {
+ static $session;
+
+ if (! $session) {
+ $session = new Zend_Session_Namespace('gems.' . GEMS_PROJECT_NAME . '.userdata', true);
+ }
+
+ return $session;
+ }
+
+ /**
+ * The store currently used.
+ *
+ * @return mixed ArrayObject or Zend_Session_Namespace
+ */
+ private function _getVariableStore()
+ {
+ $loginName = 'loginName';
+ $organizationId = 'organizationId';
+
+ if (! $this->_vars) {
+ $sessionStore = self::_getSessionStore();
+
+ if (isset($sessionStore->$loginName, $sessionStore->$organizationId) && ($sessionStore->$loginName == $this->_login_name) && ($sessionStore->$organizationId == $this->_organization_id)) {
+ $this->_vars = $sessionStore;
+ $this->_vars->__set($loginName, $this->_login_name);
+ $this->_vars->__set($organizationId, $this->_organization_id);
+ } else {
+ $this->_vars = new ArrayObject(array(), ArrayObject::ARRAY_AS_PROPS);
+ $this->_vars->offsetSet($loginName, $this->_login_name);
+ $this->_vars->offsetSet($organizationId, $this->_organization_id);
+ }
+
+ }
+
+ return $this->_vars;
+ }
+
+ /**
+ * 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 variables are missing.
+ */
+ public function checkRegistryRequestsAnswers()
+ {
+ if ($this->_getVariableStore() instanceof Zend_Session_Namespace) {
+ $init = true;
+ } else {
+ $init = $this->initVariables($this->_login_name, $this->_organization_id);
+ }
+
+ return $init && parent::checkRegistryRequestsAnswers();
+ }
+
+ /**
+ *
+ * @return string
+ */
+ protected function getLoginName()
+ {
+ return $this->_login_name;
+ }
+
+ /**
+ *
+ * @return int
+ */
+ protected function getOrganizationId()
+ {
+ return $this->_organization_id;
+ }
+
+ /**
+ * Returns the (current) role of this user.
+ *
+ * @return string
+ */
+ public function getRole()
+ {
+ return $this->getVar('user_role');
+ }
+
+ /**
+ * Get a value in whatever store is used by this object.
+ *
+ * @param string $name
+ * @return mixed
+ */
+ protected function getVar($name)
+ {
+ $store = $this->_getVariableStore();
+
+ if ($store instanceof Zend_Session_Namespace) {
+ if ($store->__isset($name)) {
+ return $store->__get($name);
+ }
+ } else {
+ if ($store->offsetExists($name)) {
+ return $store->offsetSet($name);
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Returns true if the role of this user has the given privilege.
+ *
+ * @param string $privilege
+ * @return bool
+ */
+ public function hasPrivilege($privilege)
+ {
+ return (! $this->acl) || $this->acl->isAllowed($this->getRole(), null, $privilege);
+ }
+
+ /**
+ * Intialize the values for this user.
+ *
+ * Skipped when the user is the active user and is stored in the session.
+ *
+ * @param string $login_name
+ * @param int $organization Only used when more than one organization uses this $login_name
+ * @return boolean False when the object could not load.
+ */
+ abstract protected function initVariables($login_name, $organization);
+
+ /**
+ * Set this user as the current user.
+ *
+ * This means that the data about this user will be stored in a session.
+ *
+ * @return Gems_User_UserAbstract
+ */
+ public function setAsCurrentUser()
+ {
+ // Get the current variables
+ $oldStore = $this->_getVariableStore();
+
+ // When $oldStore is a Zend_Session_Namespace, then this user is already the current user.
+ if (! $oldStore instanceof Zend_Session_Namespace) {
+ $this->_vars = self::_getSessionStore();
+
+ // Clean up what is there now.
+ $this->_vars->unsetAll();
+ $this->session->unsetAll();
+
+ foreach ($oldStore as $name => $value) {
+ $this->_vars->__set($name, $value);
+ $this->session->__set($name, $value);
+ }
+
+ }
+
+ return $this;
+ }
+
+ /**
+ * Sets the (current) role of this user.
+ *
+ * @param string $value Role
+ * @return Gems_User_UserAbstract (continuation pattern)
+ */
+ protected function setRole($value)
+ {
+ $this->setVar('user_role', $value);
+
+ return $this;
+ }
+
+ /**
+ * Store a value in whatever store is used by this object.
+ *
+ * @param string $name
+ * @param mixed $value
+ * @return Gems_User_UserAbstract (continuation pattern)
+ */
+ protected function setVar($name, $value)
+ {
+ $store = $this->_getVariableStore();
+
+ if ($store instanceof Zend_Session_Namespace) {
+ $store->__set($name, $value);
+ } else {
+ $store->offsetSet($name, $value);
+ }
+ return $this;
+ }
+}
Added: branches/newUser/classes/Gems/User/UserInterface.php
===================================================================
--- branches/newUser/classes/Gems/User/UserInterface.php (rev 0)
+++ branches/newUser/classes/Gems/User/UserInterface.php 2011-10-21 12:15:43 UTC (rev 123)
@@ -0,0 +1,60 @@
+<?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.
+ *
+ *
+ * @package Gems
+ * @subpackage User
+ * @author Matijs de Jong <mj...@ma...>
+ * @copyright Copyright (c) 2011 Erasmus MC
+ * @license New BSD License
+ * @version $Id: Sample.php 203 2011-07-07 12:51:32Z matijs $
+ */
+
+/**
+ *
+ *
+ * @package Gems
+ * @subpackage User
+ * @copyright Copyright (c) 2011 Erasmus MC
+ * @license New BSD License
+ * @since Class available since version 1.4.4
+ */
+interface Gems_User_UserInterface
+{
+ /**
+ * Check that the password is correct for this user.
+ *
+ * @param string $password Unencrypted password
+ * @return boolean
+ */
+ public function checkPassword($password);
+
+ public function hasPrivilege($privilege);
+
+ public function setAsCurrentUser();
+}
Added: branches/newUser/classes/Gems/User/UserLoader.php
===================================================================
--- branches/newUser/classes/Gems/User/UserLoader.php (rev 0)
+++ branches/newUser/classes/Gems/User/UserLoader.php 2011-10-21 12:15:43 UTC (rev 123)
@@ -0,0 +1,85 @@
+<?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.
+ *
+ *
+ * @package Gems
+ * @subpackage User
+ * @author Matijs de Jong <mj...@ma...>
+ * @copyright Copyright (c) 2011 Erasmus MC
+ * @license New BSD License
+ * @version $Id: Sample.php 203 2011-07-07 12:51:32Z matijs $
+ */
+
+/**
+ * Loads users.
+ *
+ * @package Gems
+ * @subpackage User
+ * @copyright Copyright (c) 2011 Erasmus MC
+ * @license New BSD License
+ * @since Class available since version 1.4.4
+ */
+class Gems_User_UserLoader extends Gems_Loader_TargetLoaderAbstract
+{
+ /**
+ * Allows sub classes of Gems_Loader_LoaderAbstract to specify the subdirectory where to look for.
+ *
+ * @var string $cascade An optional subdirectory where this subclass always loads from.
+ */
+ protected $cascade = 'User';
+
+ /**
+ *
+ * @var ArrayObject
+ */
+ protected $project;
+
+
+ /**
+ *
+ * @param string $login_name
+ * @param int $organization Only used when more than one organization uses this $login_name
+ * @return Gems_User_UserInterface
+ */
+ public function getUser($login_name, $organization)
+ {
+ if ($this->isProjectUser($login_name)) {
+ return $this->loadProjectUser($login_name, $organization);
+ }
+ }
+
+ protected function isProjectUser($login_name)
+ {
+ return isset($this->project->admin['user']) && ($this->project->admin['user'] == $login_name);
+ }
+
+ protected function loadProjectUser($login_name, $organization)
+ {
+ return $this->_getClass('ProjectSuperUser', null, array($login_name, $organization));
+ }
+}
Added: branches/newUser/configs/db/tables/gems__users.10.sql
===================================================================
--- branches/newUser/configs/db/tables/gems__users.10.sql (rev 0)
+++ branches/newUser/configs/db/tables/gems__users.10.sql 2011-10-21 12:15:43 UTC (rev 123)
@@ -0,0 +1,31 @@
+
+-- Table containing the users that are allowed to login
+--
+CREATE TABLE if not exists gems__users (
+ gsu_id_user bigint unsigned not null,
+
+ gsu_login varchar(30) CHARACTER SET 'utf8' COLLATE 'utf8_general_ci' not null,
+ gsu_id_organization bigint not null references gems__organizations (gor_id_organization),
+
+ 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),
+ UNIQUE(gsu_login, gsu_id_organization)
+ )
+ ENGINE=InnoDB
+ CHARACTER SET 'utf8' COLLATE 'utf8_general_ci';
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|