From: <gem...@li...> - 2011-11-09 12:18:35
|
Revision: 197 http://gemstracker.svn.sourceforge.net/gemstracker/?rev=197&view=rev Author: matijsdejong Date: 2011-11-09 12:18:27 +0000 (Wed, 09 Nov 2011) Log Message: ----------- Continue #31: Staff kan weer gewijzigd worden. Current user is nu beter geregeld, CronAction is daardoor eenvoudiger. Nu nog option controller, change password, password lost en de import controller. Modified Paths: -------------- branches/newUser2/classes/Gems/Default/CronAction.php branches/newUser2/classes/Gems/Default/IndexAction.php branches/newUser2/classes/Gems/Default/StaffAction.php branches/newUser2/classes/Gems/Menu/MenuAbstract.php branches/newUser2/classes/Gems/Model.php branches/newUser2/classes/Gems/User/User.php branches/newUser2/classes/Gems/User/UserLoader.php branches/newUser2/classes/GemsEscort.php branches/newUser2/configs/db/patches.sql branches/newUser2/configs/db/tables/gems__staff.20.sql Removed Paths: ------------- branches/newUser2/classes/Gems/User/PasswordValidator.php Modified: branches/newUser2/classes/Gems/Default/CronAction.php =================================================================== --- branches/newUser2/classes/Gems/Default/CronAction.php 2011-11-08 19:02:26 UTC (rev 196) +++ branches/newUser2/classes/Gems/Default/CronAction.php 2011-11-09 12:18:27 UTC (rev 197) @@ -102,12 +102,6 @@ /** * - * @var Gems_User_User - */ - public $user; - - /** - * * @var Gems_Util */ public $util; @@ -159,9 +153,9 @@ public function mailJob() { - $userLoader = $this->loader->getUserLoader(); - $oldUserLogin = $this->user->getLoginName(); - $oldUserOrg = $this->user->getOrganizationId(); + $userLoader = $this->loader->getUserLoader(); + $startUser = $userLoader->getCurrentUser(); + $user = $startUser; $model = $this->loader->getTracker()->getTokenModel(); $mailer = new Gems_Email_TemplateMailer($this->escort); @@ -172,10 +166,14 @@ if ($jobs) { foreach ($jobs as $job) { - $user = $userLoader->getUserByStaffId($job['gmj_id_user_as']); + if ($user->getUserId() != $job['gmj_id_user_as']) { + $user = $userLoader->getUserByStaffId($job['gmj_id_user_as']); + } if ($user->isActive()) { - $user->setAsCurrentUser(); + if (! $user->isCurrentUser()) { + $user->setAsCurrentUser(); + } // Set up filter $filter = $this->defaultFilter; @@ -217,12 +215,16 @@ $msg = $mailer->getMessages(); if (! $msg) { - $msg[] = $this->_('No mails sent'); + $msg[] = $this->_('No mails sent.'); } + if ($mailer->bounceCheck()) { + array_unshift($msg, $this->_('On this test system all mail will be delivered to the from address.')); + } - $this->html->append($msg); + $this->addMessage($msg); - $user = $userLoader->getUser($oldUserLogin, $oldUserOrg); - $user->setAsCurrentUser(); + if (! $startUser->isCurrentUser()) { + $startUser->setAsCurrentUser(); + } } } \ No newline at end of file Modified: branches/newUser2/classes/Gems/Default/IndexAction.php =================================================================== --- branches/newUser2/classes/Gems/Default/IndexAction.php 2011-11-08 19:02:26 UTC (rev 196) +++ branches/newUser2/classes/Gems/Default/IndexAction.php 2011-11-09 12:18:27 UTC (rev 197) @@ -159,7 +159,7 @@ * If already logged in, try to redirect to the first allowed and visible menu item * if that fails, try to reroute to respondent/index */ - if (isset($this->session->user_id)) { + if ($this->loader->getCurrentUser()->isActive()) { if ($menuItem = $this->menu->findFirst(array('allowed' => true, 'visible' => true))) { $redirector = Zend_Controller_Action_HelperBroker::getStaticHelper('redirector'); $redirector->gotoRoute($menuItem->toRouteUrl($this->getRequest())); @@ -167,7 +167,6 @@ $this->_reroute(array('controller' => 'respondent', 'action'=>'index')); } } - // MUtil_Echo::track(get_class($this->loader->getUser('super', null))); $form = $this->_getLoginForm(); @@ -179,19 +178,20 @@ $user->setAsCurrentUser(); /** - * Fix current locale + * Fix current locale / organization in cookies */ - Gems_Cookies::setLocale($this->session->user_locale, $this->basepath->getBasePath()); + Gems_Cookies::setLocale($user->getLocale(), $this->basepath->getBasePath()); + Gems_Cookies::setOrganization($user->getOrganizationId(), $this->basepath->getBasePath()); /** * Ready */ - $this->addMessage(sprintf($this->_('Login successful, welcome %s.'), $this->session->user_name)); + $this->addMessage(sprintf($this->_('Login successful, welcome %s.'), $user->getFullName())); /** * Log the login */ - Gems_AccessLog::getLog($this->db)->log("index.login", $this->getRequest(), null, $this->session->user_id, true); + Gems_AccessLog::getLog($this->db)->log("index.login", $this->getRequest(), null, $user->getUserId(), true); if ($previousRequestParameters = $this->session->previousRequestParameters) { $this->_reroute(array('controller' => $previousRequestParameters['controller'], 'action' => $previousRequestParameters['action']), false); @@ -200,37 +200,6 @@ $this->_reroute(array('controller' => null, 'action' => null), true); } } - - /*/ Load login data - $this->escort->loadLoginInfo($_POST['userlogin']); - - /** - * Perform any project specific post login activities - * / - $this->escort->afterLogin($_POST['userlogin']); - - /** - * Fix current locale - * / - Gems_Cookies::setLocale($this->session->user_locale, $this->basepath->getBasePath()); - - /** - * Ready - * / - $this->addMessage(sprintf($this->_('Login successful, welcome %s.'), $this->session->user_name)); - - /** - * Log the login - * / - Gems_AccessLog::getLog($this->db)->log("index.login", $this->getRequest(), null, $this->session->user_id, true); - - if ($previousRequestParameters = $this->session->previousRequestParameters) { - $this->_reroute(array('controller' => $previousRequestParameters['controller'], 'action' => $previousRequestParameters['action']), false); - } else { - // This reroutes to the first available menu page after login - $this->_reroute(array('controller' => null, 'action' => null), true); - } - } // */ } else { $errors = $form->getErrors(); @@ -243,9 +212,11 @@ public function logoffAction() { - $this->addMessage($this->_('Good bye: ') . $this->session->user_name); - Gems_Auth::getInstance()->clearIdentity(); - $this->escort->afterLogout(); + $user = $this->loader->getCurrentUser(); + + $this->addMessage(sprintf($this->_('Good bye: %s.'), $user->getFullName())); + $user->unsetAsCurrentUser(); + // Gems_Auth::getInstance()->clearIdentity(); $this->_reroute(array('action' => 'index'), true); } Modified: branches/newUser2/classes/Gems/Default/StaffAction.php =================================================================== --- branches/newUser2/classes/Gems/Default/StaffAction.php 2011-11-08 19:02:26 UTC (rev 196) +++ branches/newUser2/classes/Gems/Default/StaffAction.php 2011-11-09 12:18:27 UTC (rev 197) @@ -44,6 +44,8 @@ */ class Gems_Default_StaffAction extends Gems_Controller_BrowseEditAction { + public $defaultStaffDefinition = Gems_User_UserLoader::USER_STAFF; + public $filterStandard = array('gsf_active' => 1); public $sortKey = array('name' => SORT_ASC); @@ -92,39 +94,58 @@ { $dbLookup = $this->util->getDbLookup(); + switch ($data['gul_user_class']) { + case Gems_User_UserLoader::USER_STAFF: + Gems_Model::addUserPassword($model); + $passwordField = 'gup_password'; + $model->setOnSave($passwordField, array($this->project, 'getValueHash')); + break; + + case Gems_User_UserLoader::USER_OLD_STAFF: + $passwordField = 'gsf_password'; + $model->setOnSave($passwordField, array($this, 'getOldPasswordHash')); + break; + + default: + $passwordField = false; + break; + } + $model->set('gsf_id_primary_group', 'multiOptions', MUtil_Lazy::call($dbLookup->getAllowedStaffGroups)); if ($new) { $model->set('gsf_id_primary_group', 'default', $dbLookup->getDefaultGroup()); - } else { - $model->set('gus_password', 'description', $this->_('Enter only when changing')); - $model->setSaveWhenNotNull('gus_password'); + } elseif ($passwordField) { + $model->set($passwordField, 'description', $this->_('Enter only when changing')); + $model->setSaveWhenNotNull($passwordField); } - $model->setOnSave('gus_password', array($this->escort, 'passwordHash')); $ucfirst = new Zend_Filter_Callback('ucfirst'); - $bridge->addHidden( 'gus_id_user'); - $bridge->addHidden( 'gsf_id_user'); // Needed for e-mail validation - $bridge->addHidden( 'gsu_user_class'); - $bridge->addText( 'gsu_login', 'size', 15, 'minlength', 4, - 'validator', $model->createUniqueValidator('gsu_login', array('gsu_id_user'))); + $bridge->addHidden( 'gsf_id_user'); + $bridge->addHidden( 'gul_id_user'); + $bridge->addHidden( 'gup_id_user'); + $bridge->addHidden( 'gul_user_class'); + $bridge->addText( 'gsf_login', 'size', 15, 'minlength', 4, + 'validator', $model->createUniqueValidator('gsf_login', array('gsf_id_user'))); // Can the organization be changed? if ($this->escort->hasPrivilege('pr.staff.edit.all')) { - $bridge->addHiddenMulti($model->getKeyCopyName('gus_id_organization')); - $bridge->addSelect('gus_id_organization'); + $bridge->addHiddenMulti($model->getKeyCopyName('gsf_id_organization')); + $bridge->addSelect('gsf_id_organization'); } else { - $bridge->addExhibitor('gus_id_organization'); + $bridge->addExhibitor('gsf_id_organization'); } - $bridge->addPassword('gus_password', - 'label', $this->_('Password'), - 'minlength', $this->project->passwords['MinimumLength'], - // 'renderPassword', true, - 'repeatLabel', $this->_('Repeat password'), - 'required', $new, - 'size', 15 - ); + if ($passwordField) { + $bridge->addPassword($passwordField, + 'label', $this->_('Password'), + 'minlength', $this->project->passwords['MinimumLength'], + // 'renderPassword', true, + 'repeatLabel', $this->_('Repeat password'), + 'required', $new, + 'size', 15 + ); + } $bridge->addRadio( 'gsf_gender', 'separator', ''); $bridge->addText( 'gsf_first_name', 'label', $this->_('First name')); $bridge->addFilter( 'gsf_first_name', $ucfirst); @@ -141,8 +162,8 @@ public function afterFormLoad(array &$data, $isNew) { - if (array_key_exists('gus_login', $data)) { - $this->_instanceId = $data['gus_login']; + if (array_key_exists('glf_login', $data)) { + $this->_instanceId = $data['gsf_login']; } $sql = "SELECT ggp_id_group,ggp_role FROM gems__groups WHERE ggp_id_group = " . (int) $data['gsf_id_primary_group']; @@ -169,11 +190,6 @@ { // MUtil_Model::$verbose = true; - /* $model = new Gems_Model_UserModel('staff', 'gems__staff', array('gus_id_user' => 'gsf_id_user'), 'gsf'); - if ($detailed) { - $model->copyKeys(); - } - //$model->resetOrder(); */ $model = $this->loader->getModels()->getStaffModel(); $model->set('gsf_login', 'label', $this->_('Login')); @@ -193,7 +209,7 @@ $model->set('gsf_gender', 'label', $this->_('Gender'), 'multiOptions', $this->util->getTranslated()->getGenders()); if ($detailed) { - $model->set('gul_user_class', 'default', Gems_User_UserLoader::USER_STAFF); + $model->set('gul_user_class', 'default', $this->defaultStaffDefinition); $model->set('gsf_iso_lang', 'label', $this->_('Language'), 'multiOptions', $this->util->getLocalized()->getLanguages()); $model->set('gsf_logout_on_survey', 'label', $this->_('Logout on survey'), 'multiOptions', $this->util->getTranslated()->getYesNo()); } @@ -235,7 +251,7 @@ $filter = parent::getDataFilter($data); if (! $this->escort->hasPrivilege('pr.staff.see.all')) { - $filter['gus_id_organization'] = $this->escort->getCurrentOrganization(); + $filter['gsf_id_organization'] = $this->escort->getCurrentOrganization(); } return $filter; } @@ -250,25 +266,16 @@ } /** - * Creates from the model a MUtil_Html_TableElement for display of a single item. + * Return an old style (< 1.5) hashed version of the input value. * - * Overruled to add css classes for Gems - * - * @param integer $columns The number of columns to use for presentation - * @param mixed $filter A valid filter for MUtil_Model_ModelAbstract->load() - * @param mixed $sort A valid sort for MUtil_Model_ModelAbstract->load() - * @return MUtil_Html_TableElement + * @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 getShowTable($columns = 1, $filter = null, $sort = null) + public function getOldPasswordHash($name, $value, $new) { - if ($this->escort->hasPrivilege('pr.staff.see.all')) { - // Model filter has now been set. - $data = $this->getModel()->loadFirst(); - - $this->_setParam('gus_id_organization', $data['gus_id_organization']); - $this->menu->getParameterSource()->offsetSet('gus_id_organization', $data['gus_id_organization']); - } - return parent::getShowTable($columns, $filter, $sort); + return md5($value); } public function getTopic($count = 1) Modified: branches/newUser2/classes/Gems/Menu/MenuAbstract.php =================================================================== --- branches/newUser2/classes/Gems/Menu/MenuAbstract.php 2011-11-08 19:02:26 UTC (rev 196) +++ branches/newUser2/classes/Gems/Menu/MenuAbstract.php 2011-11-09 12:18:27 UTC (rev 197) @@ -381,9 +381,9 @@ $page = $this->addPage($label, 'pr.staff', 'staff', 'index', $other); $page->addAutofilterAction(); $page->addCreateAction(); - $page->addShowAction()->setModelParameters(2); - $editPage = $page->addEditAction()->setModelParameters(2); - $delPage = $page->addDeleteAction()->setModelParameters(2); + $page->addShowAction(); + $editPage = $page->addEditAction(); + $delPage = $page->addDeleteAction(); if (! $this->escort->hasPrivilege('pr.staff.edit.all')) { $editPage->setParameterFilter('gus_id_organization', $this->escort->getCurrentOrganization()); $delPage->setParameterFilter('gus_id_organization', $this->escort->getCurrentOrganization()); Modified: branches/newUser2/classes/Gems/Model.php =================================================================== --- branches/newUser2/classes/Gems/Model.php 2011-11-08 19:02:26 UTC (rev 196) +++ branches/newUser2/classes/Gems/Model.php 2011-11-09 12:18:27 UTC (rev 197) @@ -96,18 +96,28 @@ protected $util; /** - * Function that automatically fills changed, changed_by, created and created_by fields with a certain prefix. + * Link the model to the user_logins table. * * @param Gems_Model_JoinModel $model - * @param string $loginField Field that links to login field. + * @param string $loginField Field that links to login name field. * @param string $organizationField Field that links to the organization field. */ - public function addAsUserLogin(Gems_Model_JoinModel $model, $loginField, $organizationField) + protected function addUserLogin(Gems_Model_JoinModel $model, $loginField, $organizationField) { $model->addTable('gems__user_logins', array($loginField => 'gul_login', $organizationField => 'gul_id_organization'), 'gul'); } /** + * Link the model to the user_passwords table. + * + * @param Gems_Model_JoinModel $model + */ + public static function addUserPassword(Gems_Model_JoinModel $model) + { + $model->addLeftTable('gems__user_passwords', array('gul_id_user' => 'gup_id_user'), 'gup'); + } + + /** * Create a Gems project wide unique user id * * @param string $name @@ -152,7 +162,7 @@ { $model = $this->_loadClass('RespondentModel', true); - // $this->addAsUserLogin($model, $this->respondentLoginIdField, 'gr2o_id_organization'); + // $this->addUserLogin($model, $this->respondentLoginIdField, 'gr2o_id_organization'); $this->setAsGemsUserId($model, 'grs_id_user'); return $model; @@ -211,7 +221,7 @@ { $model = new Gems_Model_JoinModel('staff', 'gems__staff', 'gsf'); - $this->addAsUserLogin($model, 'gsf_login', 'gsf_id_organization'); + $this->addUserLogin($model, 'gsf_login', 'gsf_id_organization'); $this->setAsGemsUserId($model, 'gsf_id_user'); return $model; Deleted: branches/newUser2/classes/Gems/User/PasswordValidator.php =================================================================== --- branches/newUser2/classes/Gems/User/PasswordValidator.php 2011-11-08 19:02:26 UTC (rev 196) +++ branches/newUser2/classes/Gems/User/PasswordValidator.php 2011-11-09 12:18:27 UTC (rev 197) @@ -1,101 +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. - * - * - * @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.5 - */ -class Gems_User_LoginPasswordValidator implements Zend_Validate_Interface -{ - /** - * - * @var string - */ - private $loginField = 'userlogin'; - - private $organizationField = 'organization'; - - /** - * - * @var Gems_User_UserLoader - */ - private $userLoader; - - public function __construct(Gems_User_UserLoader $loader, Gems_User_User $user = null) - { - $this->userLoader = $loader; - $this->user = $user; - } - - /** - * Returns true if and only if $value meets the validation requirements - * - * If $value fails validation, then this method returns false, and - * getMessages() will return an array of messages that explain why the - * validation failed. - * - * @param mixed $value - * @param mixed $content - * @return boolean - * @throws Zend_Validate_Exception If validation of $value is impossible - */ - public function isValid($value, $context = array()) - { - if (! $this->user) { - if (isset($context[])) - } - } - - /** - * Returns an array of messages that explain why the most recent isValid() - * call returned false. The array keys are validation failure message identifiers, - * and the array values are the corresponding human-readable message strings. - * - * If isValid() was never called or if the most recent isValid() call - * returned true, then this method returns an empty array. - * - * @return array - */ - public function getMessages() - { - } -} Modified: branches/newUser2/classes/Gems/User/User.php =================================================================== --- branches/newUser2/classes/Gems/User/User.php 2011-11-08 19:02:26 UTC (rev 196) +++ branches/newUser2/classes/Gems/User/User.php 2011-11-09 12:18:27 UTC (rev 197) @@ -172,7 +172,7 @@ */ public function checkRegistryRequestsAnswers() { - if ($this->session instanceof Zend_Session_Namespace) { + if (! $this->session instanceof Zend_Session_Namespace) { return false; } @@ -192,9 +192,29 @@ } /** + * Returns the full user name (first, prefix, last). * * @return string */ + public function getFullName() + { + return $this->_getVar('user_name'); + } + + /** + * The locale set for this user.. + * + * @return string + */ + public function getLocale() + { + return $this->_getVar('user_locale'); + } + + /** + * + * @return string + */ public function getLoginName() { return $this->_getVar('user_login'); @@ -228,6 +248,16 @@ } /** + * Checks if this user is the current user + * + * @return boolean + */ + public function isCurrentUser() + { + return $this->_getVariableStore() instanceof Zend_Session_Namespace; + } + + /** * Set this user as the current user. * * This means that the data about this user will be stored in a session. @@ -240,17 +270,49 @@ $oldStore = $this->_getVariableStore(); // When $oldStore is a Zend_Session_Namespace, then this user is already the current user. - if (! $oldStore instanceof Zend_Session_Namespace) { + if (! $this->isCurrentUser()) { + $this->userLoader->getCurrentUser()->unsetAsCurrentUser(); + $this->_vars = $this->session; - // Clean up what is there now. - $this->_vars->unsetAll(); - foreach ($oldStore as $name => $value) { $this->_vars->__set($name, $value); } + + $this->userLoader->setCurrentUser($this); } return $this; } + + /** + * Unsets this user as the current user. + * + * This means that the data about this user will no longer be stored in a session. + * + * @return Gems_User_UserAbstract + */ + public function unsetAsCurrentUser() + { + // When $oldStore is a Zend_Session_Namespace, then this user is already the current user. + if ($this->isCurrentUser()) { + // Get the current variables + $oldStore = $this->_getVariableStore(); + + $this->_vars = new ArrayObject(); + $this->_vars->setFlags(ArrayObject::STD_PROP_LIST); + + foreach ($oldStore as $name => $value) { + $this->_vars->offsetSet($name, $value); + } + + // Clean up what is there now in the session. + $this->session->unsetAll(); + + // Signal the loader + $this->userLoader->unsetCurrentUser(); + } + + return $this; + } } Modified: branches/newUser2/classes/Gems/User/UserLoader.php =================================================================== --- branches/newUser2/classes/Gems/User/UserLoader.php 2011-11-08 19:02:26 UTC (rev 196) +++ branches/newUser2/classes/Gems/User/UserLoader.php 2011-11-09 12:18:27 UTC (rev 197) @@ -80,18 +80,12 @@ protected $session; /** + * There can be only one, current user that is. * - * @param mixed $container A container acting as source for MUtil_Registry_Source - * @param array $dirs The directories where to look for requested classes + * @var Gems_User_User */ - public final function __construct($container, array $dirs) - { - parent::__construct($container, $dirs); + protected static $currentUser; - // Make sure Gems_User_User gets userLoader variable. - $this->addRegistryContainer(array('userLoader' => $this)); - } - /** * Checks the password for the specified $login_name and $organization and * handles the login security. @@ -249,19 +243,39 @@ } /** + * 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() + { + // Make sure Gems_User_User gets userLoader variable. + $extras['userLoader'] = $this; + + // Make sure that this code keeps working when _initSession + // is removed from GemsEscort + if (! $this->session instanceof Zend_Session_Namespace) { + $this->session = new Zend_Session_Namespace('gems.' . GEMS_PROJECT_NAME . '.session'); + + $extras['session'] = $this->session; + } + + $this->addRegistryContainer($extras); + } + + /** * Get the currently loggin in user * * @return Gems_User_User */ public final function getCurrentUser() { - static $currentUser; - - if (! $currentUser) { - $currentUser = $this->_loadClass('User', true, array($this->session)); + if (! self::$currentUser) { + self::$currentUser = $this->_loadClass('User', true, array($this->session)); } - return $currentUser; + return self::$currentUser; } /** @@ -489,4 +503,40 @@ { return $this->project->getSuperAdminName() == $login_name; } + + /** + * Sets a new user as the current user. + * + * @param Gems_User_User $user + * @return Gems_User_UserLoader (continuation pattern) + */ + public function setCurrentUser(Gems_User_User $user) + { + $this->unsetCurrentUser(); + self::$currentUser = $user; + + // Double check in case this function was used as original + // start for setting the user. + if (! $user->isCurrentUser()) { + $user->setAsCurrentUser(); + } + + return $this; + } + + /** + * Sets a new user as the current user. + * + * @param Gems_User_User $user + * @return Gems_User_UserLoader (continuation pattern) + */ + public function unsetCurrentUser() + { + // Remove if the currentUser still sees itself as the current user. + if ((self::$currentUser instanceof Gems_User_User) && self::$currentUser->isCurrentUser()) { + self::$currentUser->unsetAsCurrentUser(); + } + self::$currentUser = $user; + return $this; + } } Modified: branches/newUser2/classes/GemsEscort.php =================================================================== --- branches/newUser2/classes/GemsEscort.php 2011-11-08 19:02:26 UTC (rev 196) +++ branches/newUser2/classes/GemsEscort.php 2011-11-09 12:18:27 UTC (rev 197) @@ -444,22 +444,6 @@ * * Use $this->util to access afterwards * - * @return Gems_User_User - */ - protected function _initUser() - { - $this->bootstrap(array('loader', 'project', 'session')); - - return $this->getLoader()->getCurrentUser(); - } - - /** - * Initialize the util component. - * - * You can overrule this function to specify your own project translation method / file. - * - * Use $this->util to access afterwards - * * @return Gems_Util */ protected function _initUtil() @@ -975,7 +959,6 @@ public function afterLogout() { $this->session->unsetAll(); - $this->user = $this->getLoader()->getCurrentUser(); } /** Modified: branches/newUser2/configs/db/patches.sql =================================================================== --- branches/newUser2/configs/db/patches.sql 2011-11-08 19:02:26 UTC (rev 196) +++ branches/newUser2/configs/db/patches.sql 2011-11-09 12:18:27 UTC (rev 197) @@ -282,7 +282,7 @@ INSERT INTO gems__user_logins (gul_login, gul_id_organization, gul_user_class, gul_can_login, gul_changed, gul_changed_by, gul_created, gul_created_by) - SELECT gsf_login, gsf_id_organization, 'StaffUser', + SELECT gsf_login, gsf_id_organization, 'OldStaffUser', gsf_active, gsf_changed, gsf_changed_by, gsf_created, gsf_created_by FROM gems__staff WHERE (gsf_login, gsf_id_organization) NOT IN (SELECT gul_login, gul_id_organization FROM gems__user_logins); Modified: branches/newUser2/configs/db/tables/gems__staff.20.sql =================================================================== --- branches/newUser2/configs/db/tables/gems__staff.20.sql 2011-11-08 19:02:26 UTC (rev 196) +++ branches/newUser2/configs/db/tables/gems__staff.20.sql 2011-11-09 12:18:27 UTC (rev 197) @@ -7,9 +7,10 @@ gsf_login varchar(20) CHARACTER SET 'utf8' COLLATE 'utf8_general_ci' not null, gsf_id_organization bigint not null references gems__organizations (gor_id_organization), + gsf_active boolean null default 1, + -- depreciated gsf_password varchar(32) CHARACTER SET 'utf8' COLLATE 'utf8_general_ci' null, - gsf_active boolean null default 1, gsf_failed_logins int(11) unsigned null default 0, gsf_last_failed timestamp null, -- end depreciated This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |