From: <gem...@li...> - 2011-11-14 12:53:59
|
Revision: 208 http://gemstracker.svn.sourceforge.net/gemstracker/?rev=208&view=rev Author: matijsdejong Date: 2011-11-14 12:53:50 +0000 (Mon, 14 Nov 2011) Log Message: ----------- Reintegration of newUser2 branch for #31 - note: gems__users is no longer used. Modified Paths: -------------- trunk/library/changelog.txt trunk/library/classes/Gems/Auth.php trunk/library/classes/Gems/Cookies.php trunk/library/classes/Gems/Default/AskAction.php trunk/library/classes/Gems/Default/CronAction.php trunk/library/classes/Gems/Default/ExportAction.php trunk/library/classes/Gems/Default/IndexAction.php trunk/library/classes/Gems/Default/OptionAction.php trunk/library/classes/Gems/Default/OrganizationAction.php trunk/library/classes/Gems/Default/RespondentAction.php trunk/library/classes/Gems/Default/StaffAction.php trunk/library/classes/Gems/Default/SurveyMaintenanceAction.php trunk/library/classes/Gems/Default/TokenPlanAction.php trunk/library/classes/Gems/Email/TemplateMailer.php trunk/library/classes/Gems/Loader/LoaderAbstract.php trunk/library/classes/Gems/Loader.php trunk/library/classes/Gems/Menu/MenuAbstract.php trunk/library/classes/Gems/Model/DbaModel.php trunk/library/classes/Gems/Model.php trunk/library/classes/Gems/Project/Organization/MultiOrganizationInterface.php trunk/library/classes/Gems/Project/ProjectSettings.php trunk/library/classes/Gems/Tracker/Token.php trunk/library/classes/Gems/User/UserLoader.php trunk/library/classes/Gems/Util/DbLookup.php trunk/library/classes/GemsEscort.php trunk/library/classes/MUtil/Date.php trunk/library/classes/MUtil/Model/DatabaseModelAbstract.php trunk/library/classes/MUtil/Model/FormBridge.php trunk/library/classes/MUtil/Model/JoinModel.php trunk/library/classes/MUtil/Registry/Source.php trunk/library/configs/db/patches.sql trunk/library/configs/db/tables/gems__organizations.20.sql trunk/library/configs/db/tables/gems__staff.20.sql trunk/library/configs/db/tables/gems__user_ids.10.sql trunk/library/configs/db/tables/gems__user_logins.10.sql trunk/library/configs/db/tables/gems__user_passwords.50.sql Added Paths: ----------- trunk/library/classes/Gems/User/LoginPasswordValidator.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/StaffUserDefinition.php trunk/library/classes/Gems/User/User.php trunk/library/classes/Gems/User/UserDefinitionAbstract.php trunk/library/classes/Gems/User/UserDefinitionInterface.php trunk/library/classes/Gems/User/UserPasswordValidator.php trunk/library/configs/db/tables/gems__user_login_attempts.10.sql Removed Paths: ------------- trunk/library/classes/Gems/Model/UserModel.php trunk/library/classes/Gems/User/DatabaseUserAbstract.php trunk/library/classes/Gems/User/NoLoginUser.php trunk/library/classes/Gems/User/ProjectSuperUser.php trunk/library/classes/Gems/User/RespondentUser.php trunk/library/classes/Gems/User/StaffUser.php trunk/library/classes/Gems/User/UserAbstract.php trunk/library/classes/Gems/User/UserInterface.php trunk/library/classes/Gems/Validate/GemsPasswordUsername.php trunk/library/configs/db/tables/gems__users.10.sql trunk/library/configs/db_multi_layout/ Property Changed: ---------------- trunk/library/ Property changes on: trunk/library ___________________________________________________________________ Modified: svn:mergeinfo - /branches/newUser:113-150 + /branches/newUser:113-150 /branches/newUser2:175-207 Modified: trunk/library/changelog.txt =================================================================== --- trunk/library/changelog.txt 2011-11-14 12:43:05 UTC (rev 207) +++ trunk/library/changelog.txt 2011-11-14 12:53:50 UTC (rev 208) @@ -1,7 +1,8 @@ Important changes from 1.4.3 => 1.5 ============================================================ Passwords should be set with a project.ini->salt. Salt is now a required project setting! -The table gems__staff is split into gems__staff and gems__user with all login data in gems__users. +The table gems__staff is split into gems__staff, gems__user_logins with generic login data and gems__users_passwords containing db stored password information. +The table gems__user_ids provides unique and non-sequential user ids accross gems__staff and gems__respondents. The gems__respondent.grs_bsn has been renamed to grs_ssn, to make the code more international. MailController is now called MailTemplateController. EmailController is now called CronController (with stub for compatibility). Modified: trunk/library/classes/Gems/Auth.php =================================================================== --- trunk/library/classes/Gems/Auth.php 2011-11-14 12:43:05 UTC (rev 207) +++ trunk/library/classes/Gems/Auth.php 2011-11-14 12:53:50 UTC (rev 208) @@ -98,8 +98,8 @@ * Lookup last failed login and number of failed logins */ try { - $sql = "SELECT gsu_failed_logins, UNIX_TIMESTAMP(gsu_last_failed) - AS gsu_last_failed FROM gems__users WHERE gsu_login = ?"; + $sql = "SELECT gul_failed_logins, UNIX_TIMESTAMP(gul_last_failed) AS gul_last_failed + FROM gems__user_logins WHERE gul_login = ?"; $results = $this->db->fetchRow($sql, array($username)); } catch (Zend_Db_Exception $zde) { //If we need to apply a db patch, just use a default value @@ -107,10 +107,10 @@ MUtil_Echo::r(GemsEscort::getInstance()->translate->_('Please update the database')); } - $delay = pow($results['gsu_failed_logins'], $this->_delayFactor); - $remaining = ($results['gsu_last_failed'] + $delay) - time(); + $delay = pow($results['gul_failed_logins'], $this->_delayFactor); + $remaining = ($results['gul_last_failed'] + $delay) - time(); - if ($results['gsu_failed_logins'] > 0 && $remaining > 0) { + if ($results['gul_failed_logins'] > 0 && $remaining > 0) { //$this->_obscureValue = false; $result = $this->_error(self::ERROR_PASSWORD_DELAY, ceil($remaining / 60)); } Modified: trunk/library/classes/Gems/Cookies.php =================================================================== --- trunk/library/classes/Gems/Cookies.php 2011-11-14 12:43:05 UTC (rev 207) +++ trunk/library/classes/Gems/Cookies.php 2011-11-14 12:53:50 UTC (rev 208) @@ -26,6 +26,7 @@ * (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 Cookies * @author Matijs de Jong <mj...@ma...> @@ -73,14 +74,14 @@ } /** - * Get the organization from the cookie. + * Get the current organization from the cookie. * * @param Zend_Controller_Request_Abstract $request - * @return int The organization + * @return int The current organization */ public static function getOrganization(Zend_Controller_Request_Abstract $request) { - return self::get($request, self::ORGANIZATION_COOKIE); + return intval(self::get($request, self::ORGANIZATION_COOKIE)); } /** @@ -120,13 +121,15 @@ /** * Store the organization in a cookie. * - * @param int $locale Organization to store + * @param int $organization Organization to store * @param string $basepath The folder of the domain, if any. * @return boolean True if the cookie was stored. */ - public static function setOrganization($locale, $basepath = '/') + public static function setOrganization($organization, $basepath = '/') { - // Set the cookie for 30 days - return self::set(self::ORGANIZATION_COOKIE, $locale, 30, $basepath); + if ($organization) { + // Set the cookie for 30 days + return self::set(self::ORGANIZATION_COOKIE, $organization, 30, $basepath); + } } } Modified: trunk/library/classes/Gems/Default/AskAction.php =================================================================== --- trunk/library/classes/Gems/Default/AskAction.php 2011-11-14 12:43:05 UTC (rev 207) +++ trunk/library/classes/Gems/Default/AskAction.php 2011-11-14 12:53:50 UTC (rev 208) @@ -82,13 +82,14 @@ /*************** * Get the url * ***************/ - $url = $token->getUrl($language, $this->session->user_id ? $this->session->user_id : $respId); + $user = $this->loader->getCurrentUser(); + $url = $token->getUrl($language, $user->getUserId() ? $user->getUserId() : $respId); /************************ * Optional user logout * ************************/ - if (isset($this->session->user_logout) && $this->session->user_logout) { - $this->escort->afterLogout(); + if ($user->isLogoutOnSurvey()) { + $user->unsetAsCurrentUser(); } /*********************************** Modified: trunk/library/classes/Gems/Default/CronAction.php =================================================================== --- trunk/library/classes/Gems/Default/CronAction.php 2011-11-14 12:43:05 UTC (rev 207) +++ trunk/library/classes/Gems/Default/CronAction.php 2011-11-14 12:53:50 UTC (rev 208) @@ -26,17 +26,23 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * - * @author Michiel Rook <mi...@to...> - * @package Gems + * + * @author Michiel Rook <mi...@to...> + * @package Gems * @subpackage Default + * @copyright Copyright (c) 2011 Erasmus MC + * @license New BSD License + * @version $Id$ */ /** * Performs bulk-mail action, can be called from a cronjob * - * @author Michiel Rook <mi...@to...> - * @package Gems + * @package Gems * @subpackage Default + * @copyright Copyright (c) 2011 Erasmus MC + * @license New BSD License + * @since Class available since version 1.4 */ class Gems_Default_CronAction extends MUtil_Controller_Action { @@ -69,6 +75,12 @@ /** * + * @var Gems_Loader + */ + public $loader; + + /** + * * @var Gems_Menu */ public $menu; @@ -125,7 +137,7 @@ */ protected function getUserLogin($userId) { - return $this->db->fetchOne("SELECT gsu_login FROM gems__users WHERE gsu_id_user = ?", $userId); + return $this->db->fetchOne("SELECT gsf_login FROM gems__staff WHERE gsf_id_user = ?", $userId); } public function indexAction() @@ -141,112 +153,78 @@ public function mailJob() { - // Test: update `gems__tokens` set `gto_mail_sent_date` = null where `gto_mail_sent_date` > '2011-10-23' + $userLoader = $this->loader->getUserLoader(); + $startUser = $userLoader->getCurrentUser(); + $user = $startUser; - $currentUser = isset($this->session->user_login) ? $this->session->user_login : null; - $model = $this->loader->getTracker()->getTokenModel(); $mailer = new Gems_Email_TemplateMailer($this->escort); + // $mailer->setDefaultTransport(new MUtil_Mail_Transport_EchoLog()); $jobs = $this->db->fetchAll("SELECT * FROM gems__mail_jobs WHERE gmj_active = 1"); if ($jobs) { foreach ($jobs as $job) { - $this->escort->loadLoginInfo($this->getUserLogin($job['gmj_id_user_as'])); - - // Set up filter - $filter = $this->defaultFilter; - if ($job['gmj_filter_mode'] == 'R') { - $filter[] = 'gto_mail_sent_date <= DATE_SUB(CURRENT_DATE, INTERVAL ' . $job['gmj_filter_days_between'] . ' DAY)'; - } else { - $filter['gto_mail_sent_date'] = NULL; + if ($user->getUserId() != $job['gmj_id_user_as']) { + $user = $userLoader->getUserByStaffId($job['gmj_id_user_as']); } - if ($job['gmj_id_organization']) { - $filter['gto_id_organization'] = $job['gmj_id_organization']; - } - if ($job['gmj_id_track']) { - $filter['gto_id_track'] = $job['gmj_id_track']; - } - if ($job['gmj_id_survey']) { - $filter['gto_id_survey'] = $job['gmj_id_survey']; - } - $tokensData = $model->load($filter); + if ($user->isActive()) { + if (! $user->isCurrentUser()) { + $user->setAsCurrentUser(); + } - if (count($tokensData)) { - $mailer->setMethod($job['gmj_process_method']); - if ($job['gmj_from_method'] == 'F') { - $mailer->setFrom($job['gmj_from_fixed']); + // Set up filter + $filter = $this->defaultFilter; + if ($job['gmj_filter_mode'] == 'R') { + $filter[] = 'gto_mail_sent_date <= DATE_SUB(CURRENT_DATE, INTERVAL ' . $job['gmj_filter_days_between'] . ' DAY)'; } else { - $mailer->setFrom($job['gmj_from_method']); + $filter['gto_mail_sent_date'] = NULL; } + if ($job['gmj_id_organization']) { + $filter['gto_id_organization'] = $job['gmj_id_organization']; + } + if ($job['gmj_id_track']) { + $filter['gto_id_track'] = $job['gmj_id_track']; + } + if ($job['gmj_id_survey']) { + $filter['gto_id_survey'] = $job['gmj_id_survey']; + } - $templateData = $this->getTemplate($job['gmj_id_message']); - $mailer->setSubject($templateData['gmt_subject']); - $mailer->setBody($templateData['gmt_body']); + $tokensData = $model->load($filter); - $mailer->setTokens(MUtil_Ra::column('gto_id_token', $tokensData)); - $mailer->process($tokensData); - } + if (count($tokensData)) { + $mailer->setMethod($job['gmj_process_method']); + if ($job['gmj_from_method'] == 'F') { + $mailer->setFrom($job['gmj_from_fixed']); + } else { + $mailer->setFrom($job['gmj_from_method']); + } - Gems_Auth::getInstance()->clearIdentity(); - $this->escort->session->unsetAll(); + $templateData = $this->getTemplate($job['gmj_id_message']); + $mailer->setSubject($templateData['gmt_subject']); + $mailer->setBody($templateData['gmt_body']); + + $mailer->setTokens(MUtil_Ra::column('gto_id_token', $tokensData)); + $mailer->process($tokensData); + } + } } } $msg = $mailer->getMessages(); if (! $msg) { - $msg[] = $this->_('No mails sent'); + $msg[] = $this->_('No mails sent.'); } - - $this->html->append($msg); - - if ($currentUser) { - $this->escort->loadLoginInfo($currentUser); - } else { - $this->escort->afterLogout(); + if ($mailer->bounceCheck()) { + array_unshift($msg, $this->_('On this test system all mail will be delivered to the from address.')); } - /* - if (isset($this->project->email['automatic'])) { - $batches = $this->project->email['automatic']; - $numBatches = count($batches['mode']); + $this->addMessage($msg); - for ($i = 0; $i < $numBatches; $i++) { - $this->_organizationId = $batches['organization'][$i]; - - if (isset($batches['days'][$i])) { - $this->_intervalDays = $batches['days'][$i]; - } - - $this->escort->loadLoginInfo($batches['user'][$i]); - - $model->setFilter($this->getFilter($batches['mode'][$i])); - - $tokensData = $model->load(); - - if (count($tokensData)) { - $tokens = array(); - - foreach ($tokensData as $tokenData) { - $tokens[] = $tokenData['gto_id_token']; - } - - $templateData = $this->getTemplate($batches['template'][$i]); - $mailer->setSubject($templateData['gmt_subject']); - $mailer->setBody($templateData['gmt_body']); - $mailer->setMethod($batches['method'][$i]); - $mailer->setFrom($batches['from'][$i]); - $mailer->setTokens($tokens); - - $mailer->process($tokensData); - } - - Gems_Auth::getInstance()->clearIdentity(); - $this->escort->session->unsetAll(); - } + if (! $startUser->isCurrentUser()) { + $startUser->setAsCurrentUser(); } - // */ } } \ No newline at end of file Modified: trunk/library/classes/Gems/Default/ExportAction.php =================================================================== --- trunk/library/classes/Gems/Default/ExportAction.php 2011-11-14 12:43:05 UTC (rev 207) +++ trunk/library/classes/Gems/Default/ExportAction.php 2011-11-14 12:53:50 UTC (rev 208) @@ -144,7 +144,7 @@ { //Read some data from tables, initialize defaults... $surveys = $this->db->fetchPairs('SELECT gsu_id_survey, gsu_survey_name FROM gems__surveys WHERE gsu_active = 1 ORDER BY gsu_survey_name'); - $organizations = $this->escort->getAllowedOrganizations(); + $organizations = $this->loader->getCurrentUser()->getAllowedOrganizations(); $types = $this->export->getExportClasses(); //Create the basic form @@ -230,7 +230,7 @@ $answerModel = $survey->getAnswerModel($language); //Now add the organization id => name mapping - $answerModel->set('organizationid', 'multiOptions', $this->escort->getAllowedOrganizations()); + $answerModel->set('organizationid', 'multiOptions', $this->loader->getCurrentUser()->getAllowedOrganizations()); if (count($answers) === 0) { $answers[0] = array('' => sprintf($this->_('No %s found.'), $this->getTopic(0))); Modified: trunk/library/classes/Gems/Default/IndexAction.php =================================================================== --- trunk/library/classes/Gems/Default/IndexAction.php 2011-11-14 12:43:05 UTC (rev 207) +++ trunk/library/classes/Gems/Default/IndexAction.php 2011-11-14 12:53:50 UTC (rev 208) @@ -66,37 +66,94 @@ public $menu; /** - * Extension point, use different auth adapter if needed depending on the provided formValues + * @var Gems_Project_ProjectSettings + */ + public $project; + + /** + * Returns a link for the token input page. * - * This could be an organization passed in the login-form or something else. + * @return MUtil_Form_Element_Html + */ + protected function _getAskTokenLinkElement() + { + // Veld token + $element = new MUtil_Form_Element_Html('askToken'); + $element->br(); + $element->actionLink(array('controller' => 'ask', 'action' => 'token'), $this->_('Enter your token...')); + + return $element; + } + + /** + * Returns a basic form for this action. * - * @param array $formValues - * @return Zend_Auth_Adapter_Interface + * @param $description Optional description, %s is filled with project name. + * @return Gems_Form */ - protected function _getAuthAdapter($formValues) { - $adapter = new Zend_Auth_Adapter_DbTable($this->db, 'gems__users', 'gsu_login', 'gsu_password'); - $adapter->setIdentity($formValues['userlogin']); - $adapter->setCredential($this->escort->passwordHash(null, $formValues['password'], false)); - return $adapter; + protected function _getBasicForm($description = null) + { + Gems_Html::init(); + + $form = new Gems_Form(array('labelWidthFactor' => $this->labelWidthFactor)); + $form->setMethod('post'); + if ($description) { + $form->setDescription(sprintf($description, $this->project->getName())); + } + + return $form; } /** - * New version of login form + * Returns an element for keeping a reset key. * + * @return Zend_Form_Element_Hidden + */ + protected function _getKeyElement() + { + return new Zend_Form_Element_Hidden('key'); + } + + /** + * Returns a login form + * * @return Gems_Form */ protected function _getLoginForm() { - Gems_Html::init(); + $form = $this->_getBasicForm($this->_('Login to %s application')); + $form->addElement($this->_getOrganizationElement()); + $form->addElement($this->_getUserLoginElement()); + $form->addElement($this->_getPasswordElement()); + $form->addElement($this->_getSubmitButton($this->_('Login'))); + $form->addElement($this->_getAskTokenLinkElement()); + $form->addElement($this->_getResetLinkElement()); - $this->track[] = 'Get login form.'; + return $form; + } - $delayFactor = (isset($this->project->account) && isset($this->project->account['delayFactor']) ? $this->project->account['delayFactor'] : null); + /** + * Returns a link to the login page + * + * @return MUtil_Form_Element_Html + */ + protected function _getLoginLinkElement() + { + // Reset password + $element = new MUtil_Form_Element_Html('resetPassword'); + $element->br(); + $element->actionLink(array('controller' => 'index', 'action' => 'login'), $this->_('Back to login')); - $form = new Gems_Form(array('labelWidthFactor' => $this->labelWidthFactor)); - $form->setMethod('post'); - $form->setDescription(sprintf($this->_('Login to %s application'), $this->project->name)); + return $element; + } + /** + * Returns an element for determining / selecting the organization. + * + * @return Zend_Form_Element_Xhtml + */ + protected function _getOrganizationElement() + { if ($this->escort instanceof Gems_Project_Organization_SingleOrganizationInterface) { $element = new Zend_Form_Element_Hidden('organization'); $element->setValue($this->escort->getRespondentOrganization()); @@ -110,56 +167,106 @@ $element->setValue($this->escort->getCurrentOrganization()); } } - $form->addElement($element); - // Veld inlognaam - $element = new Zend_Form_Element_Text('userlogin'); - $element->setLabel($this->_('Username')); - $element->setAttrib('size', 10); - $element->setAttrib('maxlength', 20); - $element->setRequired(true); - $form->addElement($element); + return $element; + } + /** + * Returns a password element. + * + * @return Zend_Form_Element_Password + */ + protected function _getPasswordElement() + { // Veld password $element = new Zend_Form_Element_Password('password'); $element->setLabel($this->_('Password')); $element->setAttrib('size', 10); $element->setAttrib('maxlength', 20); $element->setRequired(true); - //$element->addValidator(new Gems_Validate_GemsPasswordUsername('userlogin', 'password', $this->db, $delayFactor)); - $form->addElement($element); + $element->addValidator(new Gems_User_LoginPasswordValidator($this->loader->getUserLoader(), 'userlogin', 'organization', $this->translate)); - // Submit knop - $element = new Zend_Form_Element_Submit('button'); - $element->setLabel($this->_('Login')); - $element->setAttrib('class', 'button'); - $form->addElement($element); + return $element; + } - // Veld token - $element = new MUtil_Form_Element_Html('askToken'); - $element->br(); - $element->actionLink(array('controller' => 'ask', 'action' => 'token'), $this->_('Enter your token...')); - $form->addElement($element); + /** + * Gets a reset password form. + * + * @return Gems_Form + */ + protected function _getResetForm() + { + $form = $this->_getBasicForm($this->_('Reset password for %s application')); + $form->addElement($this->_getKeyElement()); + $form->addElement($this->_getOrganizationElement()); + $form->addElement($this->_getUserLoginElement()); + $form->addElement($this->_getSubmitButton($this->_('Reset password'))); + $form->addElement($this->_getLoginLinkElement()); + return $form; + } + + /** + * Returns a link to the reset password page + * + * @return MUtil_Form_Element_Html + */ + protected function _getResetLinkElement() + { // Reset password $element = new MUtil_Form_Element_Html('resetPassword'); $element->br(); $element->actionLink(array('controller' => 'index', 'action' => 'resetpassword'), $this->_('Lost password')); - $form->addElement($element); - return $form; + return $element; } - // Dummy: always rerouted by GemsEscort + /** + * Returns a submit button. + * + * @param string $label + * @return Zend_Form_Element_Submit + */ + protected function _getSubmitButton($label) + { + // Submit knop + $element = new Zend_Form_Element_Submit('button'); + $element->setLabel($label); + $element->setAttrib('class', 'button'); + + return $element; + } + + /** + * Returns a login name element. + * + * @return Zend_Form_Element_Text + */ + protected function _getUserLoginElement() + { + // Veld inlognaam + $element = new Zend_Form_Element_Text('userlogin'); + $element->setLabel($this->_('Username')); + $element->setAttrib('size', 10); + $element->setAttrib('maxlength', 20); + $element->setRequired(true); + + return $element; + } + + /** + * Dummy: always rerouted by GemsEscort + */ public function indexAction() { } + /** + * Default login page + */ public function loginAction() { - /** - * 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 already logged in, try to redirect to the first allowed and visible menu item + // if that fails, try to reroute to respondent/index + 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,87 +274,33 @@ $this->_reroute(array('controller' => 'respondent', 'action'=>'index')); } } - // MUtil_Echo::track(get_class($this->loader->getUser('super', null))); $form = $this->_getLoginForm(); - if ($this->_request->isPost()) { - if ($form->isValid($_POST, false)) { - /* - if ($user = $this->loader->getUser($_POST['userlogin'], $_POST['organization'])) { + $request = $this->getRequest(); + if ($request->isPost()) { + if ($form->isValid($request->getPost(), false)) { - } // */ + $user = $this->loader->getUser($request->getParam('userlogin'), $request->getParam('organization')); - if (isset($this->project->admin) && $this->project->admin['user'] == $_POST['userlogin'] && $this->project->admin['pwd'] == $_POST['password']) { - $this->session->user_id = 2000; - $this->session->user_name = $_POST['userlogin']; - $this->session->user_group = 800; - $this->session->user_role = 'master'; - $this->session->user_organization_id = 70; - $this->session->user_organization_name = 'SUPER ADMIN'; - $this->session->user_style = 'gems'; - //Als er nog geen tabellen zijn, moet dit ingesteld worden - //@@TODO Nog kijken hoe beter op te lossen (met try op tabel ofzo) - $this->session->allowedOrgs = array($this->session->user_organization_id=>$this->session->user_organization_name); + if ($user->isActive()) { + $user->setAsCurrentUser(); /** - * Ready + * Fix current locale / organization in cookies */ - $this->addMessage(sprintf($this->_('Login successful, welcome %s.'), $this->session->user_name)); - $this->_reroute(array('controller' => 'database', 'action' => 'index'), true); - return; - } - //Now check authentication - $adapter = $this->_getAuthAdapter($form->getValues()); - $auth = Gems_Auth::getInstance(); - $result = $auth->authenticate($adapter, $_POST['userlogin']); + Gems_Cookies::setLocale($user->getLocale(), $this->basepath->getBasePath()); + Gems_Cookies::setOrganization($user->getOrganizationId(), $this->basepath->getBasePath()); - // Allow login using old password. - if ((! $result->isValid()) && ($userid = $this->db->fetchOne("SELECT gsu_id_user FROM gems__users WHERE gsu_active = 1 AND gsu_password IS NULL AND gsu_login = ?", $_POST['userlogin']))) { - - $adapter = new Zend_Auth_Adapter_DbTable($this->db, 'gems__staff', 'gsf_id_user', 'gsf_password'); - $adapter->setIdentity($userid); - $adapter->setCredential(md5($_POST['password'], false)); - $result = $auth->authenticate($adapter, $_POST['userlogin']); - // MUtil_Echo::track('old autho'); - } else { - // MUtil_Echo::track('new autho'); - } - - if (!$result->isValid()) { - // Invalid credentials - $errors = $result->getMessages(); - $this->addMessage($errors); - $code = $result->getCode(); - if ($code != Gems_Auth::ERROR_PASSWORD_DELAY) { - $this->escort->afterFailedLogin(); - } - - $this->view->form = $form; - } else { - // Load login data - $this->escort->loadLoginInfo($_POST['userlogin']); - /** - * Perform any project specific post login activities - */ - $this->escort->afterLogin($_POST['userlogin']); - - /** - * Fix current locale & organization - */ - Gems_Cookies::setLocale($this->session->user_locale, $this->basepath->getBasePath()); - Gems_Cookies::setOrganization($this->session->user_organization_id, $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); @@ -255,116 +308,87 @@ // This reroutes to the first available menu page after login $this->_reroute(array('controller' => null, 'action' => null), true); } + return; } } else { $errors = $form->getErrors(); - - $this->view->form = $form; } - } else { - $this->view->form = $form; } + $this->view->form = $form; } + /** + * Default logoff action + */ 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(); $this->_reroute(array('action' => 'index'), true); } - protected function _getResetForm() - { - $form = new Gems_Form(array('labelWidthFactor' => $this->labelWidthFactor)); - $form->setMethod('post'); - $form->setDescription(sprintf($this->_('Reset password for %s application'), $this->project->name)); - - // Veld inlognaam - $element = new Zend_Form_Element_Text('userlogin'); - $element->setLabel($this->_('Username')); - $element->setAttrib('size', 10); - $element->setAttrib('maxlength', 20); - $element->setRequired(true); - $form->addElement($element); - - // Submit knop - $element = new Zend_Form_Element_Submit('button'); - $element->setLabel($this->_('Reset password')); - $element->setAttrib('class', 'button'); - $form->addElement($element); - - return $form; - } - + /** + * Reset password page. + */ public function resetpasswordAction() { $this->view->setScriptPath(GEMS_LIBRARY_DIR . '/views/scripts' ); + $request = $this->getRequest(); $form = $this->_getResetForm(); - $mail = new MUtil_Mail(); - $mail->setFrom('no...@er...'); + if ($request->isPost() && $form->isValid($request->getPost())) { - if (isset($this->escort->project->email) && isset($this->escort->project->email['bcc'])) { - $mail->addBcc($this->escort->project->email['bcc']); - } + $user = $this->loader->getUser($request->getParam('userlogin'), $request->getParam('organization')); - if ($this->_request->isPost() && $form->isValid($_POST)) { - $sql = $this->db->quoteInto("SELECT gsu_id_user, gsf_email, gsu_reset_key, DATEDIFF(NOW(), gsu_reset_requested) AS gsf_days FROM gems__users INNER JOIN gems__staff ON gsu_id_user = gsf_id_user WHERE gsu_login = ?", $_POST['userlogin']); - $result = $this->db->fetchRow($sql); + If ($user->canResetPassword()) { + if ($key = $request->getParam('key')) { + // Key has been passed by mail + if ($user->checkPasswordResetKey($key)) { + $user->setPasswordResetRequired(true); + $user->setAsCurrentUser(); + $this->addMessage($this->_('Reset accepted, enter your new password.')); + $user->gotoStartPage($this->menu, $request); + return; + } else { + $this->addMessage($this->_('This key timed out or does not belong to this user.')); + } + } else { + // P{ass mail by key + $mail = new MUtil_Mail(); + $mail->setFrom('mj...@ma...'); + $mail->addTo($user->getEmailAddress(), $user->getFullName()); - if (empty($result) || empty($result['gsf_email'])) { - $this->addMessage($this->_('No such user found or no e-mail address known')); - } else if (!empty($result['gsu_reset_key']) && $result['gsf_days'] < 1) { - $this->addMessage($this->_('Reset e-mail already sent, please try again after 24 hours')); - } else { - $email = $result['gsf_email']; - $key = md5(time() . $email); - $url = $this->util->getCurrentURI('index/resetpassword/key/' . $key); + if (isset($this->escort->project->email) && isset($this->escort->project->email['bcc'])) { + $mail->addBcc($this->escort->project->email['bcc']); + } - $this->db->update('gems__users', array('gsu_reset_key' => $key, 'gsu_reset_requested' => new Zend_Db_Expr('NOW()')), 'gsu_id_user = ' . $result['gsu_id_user']); - $mail->setSubject('Password reset requested'); - $mail->setBodyText('To reset your password, please click this link: ' . $url); + $key = $user->getPasswordResetKey(); - $mail->addTo($email); + $url = $this->util->getCurrentURI('index/resetpassword/key/' . $key); - try { - $mail->send(); - $this->addMessage($this->_('Follow the instructions in the e-mail')); - } catch (Exception $e) { - $this->addMessage($this->_('Unable to send e-mail')); - throw $e; - } - } - } else if ($key = $this->_request->getParam('key')) { - $sql = $this->db->quoteInto("SELECT gsu_id_user, gsf_email FROM gems__users INNER JOIN gems__staff ON gsu_id_user = gsf_id_user WHERE gsu_reset_key = ?", $key); - $result = $this->db->fetchRow($sql); + $mail->setSubject($this->_('Password reset requested')); + $mail->setBodyText(sprintf($this->_('To reset your password for %s, please click this link: %s'), GEMS_PROJECT_NAME_UC, $url)); - if (!empty($result)) { - // generate new password - $password = $this->escort->getRandomPassword(); - $passwordHash = $this->escort->passwordHash(null, $password, false); - $mail->setSubject('New password'); - $mail->setBodyText('Your new password has been generated. Your new password is: ' . $password); - - $mail->addTo($result['gsf_email']); - - try { - $mail->send(); - $this->addMessage($this->_('An e-mail was sent containing your new password')); - $this->db->update('gems__users', array('gsu_reset_key' => new Zend_Db_Expr('NULL'), 'gsu_reset_requested' => new Zend_Db_Expr('NULL'), 'gsu_password' => $passwordHash), 'gsu_id_user = ' . $result['gsu_id_user']); - $this->_reroute(array('action' => 'index'), true); - } catch (Exception $e) { - $this->addMessage($this->_('Unable to send e-mail')); - throw $e; + try { + $mail->send(); + $this->addMessage($this->_('We sent you an e-mail with a reset link. Click on the link in the e-mail.')); + } catch (Exception $e) { + $this->addMessage($this->_('Unable to send e-mail.')); + throw $e; + } } } else { - $this->addMessage($this->_('Unknown request')); + $this->addMessage($this->_('No such user found or no e-mail address known or user cannot be reset.')); } } - + if ($request->getParam('key')) { + $this->addMessage($this->_('We received your password reset key.')); + $this->addMessage($this->_('Please enter the organization and username belonging to this key.')); + } $this->view->form = $form; } } Modified: trunk/library/classes/Gems/Default/OptionAction.php =================================================================== --- trunk/library/classes/Gems/Default/OptionAction.php 2011-11-14 12:43:05 UTC (rev 207) +++ trunk/library/classes/Gems/Default/OptionAction.php 2011-11-14 12:53:50 UTC (rev 208) @@ -1,6 +1,5 @@ <?php - /** * Copyright (c) 2011, Erasmus MC * All rights reserved. @@ -26,60 +25,52 @@ * 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. - */ - -/** * - * @author Matijs de Jong - * @since 1.0 - * @version 1.1 - * @package Gems + * + * @package Gems * @subpackage Default + * @author Matijs de Jong <mj...@ma...> + * @copyright Copyright (c) 2011 Erasmus MC + * @license New BSD License + * @version $Id$ */ /** * - * @author Matijs de Jong - * @package Gems + * @package Gems * @subpackage Default + * @copyright Copyright (c) 2011 Erasmus MC + * @license New BSD License + * @since Class available since version 1.1 */ class Gems_Default_OptionAction extends Gems_Controller_BrowseEditAction { public $autoFilter = false; /** - * Adds elements from the model to the bridge that creates the form. * - * Overrule this function to add different elements to the browse table, without - * having to recode the core table building code. - * - * @param MUtil_Model_FormBridge $bridge - * @param MUtil_Model_ModelAbstract $model - * @param array $data The data that will later be loaded into the form - * @param optional boolean $new Form should be for a new element - * @return void|array When an array of new values is return, these are used to update the $data array in the calling function + * @var Gems_Project_ProjectSettings */ - protected function addFormElements(MUtil_Model_FormBridge $bridge, MUtil_Model_ModelAbstract $model, array $data, $new = false) - { - $bridge->addHidden( 'gsu_id_user'); - $bridge->addHidden( 'gsu_id_organization'); - $bridge->addHidden( 'gsf_id_user'); - $bridge->addExhibitor('gsu_login', array('size' => 15, 'minlength' => 4)); - $bridge->addText( 'gsf_first_name'); - $bridge->addText( 'gsf_surname_prefix'); - $bridge->addText( 'gsf_last_name'); - $bridge->addText( 'gsf_email', array('size' => 30)); + public $project; - $bridge->addRadio( 'gsf_gender', 'separator', ''); - - $bridge->addSelect( 'gsf_iso_lang', array('label' => $this->_('Language'), 'multiOptions' => $this->util->getLocalized()->getLanguages())); - } - + /** + * Hook to perform action after a record (with changes) was saved + * + * As the data was already saved, it can NOT be changed anymore + * + * @param array $data + * @param boolean $isNew + * @return boolean True when you want to display the default 'saved' messages + */ public function afterSave(array $data, $isNew) { - $this->escort->loadLoginInfo($data['gsu_login']); + // Reload the current user data + $this->loader->getUser($data['gsf_login'], $data['gsf_id_organization']); } + /** + * Allow a user to change his / her password. + */ public function changePasswordAction() { /************* @@ -87,20 +78,31 @@ *************/ $form = $this->createForm(); - $sql = "SELECT CASE WHEN gsu_password IS NULL THEN 0 ELSE 1 END FROM gems__users WHERE gsu_id_user = ? AND gsu_id_organization = ?"; - if ($this->db->fetchOne($sql, array($this->session->user_id, $this->session->user_organization_id))) { - // Veld current password + $user = $this->loader->getCurrentUser(); + + if (! $user->canSetPassword()) { + $this->addMessage($this->_('You are not allowed to change your password.')); + return; + } + + if ($user->isPasswordResetRequired()) { + $this->menu->setVisible(false); + } elseif ($user->hasPassword()) { + // Field current password + // + // This is only used when the password is already set, which may not always be the case + // e.g. when using embedded login in Pulse. $element = new Zend_Form_Element_Password('old_password'); $element->setLabel($this->_('Current password')); $element->setAttrib('size', 10); $element->setAttrib('maxlength', 20); $element->setRenderPassword(true); $element->setRequired(true); - $element->addValidator(new Gems_Validate_GemsPasswordUsername($this->session->user_login, 'old_password', $this->db)); + $element->addValidator(new Gems_User_UserPasswordValidator($user, $this->translate)); $form->addElement($element); } - // Veld new password + // Field new password $element = new Zend_Form_Element_Password('new_password'); $element->setLabel($this->_('New password')); $element->setAttrib('size', 10); @@ -111,7 +113,7 @@ $element->addValidator(new MUtil_Validate_IsConfirmed('repeat_password', $this->_('Repeat password'))); $form->addElement($element); - // Veld repeat password + // Field repeat password $element = new Zend_Form_Element_Password('repeat_password'); $element->setLabel($this->_('Repeat password')); $element->setAttrib('size', 10); @@ -130,21 +132,10 @@ * Process form * ****************/ if ($this->_request->isPost() && $form->isValid($_POST)) { + $user->setPassword($_POST['new_password']); - $data['gsu_id_user'] = $this->session->user_id; - $data['gsu_id_organization'] = $this->session->user_organization_id; - $data['gsu_password'] = $this->escort->passwordHash(null, $_POST['new_password']); - - $this->getModel()->save($data); - - // $data = $_POST; - // $data['name'] = ''; - // $data['type'] = $this->_('raw'); - - // $results = array(); - // $this->_runScript($data, $results); $this->addMessage($this->_('New password is active.')); - $this->afterSaveRoute($this->getRequest()); + $this->_reroute(array($this->getRequest()->getActionKey() => 'edit')); } else { if (isset($_POST['old_password'])) { @@ -162,7 +153,7 @@ $table->setAsFormLayout($form, true, true); $table['tbody'][0][0]->class = 'label'; // Is only one row with formLayout, so all in output fields get class. - if ($links = $this->createMenuLinks()) { + if (! $user->isPasswordResetRequired() && ($links = $this->createMenuLinks())) { $table->tf(); // Add empty cell, no label $linksCell = $table->tf($links); } @@ -185,23 +176,23 @@ */ public function createModel($detailed, $action) { - $model = new Gems_Model_UserModel('staff', 'gems__staff', array('gsu_id_user' => 'gsf_id_user'), 'gsf'); - $model->copyKeys(); + $model = $this->loader->getModels()->getStaffModel(); - $model->set('gsu_login', 'label', $this->_('Login Name')); - $model->set('gsf_email', 'label', $this->_('E-Mail')); - $model->set('gsf_first_name', 'label', $this->_('First name')); - $model->set('gsf_surname_prefix', 'label', $this->_('Surname prefix'), 'description', 'de, van der, \'t, etc...'); - $model->set('gsf_last_name', 'label', $this->_('Last name'), 'required', true); + $model->set('gsf_login', 'label', $this->_('Login Name'), 'elementClass', 'Exhibitor'); + $model->set('gsf_email', 'label', $this->_('E-Mail'), 'size', 30); + $model->set('gsf_first_name', 'label', $this->_('First name')); + $model->set('gsf_surname_prefix', 'label', $this->_('Surname prefix'), 'description', 'de, van der, \'t, etc...'); + $model->set('gsf_last_name', 'label', $this->_('Last name'), 'required', true); + $model->set('gsf_gender', 'label', $this->_('Gender'), 'multiOptions', $this->util->getTranslated()->getGenders(), + 'elementClass', 'Radio', 'separator', ''); + $model->set('gsf_iso_lang', 'label', $this->_('Language'), 'multiOptions', $this->util->getLocalized()->getLanguages()); - $model->set('gsf_gender', 'label', $this->_('Gender'), 'multiOptions', $this->util->getTranslated()->getGenders()); - return $model; } public function editAction() { - $this->getModel()->setFilter(array('gsu_id_user' => $this->session->user_id)); + $this->getModel()->setFilter(array('gsf_id_user' => $this->loader->getCurrentUser()->getUserId())); if ($form = $this->processForm()) { $this->html->h3(sprintf($this->_('Options'), $this->getTopic())); @@ -222,7 +213,7 @@ WHERE glac.glac_name = 'index.login' ORDER BY glua.glua_created DESC LIMIT 10"; - $activity = $this->db->fetchAll($sql, $this->session->user_id); + $activity = $this->db->fetchAll($sql, $this->loader->getCurrentUser()->getUserId()); foreach (array_keys($activity) as $key) { $date = new MUtil_Date($activity[$key]['glua_created']); Modified: trunk/library/classes/Gems/Default/OrganizationAction.php =================================================================== --- trunk/library/classes/Gems/Default/OrganizationAction.php 2011-11-14 12:43:05 UTC (rev 207) +++ trunk/library/classes/Gems/Default/OrganizationAction.php 2011-11-14 12:53:50 UTC (rev 208) @@ -50,7 +50,7 @@ $url = base64_decode($request->getParam('current_uri')); $oldOrgId = $this->session->user_organization_id; - $allowedOrganizations = $this->escort->getAllowedOrganizations(); + $allowedOrganizations = $this->loader->getCurrentUser()->getAllowedOrganizations(); if ($orgId = array_search($org, $allowedOrganizations)) { $this->session->user_organization_id = $orgId; $this->session->user_organization_name = $allowedOrganizations[$orgId]; Modified: trunk/library/classes/Gems/Default/RespondentAction.php =================================================================== --- trunk/library/classes/Gems/Default/RespondentAction.php 2011-11-14 12:43:05 UTC (rev 207) +++ trunk/library/classes/Gems/Default/RespondentAction.php 2011-11-14 12:53:50 UTC (rev 208) @@ -316,26 +316,6 @@ $this->html[] = $form; } - public function getPhysicians() - { - $session = new Zend_Session_Namespace('Pulse_' . __FILE__); - - if (! isset($session->physicians)) { - $organizationId = $this->escort->getCurrentOrganization(); - - $values = $this->db->fetchPairs(" - SELECT gsf_id_user, - CONCAT(gsf_last_name, ', ', COALESCE(CONCAT(gsf_first_name, ' '), ''), COALESCE(gsf_surname_prefix, '')) AS name - FROM (gems__users INNER JOIN gems__staff ON gsu_id_user = gsf_id_user) INNER JOIN gems__groups ON gsf_id_primary_group = ggp_id_group - WHERE gsu_active=1 AND gsu_id_organization = ? AND ggp_role = 'physician' - ORDER BY 2", $organizationId); - - $session->physicians = $values; - } - - return $this->util->getTranslated()->getEmptyDropdownArray() + $session->physicians; - } - public function getMenuParameter($name, $default) { switch ($name) { Modified: trunk/library/classes/Gems/Default/StaffAction.php =================================================================== --- trunk/library/classes/Gems/Default/StaffAction.php 2011-11-14 12:43:05 UTC (rev 207) +++ trunk/library/classes/Gems/Default/StaffAction.php 2011-11-14 12:53:50 UTC (rev 208) @@ -44,7 +44,9 @@ */ class Gems_Default_StaffAction extends Gems_Controller_BrowseEditAction { - public $filterStandard = array('gsu_active' => 1); + public $defaultStaffDefinition = Gems_User_UserLoader::USER_STAFF; + + public $filterStandard = array('gsf_active' => 1); public $sortKey = array('name' => SORT_ASC); protected $_instanceId; @@ -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, 'getValueHashForModel')); + 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('gsu_password', 'description', $this->_('Enter only when changing')); - $model->setSaveWhenNotNull('gsu_password'); + } elseif ($passwordField) { + $model->set($passwordField, 'description', $this->_('Enter only when changing')); + $model->setSaveWhenNotNull($passwordField); } - $model->setOnSave('gsu_password', array($this->escort, 'passwordHash')); $ucfirst = new Zend_Filter_Callback('ucfirst'); - $bridge->addHidden( 'gsu_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('gsu_id_organization')); - $bridge->addSelect('gsu_id_organization'); + $bridge->addHiddenMulti($model->getKeyCopyName('gsf_id_organization')); + $bridge->addSelect('gsf_id_organization'); } else { - $bridge->addExhibitor('gsu_id_organization'); + $bridge->addExhibitor('gsf_id_organization'); } - $bridge->addPassword('gsu_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,15 +162,15 @@ public function afterFormLoad(array &$data, $isNew) { - if (array_key_exists('gsu_login', $data)) { - $this->_instanceId = $data['gsu_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']; $groups = $this->db->fetchPairs($sql); if (! ($this->escort->hasPrivilege('pr.staff.edit.all') || - $data['gsu_id_organization'] == $this->escort->getCurrentOrganization())) { + $data['gsf_id_organization'] == $this->escort->getCurrentOrganization())) { throw new Zend_Exception($this->_('You are not allowed to edit this staff member.')); } } @@ -169,21 +190,17 @@ { // MUtil_Model::$verbose = true; - $model = new Gems_Model_UserModel('staff', 'gems__staff', array('gsu_id_user' => 'gsf_id_user'), 'gsf'); - if ($detailed) { - $model->copyKeys(); - } - //$model->resetOrder(); + $model = $this->loader->getModels()->getStaffModel(); - $model->set('gsu_login', 'label', $this->_('Login')); + $model->set('gsf_login', 'label', $this->_('Login')); $model->set('name', 'label', $this->_('Name'), 'column_expression', "CONCAT(COALESCE(CONCAT(gsf_last_name, ', '), '-, '), COALESCE(CONCAT(gsf_first_name, ' '), ''), COALESCE(gsf_surname_prefix, ''))"); $model->set('gsf_email', 'label', $this->_('E-Mail'), 'itemDisplay', 'MUtil_Html_AElement::ifmail'); if ($detailed || $this->escort->hasPrivilege('pr.staff.see.all')) { - $this->menu->getParameterSource()->offsetSet('gsu_id_organization', $this->escort->getCurrentOrganization()); + $this->menu->getParameterSource()->offsetSet('gsf_id_organization', $this->escort->getCurrentOrganization()); - $model->set('gsu_id_organization', 'label', $this->_('Organization'), + $model->set('gsf_id_organization', 'label', $this->_('Organization'), 'multiOptions', $this->util->getDbLookup()->getOrganizations(), 'default', $this->escort->getCurrentOrganization()); } @@ -192,12 +209,12 @@ $model->set('gsf_gender', 'label', $this->_('Gender'), 'multiOptions', $this->util->getTranslated()->getGenders()); if ($detailed) { - $model->set('gsu_user_class', 'default', 'StaffUser'); + $model->set('gul_user_class', 'default', $this->defaultStaffDefinition); ... [truncated message content] |