From: <gem...@li...> - 2011-09-22 14:13:38
|
Revision: 70 http://gemstracker.svn.sourceforge.net/gemstracker/?rev=70&view=rev Author: mennodekker Date: 2011-09-22 14:13:27 +0000 (Thu, 22 Sep 2011) Log Message: ----------- Fixed Spss export (forgot to rename zsd to gems) Fixed Excel export (first row should not be formatted) Made bulk email a separate privilege from normal mail Fixed a problem with tableform (not used yet) and File elements Modified Paths: -------------- trunk/library/classes/Gems/Export/Spss.php trunk/library/classes/Gems/Form/TableForm.php trunk/library/classes/Gems/Menu/MenuAbstract.php trunk/library/classes/Gems/View/Helper/Excel.php Modified: trunk/library/classes/Gems/Export/Spss.php =================================================================== --- trunk/library/classes/Gems/Export/Spss.php 2011-09-22 09:31:24 UTC (rev 69) +++ trunk/library/classes/Gems/Export/Spss.php 2011-09-22 14:13:27 UTC (rev 70) @@ -205,7 +205,7 @@ //We should create a model with the transformations we need //think of date translations, numers and strings $answerRow = reset($answers); - $spssModel = new Zsd_Export_ExportModel(); + $spssModel = new Gems_Export_ExportModel(); foreach($answerRow as $key => $value) { $options = array(); $type = $answerModel->get($key,'type'); Modified: trunk/library/classes/Gems/Form/TableForm.php =================================================================== --- trunk/library/classes/Gems/Form/TableForm.php 2011-09-22 09:31:24 UTC (rev 69) +++ trunk/library/classes/Gems/Form/TableForm.php 2011-09-22 14:13:27 UTC (rev 70) @@ -69,6 +69,8 @@ if (isset($decorators['Zend_Form_Decorator_ViewHelper'])) { $dec1 = $decorators['Zend_Form_Decorator_ViewHelper']; + } elseif (isset($decorators['Zend_Form_Decorator_File'])) { + $dec1 = $decorators['Zend_Form_Decorator_File']; } else { foreach($decorators as $name=>$decorator) { if (substr($name, 0, 5) == 'ZendX') { Modified: trunk/library/classes/Gems/Menu/MenuAbstract.php =================================================================== --- trunk/library/classes/Gems/Menu/MenuAbstract.php 2011-09-22 09:31:24 UTC (rev 69) +++ trunk/library/classes/Gems/Menu/MenuAbstract.php 2011-09-22 14:13:27 UTC (rev 70) @@ -253,7 +253,7 @@ foreach ($plans as $plan) { $plan->addAutofilterAction(); - $plan->addAction($this->_('Bulk mail'), 'pr.token.mail', 'email', array('routeReset' => false)); + $plan->addAction($this->_('Bulk mail'), 'pr.token.bulkmail', 'email', array('routeReset' => false)); $plan->addExcelAction(); } Modified: trunk/library/classes/Gems/View/Helper/Excel.php =================================================================== --- trunk/library/classes/Gems/View/Helper/Excel.php 2011-09-22 09:31:24 UTC (rev 69) +++ trunk/library/classes/Gems/View/Helper/Excel.php 2011-09-22 14:13:27 UTC (rev 70) @@ -3,7 +3,7 @@ /** * Copyright (c) 2011, Erasmus MC * All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright @@ -14,7 +14,7 @@ * * Neither the name of Erasmus MC nor the * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE @@ -29,7 +29,7 @@ /** * Outputs an array of arrays (or a Zend_Db_Table_Rowset) as a table - * + * * The first 'record' is rendered bold, being the header for the table * * @category Gems @@ -49,25 +49,35 @@ Zend_Controller_Front::getInstance()->unregisterPlugin('ZFDebug_Controller_Plugin_Debug'); } catch (Exception $e) {} $this->view->layout()->setLayout('excel'); + if ($rowset instanceof Gems_FormattedData) { + $rowset->setFormatted(false); + } $rowcnt = 0; foreach ($rowset as $row) { - if ($row instanceof Zend_Db_Table_Row) $row = $row->toArray(); - if (!is_array($row)) $row = (array) $row; + if ($row instanceof Zend_Db_Table_Row) { + $row = $row->toArray(); + } + if (!is_array($row)) { + $row = (array) $row; + } if ($rowcnt == 0) { //Only for the first row: output headers $output = "<table>\r\n"; $output .= "\t<thead>\r\n"; $output .= "\t\t<tr>\r\n"; foreach ($row as $name => $value) { - $output .= "\t\t\t<th>$value</th>\r\n"; + $output .= "\t\t\t<th>$value</th>\r\n"; } $output .= "\t\t</tr>\r\n"; $output .= "\t</thead>\r\n"; $output .= "\t<tbody>\r\n"; - } else { - $output .= "\t\t<tr>\r\n"; + if ($rowset instanceof Gems_FormattedData) { + $rowset->setFormatted(true); + } + } else { + $output .= "\t\t<tr>\r\n"; foreach ($row as $name => $value) { - $output .= "\t\t\t<td>$value</td>\r\n"; + $output .= "\t\t\t<td>$value</td>\r\n"; } $output .= "\t\t</tr>\r\n"; } @@ -76,7 +86,7 @@ if (isset($output)) { $output .= "\t</tbody>\r\n"; $output .= "</table>\r\n"; - return $output; + return $output; } else { return null; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <gem...@li...> - 2011-09-27 10:38:17
|
Revision: 76 http://gemstracker.svn.sourceforge.net/gemstracker/?rev=76&view=rev Author: mennodekker Date: 2011-09-27 10:38:07 +0000 (Tue, 27 Sep 2011) Log Message: ----------- Append class attrib to the displaygroup for better css control Removed escaping from labels for better styling Modified Paths: -------------- trunk/library/classes/Gems/Form/TableForm.php trunk/library/classes/Gems/TabForm.php Modified: trunk/library/classes/Gems/Form/TableForm.php =================================================================== --- trunk/library/classes/Gems/Form/TableForm.php 2011-09-26 16:29:02 UTC (rev 75) +++ trunk/library/classes/Gems/Form/TableForm.php 2011-09-27 10:38:07 UTC (rev 76) @@ -118,9 +118,9 @@ array(array('data' => 'HtmlTag'), array('tag' => 'td', 'class' => 'element')), array(array('labelCellClose' => 'HtmlTag'), array('tag' => 'td', 'placement'=> Zend_Form_Decorator_Abstract::PREPEND, 'closeOnly'=>true)), array('Tooltip'), - array('Description', array('tag'=>'label', 'class'=>'optional', 'placement'=> Zend_Form_Decorator_Abstract::PREPEND)), + array('Description', array('tag'=>'label', 'class'=>'optional', 'placement'=> Zend_Form_Decorator_Abstract::PREPEND, 'escape'=>false)), array(array('labelCellOpen' => 'HtmlTag'), array('tag' => 'td', 'class'=>'label', 'placement'=> Zend_Form_Decorator_Abstract::PREPEND, 'openOnly'=>true)), - array(array('row' => 'HtmlTag'), array('tag' => 'tr', 'class' => $this->_alternate . ' ' . $group->getName())) + array(array('row' => 'HtmlTag'), array('tag' => 'tr', 'class' => $this->_alternate . ' ' . $group->getName(). ' ' . $group->getAttrib('class'))) )); //Now add the right decorators to the elements @@ -136,7 +136,7 @@ //If we want to see the individual fields labels, do so: if ($group->getAttrib('showLabels')===true) { - $decorators[] = 'Label'; + $decorators[] = array('Label', array('escape'=>false)); } //Apply final class and id to allow for custom styling @@ -177,7 +177,7 @@ array('Description', array('class'=>'description')), 'Errors', array('Tooltip'), - array('Label'), + array('Label', array('escape'=>false)), array(array('labelCell' => 'HtmlTag'), array('tag' => 'td', 'class'=>'label', 'colspan'=>2)), array(array('row' => 'HtmlTag'), array('tag' => 'tr', 'class' => $element->getName())) ); @@ -200,7 +200,7 @@ array(array('data' => 'HtmlTag'), array('tag' => 'td', 'class' => 'element')), array(array('labelCellClose' => 'HtmlTag'), array('tag' => 'td', 'placement'=> Zend_Form_Decorator_Abstract::PREPEND, 'closeOnly'=>true)), array('Tooltip'), - array('Label'), + array('Label', array('escape'=>false)), array(array('labelCellOpen' => 'HtmlTag'), array('tag' => 'td', 'class'=>'label', 'placement'=> Zend_Form_Decorator_Abstract::PREPEND, 'openOnly'=>true)), array(array('row' => 'HtmlTag'), array('tag' => 'tr', 'class' => $element->getName())) ); Modified: trunk/library/classes/Gems/TabForm.php =================================================================== --- trunk/library/classes/Gems/TabForm.php 2011-09-26 16:29:02 UTC (rev 75) +++ trunk/library/classes/Gems/TabForm.php 2011-09-27 10:38:07 UTC (rev 76) @@ -226,7 +226,7 @@ //Retrieve it and set decorators $group = $this->getDisplayGroup($name); $group->setDecorators( array('FormElements', - array('HtmlTag', array('tag' => 'div', 'class' => $group->getName())) + array('HtmlTag', array('tag' => 'div', 'class' => $group->getName(). ' ' . $group->getAttrib('class'))) )); } } \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <gem...@li...> - 2011-10-11 12:25:40
|
Revision: 87 http://gemstracker.svn.sourceforge.net/gemstracker/?rev=87&view=rev Author: matijsdejong Date: 2011-10-11 12:25:29 +0000 (Tue, 11 Oct 2011) Log Message: ----------- Menu reorganized as per ticket #5 Modified Paths: -------------- trunk/library/classes/Gems/Default/ProjectInformationAction.php trunk/library/classes/Gems/Log.php trunk/library/classes/Gems/Menu/MenuAbstract.php trunk/library/classes/Gems/Menu.php Modified: trunk/library/classes/Gems/Default/ProjectInformationAction.php =================================================================== --- trunk/library/classes/Gems/Default/ProjectInformationAction.php 2011-10-11 11:35:46 UTC (rev 86) +++ trunk/library/classes/Gems/Default/ProjectInformationAction.php 2011-10-11 12:25:29 UTC (rev 87) @@ -54,46 +54,58 @@ $this->html[] = $table; } - public function changelogAction() + protected function _showText($caption, $log_file, $empty_label = null) { - $this->html->h2($this->_('Changelog')); + $this->html->h2($caption); - $log_path = APPLICATION_PATH; - $log_file = $log_path . '/changelog.txt'; - - if ((1 == $this->_getParam(MUtil_Model::REQUEST_ID)) && file_exists($log_file)) { + if ($empty_label && (1 == $this->_getParam(MUtil_Model::REQUEST_ID)) && file_exists($log_file)) { unlink($log_file); } if (file_exists($log_file)) { - $this->html->pre(trim(file_get_contents($log_file)), array('class' => 'logFile')); + $content = trim(file_get_contents($log_file)); + + if ($content) { + $error = false; + } else { + $error = $this->_('empty file'); + } } else { - $this->html->pInfo(sprintf($this->_('No changelog found. Place one in %s.'), $log_file)); + $content = null; + $error = $this->_('file not found'); } - } - public function errorsAction() - { - $this->html->h2($this->_('Logged errors')); + if ($empty_label) { + $buttons = $this->html->buttonDiv(); + if ($error) { + $buttons->actionDisabled($empty_label); + } else { + $buttons->actionLink(array(MUtil_Model::REQUEST_ID => 1), $empty_label); + } + } - $log_path = GEMS_ROOT_DIR . '/var/logs'; - $log_file = $log_path . '/errors.log'; + if ($error) { + $this->html->pre($error, array('class' => 'disabled logFile')); + } else { + $this->html->pre($content, array('class' => 'logFile')); + } - if ((1 == $this->_getParam(MUtil_Model::REQUEST_ID)) && file_exists($log_file)) { - unlink($log_file); + if ($empty_label) { + // Buttons at both bottom and top. + $this->html[] = $buttons; } + } - if (file_exists($log_file)) { - $buttons = $this->html->buttonDiv(); - $buttons->actionLink(array(MUtil_Model::REQUEST_ID => 1), $this->_('Empty logfile')); + public function changelogAction() + { + $this->_showText($this->_('Changelog'), APPLICATION_PATH . '/changelog.txt'); + } - $this->html->pre(trim(file_get_contents($log_file)), array('class' => 'logFile')); + public function errorsAction() + { + $this->logger->shutdown(); - $this->html[] = $buttons; - } else { - $this->html->pInfo($this->_('No logged errors found.')); - $this->html->buttonDiv()->actionDisabled($this->_('Empty logfile')); - } + $this->_showText($this->_('Logged errors'), GEMS_ROOT_DIR . '/var/logs/errors.log', $this->_('Empty logfile')); } public function indexAction() Modified: trunk/library/classes/Gems/Log.php =================================================================== --- trunk/library/classes/Gems/Log.php 2011-10-11 11:35:46 UTC (rev 86) +++ trunk/library/classes/Gems/Log.php 2011-10-11 12:25:29 UTC (rev 87) @@ -3,7 +3,7 @@ /** * Copyright (c) 2011, Erasmus MC * All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright @@ -14,7 +14,7 @@ * * Neither the name of Erasmus MC nor the * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE @@ -25,7 +25,7 @@ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * + * * @version $Id$ * @package Gems * @subpackage Log @@ -46,7 +46,7 @@ * @var Gems_Log */ private static $_instance = null; - + /** * Returns static instance * @return Gems_Log @@ -56,7 +56,7 @@ if (empty(self::$_instance)) { self::$_instance = new Gems_Log(); } - + return self::$_instance; } @@ -72,17 +72,17 @@ } /** - * Helper method to log exception and (optional) request information + * Helper method to log exception and (optional) request information * @param Exception $exception * @param Zend_Controller_Request_Abstract $request */ public function logError(Exception $exception, Zend_Controller_Request_Abstract $request = null) { $info = array(); - + $info[] = 'Class: ' . get_class($exception); $info[] = 'Message: ' . $this->stripHtml($exception->getMessage()); - + if (($exception instanceof Gems_Exception) && ($text = $exception->getInfo())) { $info[] = 'Info: ' . $this->stripHtml($text); } @@ -98,19 +98,29 @@ $info[] = 'Changed info: ' . $this->stripHtml($text); } } */ - + if (!empty($request)) { $info[] = 'Request Parameters:'; foreach ($request->getParams() as $key => $value) { $info[] = $key . ' => ' . $value; } } - + $info[] = 'Stack trace:'; $info[] = $exception->getTraceAsString(); - + foreach ($info as $line) { $this->log($line, Zend_Log::ERR); } } + + /** + * Closes all writers. + */ + public function shutdown() + { + foreach ($this->_writers as $writer) { + $writer->shutdown(); + } + } } \ No newline at end of file Modified: trunk/library/classes/Gems/Menu/MenuAbstract.php =================================================================== --- trunk/library/classes/Gems/Menu/MenuAbstract.php 2011-10-11 11:35:46 UTC (rev 86) +++ trunk/library/classes/Gems/Menu/MenuAbstract.php 2011-10-11 12:25:29 UTC (rev 87) @@ -1,6 +1,5 @@ <?php - /** * Copyright (c) 2011, Erasmus MC * All rights reserved. @@ -37,6 +36,9 @@ */ /** + * Base class for building a menu / button structure where the display of items is dependent + * on both privileges and the availability of parameter information, + * e.g. data to fill an 'id' parameter. * * @package Gems * @subpackage Menu @@ -140,8 +142,25 @@ } /** + * Add a sub item to this item. * - * @param <type> $args_array + * The argumenets can be any of those used for Zend_Navigation_Page as well as some Gems specials.<ul> + * <li>'action' The name of the action.</li> + * <li>'allowed' Is the user allowed to access this menu item. Is checked against ACL using 'privilige'.</li> + * <li>'button_only' Never in the menu, only shown as a button by the program.</li> + * <li>'class' Display class for the menu link.</li> + * <li>'controller' What controller to use.</li> + * <li>'icon' Icon to display with the label.</li> + * <li>'label' The label to display for the menu item.</li> + * <li>'privilege' The privilege needed to choose the item.</li> + * <li>'target' Optional target attribute for the link.</li> + * <li>'type' Optional content type for the link</li> + * <li>'visible' Is the item visible. Is checked against ACL using 'privilige'.</li> + * </ul> + * + * @see Zend_Navigation_Page + * + * @param array $args_array MUtil_Ra::args array with defaults 'visible' and 'allowed' true. * @return Gems_Menu_SubMenuItem */ protected function add($args_array) @@ -198,7 +217,14 @@ return $this->addPage($label, $privilege, $controller, $action, $other); } - public function addMailSetupPage($label) + /** + * Add a Mail menu tree to the menu + * + * @param string $label + * @param array $other + * @return Gems_Menu_SubMenuItem + */ + public function addMailSetupMenu($label) { $setup = $this->addContainer($label); @@ -226,8 +252,7 @@ * @param string $privilege The privilege for the item * @param string $controller What controller to use * @param string $action The name of the action - * @param array $other Array of extra options for this item - * + * @param array $other Array of extra options for this item, e.g. 'visible', 'allowed', 'class', 'icon', 'target', 'type', 'button_only' * @return Gems_Menu_SubMenuItem */ public function addPage($label, $privilege, $controller, $action = 'index', array $other = array()) @@ -260,6 +285,33 @@ return $infoPage; } + /** + * Add pages that show the user technical information about the installation + * in the project. + * + * @param string $label + * @param array $other + * @return Gems_Menu_SubMenuItem + */ + public function addProjectInfoPage($label) + { + $page = $this->addPage($label, 'pr.project-information', 'project-information'); + $page->addAction($this->_('Errors'), null, 'errors'); + $page->addAction($this->_('PHP'), null, 'php'); + $page->addAction($this->_('Project'), null, 'project'); + $page->addAction($this->_('Session'), null, 'session'); + + return $page; + } + + /** + * Add pages that show the user an overview of the tracks / surveys used + * in the project. + * + * @param string $label + * @param array $other + * @return Gems_Menu_SubMenuItem + */ public function addProjectPage($label) { if ($this->escort instanceof Gems_Project_Tracks_SingleTrackInterface) { @@ -300,6 +352,13 @@ return $infoPage; } + /** + * Add a staff browse edit page to the menu, + * + * @param string $label + * @param array $other + * @return Gems_Menu_SubMenuItem + */ public function addStaffPage($label, array $other = array()) { $page = $this->addPage($label, 'pr.staff', 'staff', 'index', $other); @@ -317,6 +376,73 @@ return $page; } + + /** + * Add a Trackbuilder menu tree to the menu + * + * @param string $label + * @param array $other + * @return Gems_Menu_SubMenuItem + */ + public function addTrackBuilderMenu($label, array $other = array()) + { + $setup = $this->addContainer($label); + + // SURVEY SOURCES CONTROLLER + $page = $setup->addBrowsePage($this->_('Survey Sources'), 'pr.source', 'source'); + $page->addDeleteAction(); + $page->addAction($this->_('Check status'), null, 'ping')->addParameters(MUtil_Model::REQUEST_ID); + $page->addAction($this->_('Synchronize surveys'), 'pr.source.synchronize', 'synchronize')->addParameters(MUtil_Model::REQUEST_ID); + $page->addAction($this->_('Check answers'), 'pr.source.check-answers', 'check')->addParameters(MUtil_Model::REQUEST_ID); + $page->addAction($this->_('Synchronize all surveys'), 'pr.source.synchronize-all', 'synchronize-all'); + $page->addAction($this->_('Check all answers'), 'pr.source.check-answers-all', 'check-all'); + + // SURVEY MAINTENANCE CONTROLLER + $page = $setup->addPage($this->_('Surveys'), 'pr.survey-maintenance', 'survey-maintenance'); + $page->addEditAction(); + $page->addShowAction(); + $page->addPdfButton($this->_('PDF'), 'pr.survey-maintenance') + ->addParameters(MUtil_Model::REQUEST_ID) + ->setParameterFilter('gsu_has_pdf', 1); + $page->addAction($this->_('Check answers'), 'pr.survey-maintenance.check', 'check')->addParameters(MUtil_Model::REQUEST_ID); + $page->addAction($this->_('Check all answers'), 'pr.survey-maintenance.check-all', 'check-all'); + + $page->addAutofilterAction(); + + // TRACK MAINTENANCE CONTROLLER + $page = $setup->addBrowsePage($this->_('Tracks'), 'pr.track-maintenance', 'track-maintenance'); + + // Fields + $fpage = $page->addPage($this->_('Fields'), 'pr.track-maintenance', 'track-fields')->addNamedParameters(MUtil_Model::REQUEST_ID, 'gtf_id_track'); + $fpage->addAutofilterAction(); + $fpage->addCreateAction('pr.track-maintenance.create')->addNamedParameters(MUtil_Model::REQUEST_ID, 'gtf_id_track'); + $fpage->addShowAction()->addNamedParameters(MUtil_Model::REQUEST_ID, 'gtf_id_track', 'fid', 'gtf_id_field'); + $fpage->addEditAction('pr.track-maintenance.edit')->addNamedParameters('fid', 'gtf_id_field', MUtil_Model::REQUEST_ID, 'gtf_id_track'); + + // Standard tracks + $fpage = $page->addPage($this->_('Rounds'), 'pr.track-maintenance', 'track-rounds') + ->addNamedParameters(MUtil_Model::REQUEST_ID, 'gro_id_track') + ->setParameterFilter('gtr_track_type', 'T'); + $fpage->addAutofilterAction(); + $fpage->addCreateAction('pr.track-maintenance.create')->addNamedParameters(MUtil_Model::REQUEST_ID, 'gro_id_track'); + $fpage->addShowAction()->addNamedParameters(MUtil_Model::REQUEST_ID, 'gro_id_track', Gems_Model::ROUND_ID, 'gro_id_round'); + $fpage->addEditAction('pr.track-maintenance.edit')->addNamedParameters(Gems_Model::ROUND_ID, 'gro_id_round', MUtil_Model::REQUEST_ID, 'gro_id_track'); + + // Single survey tracks + $fpage = $page->addPage($this->_('Round'), 'pr.track-maintenance', 'track-round', 'show') + ->addNamedParameters(MUtil_Model::REQUEST_ID, 'gro_id_track') + ->setParameterFilter('gtr_track_type', 'S'); + $fpage->addEditAction('pr.track-maintenance.edit') + ->addNamedParameters(MUtil_Model::REQUEST_ID, 'gro_id_track'); + + $page->addAction($this->_('Check assignments'), 'pr.track-maintenance.check', 'check-track') + ->addParameters(MUtil_Model::REQUEST_ID); + + $page->addAction($this->_('Check all assignments'), 'pr.track-maintenance.check-all', 'check-all'); + + return $setup; + } + public function applyAcl(Zend_Acl $acl, $userRole) { if ($this->_subItems) { Modified: trunk/library/classes/Gems/Menu.php =================================================================== --- trunk/library/classes/Gems/Menu.php 2011-10-11 11:35:46 UTC (rev 86) +++ trunk/library/classes/Gems/Menu.php 2011-10-11 12:25:29 UTC (rev 87) @@ -163,6 +163,8 @@ { $setup = $this->addContainer($label); + $setup->addProjectInfoPage($this->_('Project setup')); + // DATABASE CONTROLLER $page = $setup->addPage($this->_('Database'), 'pr.database', 'database'); $page->addAutofilterAction(); @@ -183,89 +185,27 @@ } $page->addAction($this->_('Run SQL'), 'pr.database.execute', 'run-sql'); - // PROJECT - $page = $setup->addPage($this->_('Project setup'), 'pr.project-information', 'project-information'); - $page->addAction($this->_('Errors'), null, 'errors'); - $page->addAction($this->_('PHP'), null, 'php'); - $page->addAction($this->_('Project'), null, 'project'); - $page->addAction($this->_('Session'), null, 'session'); + // RECEPTION CODE CONTROLLER + $page->addBrowsePage($this->_('Reception codes'), 'pr.reception', 'reception'); - // COUNTRIES CONTROLLER - // $setup->addBrowsePage($this->_('Countries'), 'pr.country', 'country'); - - // LANGUAGE CONTROLLER - // $setup->addPage($this->_('Languages'), 'pr.language', 'language'); - // CONSENT CONTROLLER - $setup->addBrowsePage($this->_('Consents'), 'pr.consent', 'consent'); + $page->addBrowsePage($this->_('Consents'), 'pr.consent', 'consent'); - // ORGANIZATIONS CONTROLLER - $setup->addBrowsePage($this->_('Organizations'),'pr.organization', 'organization'); - - // GROUPS CONTROLLER - $setup->addBrowsePage($this->_('Groups'), 'pr.group', 'group'); - // ROLES CONTROLLER $page = $setup->addBrowsePage($this->_('Roles'), 'pr.role', 'role'); $page->addAction($this->_('ACL'), null, 'acl'); $page->addAction($this->_('Assigned'), null, 'overview'); $page->addAction($this->_('Privileges'), null, 'privilege'); - // RECEPTION CODE CONTROLLER - $setup->addBrowsePage($this->_('Reception codes'), 'pr.reception', 'reception'); + // GROUPS CONTROLLER + $setup->addBrowsePage($this->_('Groups'), 'pr.group', 'group'); - // SURVEY SOURCES CONTROLLER - $page = $setup->addBrowsePage($this->_('Survey Sources'), 'pr.source', 'source'); - $page->addDeleteAction(); - $page->addAction($this->_('Check status'), null, 'ping')->addParameters(MUtil_Model::REQUEST_ID); - $page->addAction($this->_('Synchronize surveys'), 'pr.source.synchronize', 'synchronize')->addParameters(MUtil_Model::REQUEST_ID); - $page->addAction($this->_('Check answers'), 'pr.source.check-answers', 'check')->addParameters(MUtil_Model::REQUEST_ID); - $page->addAction($this->_('Synchronize all surveys'), 'pr.source.synchronize-all', 'synchronize-all'); - $page->addAction($this->_('Check all answers'), 'pr.source.check-answers-all', 'check-all'); + // ORGANIZATIONS CONTROLLER + $setup->addBrowsePage($this->_('Organizations'),'pr.organization', 'organization'); - // SURVEY MAINTENANCE CONTROLLER - $page = $setup->addPage($this->_('Surveys'), 'pr.survey-maintenance', 'survey-maintenance'); - $page->addEditAction(); - $page->addShowAction(); - $page->addPdfButton($this->_('PDF'), 'pr.survey-maintenance') - ->addParameters(MUtil_Model::REQUEST_ID) - ->setParameterFilter('gsu_has_pdf', 1); - $page->addAction($this->_('Check answers'), 'pr.survey-maintenance.check', 'check')->addParameters(MUtil_Model::REQUEST_ID); - $page->addAction($this->_('Check all answers'), 'pr.survey-maintenance.check-all', 'check-all'); + // STAFF CONTROLLER + $setup->addStaffPage($this->_('Staff')); - $page->addAutofilterAction(); - - // TRACK MAINTENANCE CONTROLLER - $page = $setup->addBrowsePage($this->_('Tracks'), 'pr.track-maintenance', 'track-maintenance'); - - // Fields - $fpage = $page->addPage($this->_('Fields'), 'pr.track-maintenance', 'track-fields')->addNamedParameters(MUtil_Model::REQUEST_ID, 'gtf_id_track'); - $fpage->addAutofilterAction(); - $fpage->addCreateAction('pr.track-maintenance.create')->addNamedParameters(MUtil_Model::REQUEST_ID, 'gtf_id_track'); - $fpage->addShowAction()->addNamedParameters(MUtil_Model::REQUEST_ID, 'gtf_id_track', 'fid', 'gtf_id_field'); - $fpage->addEditAction('pr.track-maintenance.edit')->addNamedParameters('fid', 'gtf_id_field', MUtil_Model::REQUEST_ID, 'gtf_id_track'); - - // Standard tracks - $fpage = $page->addPage($this->_('Rounds'), 'pr.track-maintenance', 'track-rounds') - ->addNamedParameters(MUtil_Model::REQUEST_ID, 'gro_id_track') - ->setParameterFilter('gtr_track_type', 'T'); - $fpage->addAutofilterAction(); - $fpage->addCreateAction('pr.track-maintenance.create')->addNamedParameters(MUtil_Model::REQUEST_ID, 'gro_id_track'); - $fpage->addShowAction()->addNamedParameters(MUtil_Model::REQUEST_ID, 'gro_id_track', Gems_Model::ROUND_ID, 'gro_id_round'); - $fpage->addEditAction('pr.track-maintenance.edit')->addNamedParameters(Gems_Model::ROUND_ID, 'gro_id_round', MUtil_Model::REQUEST_ID, 'gro_id_track'); - - // Single survey tracks - $fpage = $page->addPage($this->_('Round'), 'pr.track-maintenance', 'track-round', 'show') - ->addNamedParameters(MUtil_Model::REQUEST_ID, 'gro_id_track') - ->setParameterFilter('gtr_track_type', 'S'); - $fpage->addEditAction('pr.track-maintenance.edit') - ->addNamedParameters(MUtil_Model::REQUEST_ID, 'gro_id_track'); - - $page->addAction($this->_('Check assignments'), 'pr.track-maintenance.check', 'check-track') - ->addParameters(MUtil_Model::REQUEST_ID); - - $page->addAction($this->_('Check all assignments'), 'pr.track-maintenance.check-all', 'check-all'); - // LOG CONTROLLER $page = $setup->addPage($this->_('Logging'), 'pr.log', 'log', 'index'); $page->addAutofilterAction(); @@ -568,27 +508,30 @@ public function loadDefaultMenu() { // MAIN RESPONDENTS ITEM - $this->addRespondentPage($this->escort->_('Respondents')); + $this->addRespondentPage($this->_('Respondents')); // MAIN PLANNING ITEM - $this->addPlanPage($this->escort->_('Overview')); + $this->addPlanPage($this->_('Overview')); // MAIN RESULTS ITEM // $menu->addPage($this->_('Results'), 'pr.result', 'result'); // $menu->addPage($this->_('Invite'), 'pr.invitation', 'invitation'); // PROJECT INFO - $this->addProjectPage($this->escort->_('Project')); + $this->addProjectPage($this->_('Project')); // MAIN STAFF ITEM - $this->addStaffPage($this->escort->_('Staff'), array('order'=>40)); + $this->addStaffPage($this->_('Staff'), array('order'=>40)); // SETUP CONTAINER - $this->addGemsSetupContainer($this->escort->_('Setup')); + $this->addGemsSetupContainer($this->_('Setup')); // MAIL CONTAINER - $this->addMailSetupPage($this->escort->_('Mail')); - + $this->addMailSetupMenu($this->_('Mail')); + + // TRACK BUILDER + $this->addTrackBuilderMenu($this->_('Track Builder')); + // EXPORT DATA $this->addContainer('Export data', 'pr.export', array('controller'=>'export', 'action'=>'index')); @@ -596,7 +539,7 @@ $this->addLogonOffToken(); // CONTACT MENU - $this->addContactPage($this->escort->_('Contact')); + $this->addContactPage($this->_('Contact')); // Privileges not associated with menu item $this->addHiddenPrivilige('pr.plan.choose-org'); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <gem...@li...> - 2011-10-12 07:55:37
|
Revision: 92 http://gemstracker.svn.sourceforge.net/gemstracker/?rev=92&view=rev Author: mennodekker Date: 2011-10-12 07:55:30 +0000 (Wed, 12 Oct 2011) Log Message: ----------- Menu updates: -Removed duplicate 'staff' item that caused jumping branches when clicked from within setup item -Removed 'acl' as it provides no useful information not mentioned elsewhere Modified Paths: -------------- trunk/library/classes/Gems/Default/RoleAction.php trunk/library/classes/Gems/Menu.php Modified: trunk/library/classes/Gems/Default/RoleAction.php =================================================================== --- trunk/library/classes/Gems/Default/RoleAction.php 2011-10-11 16:24:36 UTC (rev 91) +++ trunk/library/classes/Gems/Default/RoleAction.php 2011-10-12 07:55:30 UTC (rev 92) @@ -53,12 +53,6 @@ $this->html[] = $table; } - public function aclAction() - { - $this->html->h2($this->_('Access Control Lists')); - $this->_showTable($this->_('ACL\'s'), $this->acl->getRoles()); - } - /** * Adds elements from the model to the bridge that creates the form. * Modified: trunk/library/classes/Gems/Menu.php =================================================================== --- trunk/library/classes/Gems/Menu.php 2011-10-11 16:24:36 UTC (rev 91) +++ trunk/library/classes/Gems/Menu.php 2011-10-12 07:55:30 UTC (rev 92) @@ -193,7 +193,6 @@ // ROLES CONTROLLER $page = $setup->addBrowsePage($this->_('Roles'), 'pr.role', 'role'); - $page->addAction($this->_('ACL'), null, 'acl'); $page->addAction($this->_('Assigned'), null, 'overview'); $page->addAction($this->_('Privileges'), null, 'privilege'); @@ -520,9 +519,6 @@ // PROJECT INFO $this->addProjectPage($this->_('Project')); - // MAIN STAFF ITEM - $this->addStaffPage($this->_('Staff'), array('order'=>40)); - // SETUP CONTAINER $this->addGemsSetupContainer($this->_('Setup')); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <gem...@li...> - 2011-10-12 13:14:25
|
Revision: 95 http://gemstracker.svn.sourceforge.net/gemstracker/?rev=95&view=rev Author: mennodekker Date: 2011-10-12 13:14:19 +0000 (Wed, 12 Oct 2011) Log Message: ----------- cleanup exportaction stepengine only looks at rounds when a round id is present Modified Paths: -------------- trunk/library/classes/Gems/Default/ExportAction.php trunk/library/classes/Gems/Tracker/Engine/StepEngineAbstract.php Modified: trunk/library/classes/Gems/Default/ExportAction.php =================================================================== --- trunk/library/classes/Gems/Default/ExportAction.php 2011-10-12 08:40:10 UTC (rev 94) +++ trunk/library/classes/Gems/Default/ExportAction.php 2011-10-12 13:14:19 UTC (rev 95) @@ -96,7 +96,7 @@ //Now add all onload actions to make the form still work $actions = $this->view->jQuery()->getOnLoadActions(); $this->html->raw('<script type="text/javascript">'); - foreach($actions as $action) { + foreach ($actions as $action) { $this->html->raw($action); } $this->html->raw('</script>'); @@ -161,11 +161,9 @@ //then remove it or make it more efficient unset($data['records']); if (isset($data['sid'])) { - $gsu_id = intval($data['sid']); - $survey = $this->loader->getTracker()->getSurvey($gsu_id); - - $filter = $this->_getFilter($data); - $answers = $survey->getRawTokenAnswerRows($filter); + $survey = $this->loader->getTracker()->getSurvey(intval($data['sid'])); + $filter = $this->_getFilter($data); + $answers = $survey->getRawTokenAnswerRows($filter); } else { $answers = array(); } @@ -226,11 +224,8 @@ */ public function handleExport($data) { - $language = $this->locale->getLanguage(); - $emptyMsg = sprintf($this->_('No %s found.'), $this->getTopic(0)); - $gsu_id = intval($data['sid']); - $survey = $this->loader->getTracker()->getSurvey($gsu_id); - + $language = $this->locale->getLanguage(); + $survey = $this->loader->getTracker()->getSurvey($data['sid']); $filter = $this->_getFilter($data); $answers = $survey->getRawTokenAnswerRows($filter); $answerModel = $survey->getAnswerModel($language); @@ -239,7 +234,7 @@ $answerModel->set('organizationid', 'multiOptions', $this->escort->getAllowedOrganizations()); if (count($answers) === 0) { - $answers[0] = array('' => $emptyMsg); + $answers[0] = array('' => sprintf($this->_('No %s found.'), $this->getTopic(0))); } if (isset($data['type'])) { Modified: trunk/library/classes/Gems/Tracker/Engine/StepEngineAbstract.php =================================================================== --- trunk/library/classes/Gems/Tracker/Engine/StepEngineAbstract.php 2011-10-12 08:40:10 UTC (rev 94) +++ trunk/library/classes/Gems/Tracker/Engine/StepEngineAbstract.php 2011-10-12 13:14:19 UTC (rev 95) @@ -281,17 +281,20 @@ if ($token->hasSuccesCode() && (! $token->isCompleted())) { - $round = $this->_rounds[$token->getRoundId()]; + //Only process the token when linked to a round + if(array_key_exists($token->getRoundId(), $this->_rounds)) { + $round = $this->_rounds[$token->getRoundId()]; - $fromDate = $this->getValidFromDate($round['grp_valid_after_source'], $round['grp_valid_after_field'], $round['grp_valid_after_id'], $token, $respTrack); - $validFrom = $this->calculateFromDate($fromDate, $round['grp_valid_after_unit'], $round['grp_valid_after_length']); + $fromDate = $this->getValidFromDate($round['grp_valid_after_source'], $round['grp_valid_after_field'], $round['grp_valid_after_id'], $token, $respTrack); + $validFrom = $this->calculateFromDate($fromDate, $round['grp_valid_after_unit'], $round['grp_valid_after_length']); - // MUtil_Echo::track($round, (string) $fromDate, $validFrom); + // MUtil_Echo::track($round, (string) $fromDate, $validFrom); - $untilDate = $this->getValidUntilDate($round['grp_valid_for_source'], $round['grp_valid_for_field'], $round['grp_valid_for_id'], $token, $respTrack, $validFrom); - $validUntil = $this->calculateUntilDate($untilDate, $round['grp_valid_for_unit'], $round['grp_valid_for_length']); + $untilDate = $this->getValidUntilDate($round['grp_valid_for_source'], $round['grp_valid_for_field'], $round['grp_valid_for_id'], $token, $respTrack, $validFrom); + $validUntil = $this->calculateUntilDate($untilDate, $round['grp_valid_for_unit'], $round['grp_valid_for_length']); - $changed += $token->setValidFrom($validFrom, $validUntil, $userId); + $changed += $token->setValidFrom($validFrom, $validUntil, $userId); + } } $token = $token->getNextToken(); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <gem...@li...> - 2011-10-24 11:18:36
|
Revision: 128 http://gemstracker.svn.sourceforge.net/gemstracker/?rev=128&view=rev Author: mennodekker Date: 2011-10-24 11:18:29 +0000 (Mon, 24 Oct 2011) Log Message: ----------- Make super and nologin special roles so super always has all privileges Modified Paths: -------------- trunk/library/classes/Gems/Default/IndexAction.php trunk/library/classes/Gems/Default/RoleAction.php trunk/library/classes/Gems/Roles.php Modified: trunk/library/classes/Gems/Default/IndexAction.php =================================================================== --- trunk/library/classes/Gems/Default/IndexAction.php 2011-10-24 10:20:26 UTC (rev 127) +++ trunk/library/classes/Gems/Default/IndexAction.php 2011-10-24 11:18:29 UTC (rev 128) @@ -61,6 +61,11 @@ public $escort; /** + * @var Gems_Menu + */ + public $menu; + + /** * Extension point, use different auth adapter if needed depending on the provided formValues * * This could be an organization passed in the login-form or something else. @@ -135,8 +140,17 @@ 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)) { - $this->_reroute(array('controller' => 'respondent')); + if ($menuItem = $this->menu->findFirst(array('allowed' => true, 'visible' => true))) { + $redirector = Zend_Controller_Action_HelperBroker::getStaticHelper('redirector'); + $redirector->gotoRoute($menuItem->toRouteUrl($this->getRequest())); + } else { + $this->_reroute(array('controller' => 'respondent', 'action'=>'index')); + } } $form = $this->_getLoginForm(); Modified: trunk/library/classes/Gems/Default/RoleAction.php =================================================================== --- trunk/library/classes/Gems/Default/RoleAction.php 2011-10-24 10:20:26 UTC (rev 127) +++ trunk/library/classes/Gems/Default/RoleAction.php 2011-10-24 11:18:29 UTC (rev 128) @@ -139,6 +139,14 @@ $data['grl_parents'] = implode(',', $data['grl_parents']); } + //Always add nologin privilege to 'nologin' role + if (isset($data['grl_name']) && $data['grl_name'] == 'nologin') { + $data['grl_privileges'][] = 'pr.nologin'; + } elseif (isset($data['grl_name']) && $data['grl_name'] !== 'nologin') { + //Assign islogin to all other roles + $data['grl_privileges'][] = 'pr.islogin'; + } + if (isset($data['grl_privileges'])) { $data['grl_privileges'] = implode(',', $data['grl_privileges']); } @@ -171,6 +179,20 @@ return $model; } + public function editAction() + { + $model = $this->getModel(); + $data = $model->loadFirst(); + + //If we try to edit super, add an error message and reroute + if (isset($data['grl_name']) && $data['grl_name']=='super') { + $this->addMessage($this->_('Editing `super` is not allowed')); + $this->_reroute(array('action'=>'index'), true); + } + + parent::editAction(); + } + public function formatLongLine($line) { if (strlen($line) > 50) { @@ -195,6 +217,10 @@ $privileges = $this->menu->getUsedPrivileges(); asort($privileges); + //don't allow to edit the pr.nologin and pr.islogin privilege + unset($privileges['pr.nologin']); + unset($privileges['pr.islogin']); + return $privileges; } Modified: trunk/library/classes/Gems/Roles.php =================================================================== --- trunk/library/classes/Gems/Roles.php 2011-10-24 10:20:26 UTC (rev 127) +++ trunk/library/classes/Gems/Roles.php 2011-10-24 11:18:29 UTC (rev 128) @@ -4,7 +4,7 @@ /** * Copyright (c) 2011, Erasmus MC * All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright @@ -15,7 +15,7 @@ * * Neither the name of Erasmus MC nor the * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE @@ -103,7 +103,7 @@ public function getAcl() { return $this->_acl; } - + public static function getInstance() { if (!isset(self::$_instanceOfSelf)) { @@ -124,11 +124,11 @@ $this->loadDbAcl(); } catch (Exception $e) { Gems_Log::getLogger()->logError($e); - + // Reset all roles unset($this->_acl); $this->_acl = new MUtil_Acl(); - + //Voeg standaard rollen en privileges in $this->loadDefaultRoles(); $this->loadDefaultPrivileges(); @@ -137,6 +137,10 @@ $this->loadProjectRoles(); $this->loadProjectPrivileges(); } + + //Now allow super admin all access, except for the actions that have the nologin privilege (->the login action) + $this->_acl->allow('super'); + $this->_acl->deny('super', null, 'pr.nologin'); } public function load() { @@ -154,7 +158,7 @@ $this->build(); } } - + /** * Recursively expands roles into Zend_Acl_Role objects * @param array $roleList @@ -163,31 +167,31 @@ private function _expandRole(&$roleList, $roleName, $depth = 0) { $role = $roleList[$roleName]; - + if (isset($role['marked']) && $role['marked']) { return; } - + // possible circular reference! if ($depth > 5) { throw new Exception("Possible circular reference detected while expanding role '{$roleName}'"); } - + if (!empty($role['grl_parents'])) { $parents = explode(",", $role['grl_parents']); - + foreach ($parents as $parent) { $this->_expandRole($roleList, $parent, $depth + 1); } } else { $parents = array(); } - + $this->addRole(new Zend_Acl_Role($role['grl_name']), $parents); - + $privileges = explode(",", $role['grl_privileges']); $this->addPrivilege($role['grl_name'], $privileges); - + $roleList[$roleName]['marked'] = true; } @@ -199,19 +203,19 @@ $db = Zend_Registry::get('db'); $sql = "SELECT grl_id_role,grl_name,grl_privileges,grl_parents FROM gems__roles"; - + $roles = $db->fetchAll($sql); - + if (empty($roles)) { throw new Exception("No roles stored in db"); } - + $roleList = array_combine(array_map(function($value) { return $value['grl_name']; }, $roles), $roles); - + foreach ($roleList as $role) { $this->_expandRole($roleList, $role['grl_name']); } - + return true; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <gem...@li...> - 2011-10-24 12:26:50
|
Revision: 133 http://gemstracker.svn.sourceforge.net/gemstracker/?rev=133&view=rev Author: matijsdejong Date: 2011-10-24 12:06:15 +0000 (Mon, 24 Oct 2011) Log Message: ----------- Fix for difference between active staff and staff members who ever did something. Modified Paths: -------------- trunk/library/classes/Gems/Default/MailJobAction.php trunk/library/classes/Gems/Util/DbLookup.php Modified: trunk/library/classes/Gems/Default/MailJobAction.php =================================================================== --- trunk/library/classes/Gems/Default/MailJobAction.php 2011-10-24 11:58:01 UTC (rev 132) +++ trunk/library/classes/Gems/Default/MailJobAction.php 2011-10-24 12:06:15 UTC (rev 133) @@ -100,7 +100,7 @@ $model->set('gmj_id_message', 'label', $this->_('Template'), 'multiOptions', $unselected + $dbLookup->getMailTemplates()); $model->set('gmj_id_user_as', 'label', $this->_('By staff member'), - 'multiOptions', $unselected + $dbLookup->getStaff(), 'default', $this->escort->getCurrentUserId(), + 'multiOptions', $unselected + $dbLookup->getActiveStaff(), 'default', $this->escort->getCurrentUserId(), 'description', $this->_('Used for logging and possibly from address.')); $model->set('gmj_active', 'label', $this->_('Active'), 'multiOptions', $translated->getYesNo(), 'elementClass', 'Checkbox', 'required', true, Modified: trunk/library/classes/Gems/Util/DbLookup.php =================================================================== --- trunk/library/classes/Gems/Util/DbLookup.php 2011-10-24 11:58:01 UTC (rev 132) +++ trunk/library/classes/Gems/Util/DbLookup.php 2011-10-24 12:06:15 UTC (rev 133) @@ -93,6 +93,24 @@ return $organizations; } + /** + * Return key/value pairs of all active staff members + * + * @staticvar array $data + * @return array + */ + public function getActiveStaff() + { + static $data; + + if (! $data) { + $data = $this->db->fetchPairs("SELECT gsf_id_user, CONCAT(COALESCE(gsf_last_name, '-'), ', ', COALESCE(gsf_first_name, ''), COALESCE(CONCAT(' ', gsf_surname_prefix), '')) + FROM gems__staff WHERE gsf_active = 1 ORDER BY gsf_last_name, gsf_first_name, gsf_surname_prefix"); + } + + return $data; + } + public function getActiveStaffGroups() { static $groups; @@ -214,7 +232,7 @@ } /** - * Return key/value pairs of all active staff members + * Return key/value pairs of all staff members, currently active or not * * @staticvar array $data * @return array @@ -225,7 +243,7 @@ if (! $data) { $data = $this->db->fetchPairs("SELECT gsf_id_user, CONCAT(COALESCE(gsf_last_name, '-'), ', ', COALESCE(gsf_first_name, ''), COALESCE(CONCAT(' ', gsf_surname_prefix), '')) - FROM gems__staff WHERE gsf_active = 1 ORDER BY gsf_last_name, gsf_first_name, gsf_surname_prefix"); + FROM gems__staff WHERE ORDER BY gsf_last_name, gsf_first_name, gsf_surname_prefix"); } return $data; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <gem...@li...> - 2011-10-26 12:51:35
|
Revision: 144 http://gemstracker.svn.sourceforge.net/gemstracker/?rev=144&view=rev Author: mennodekker Date: 2011-10-26 12:51:28 +0000 (Wed, 26 Oct 2011) Log Message: ----------- activated cache in Gems_Roles, and forced a rebuild of the acl on save in the RoleAction Modified Paths: -------------- trunk/library/classes/Gems/Default/RoleAction.php trunk/library/classes/Gems/Roles.php Modified: trunk/library/classes/Gems/Default/RoleAction.php =================================================================== --- trunk/library/classes/Gems/Default/RoleAction.php 2011-10-26 11:58:13 UTC (rev 143) +++ trunk/library/classes/Gems/Default/RoleAction.php 2011-10-26 12:51:28 UTC (rev 144) @@ -46,6 +46,11 @@ */ class Gems_Default_RoleAction extends Gems_Controller_BrowseEditAction { + /** + * @var GemsEscort + */ + public $escort; + protected function _showTable($caption, $data, $nested = false) { $table = MUtil_Html_TableElement::createArray($data, $caption, $nested); @@ -107,6 +112,21 @@ } /** + * As the ACL might have to be updated, rebuild the acl + * + * @param array $data + * @param type $isNew + * @return type + */ + public function afterSave(array $data, $isNew) + { + $roles = $this->loader->getRoles($this->escort); + $roles->build(); + + return true; + } + + /** * Check the disabled (=inherited) privileges * * @param Gems_Form $form Modified: trunk/library/classes/Gems/Roles.php =================================================================== --- trunk/library/classes/Gems/Roles.php 2011-10-26 11:58:13 UTC (rev 143) +++ trunk/library/classes/Gems/Roles.php 2011-10-26 12:51:28 UTC (rev 144) @@ -241,13 +241,16 @@ private function save() { if ($this->_cache instanceof Zend_Cache_Core) { if (!$this->_cache->save($this->_acl, $this->_cacheid, array(), null)) - echo "MISLUKT!"; + throw new Gems_Exception('Failed to save acl to cache'); } } public function setCache($cache) { - if ($cache instanceof Zend_Cache_Core) + if ($cache instanceof Zend_Cache_Core) { $this->_cache = $cache; - } + } elseif ($cache instanceof GemsEscort) { + $this->_cache = $cache->cache; + } + } } \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <gem...@li...> - 2011-11-02 12:35:03
|
Revision: 165 http://gemstracker.svn.sourceforge.net/gemstracker/?rev=165&view=rev Author: mennodekker Date: 2011-11-02 12:34:57 +0000 (Wed, 02 Nov 2011) Log Message: ----------- Updated docs Modified Paths: -------------- trunk/library/classes/Gems/Form/TableForm.php trunk/library/classes/Gems/TabForm.php Modified: trunk/library/classes/Gems/Form/TableForm.php =================================================================== --- trunk/library/classes/Gems/Form/TableForm.php 2011-11-02 11:35:57 UTC (rev 164) +++ trunk/library/classes/Gems/Form/TableForm.php 2011-11-02 12:34:57 UTC (rev 165) @@ -159,8 +159,13 @@ /** * Add element to stack * - * @param Zend_Form_Element $element - * @return Zend_Form_Element + * Takes care of setting the right decorators for table display + * + * @param string|Zend_Form_Element $element + * @param string $name + * @param array|Zend_Config $options + * @throws Zend_Form_Exception on invalid element + * @return Gems_Form_TableForm */ public function addElement($element, $name = null, $options = null) { Modified: trunk/library/classes/Gems/TabForm.php =================================================================== --- trunk/library/classes/Gems/TabForm.php 2011-11-02 11:35:57 UTC (rev 164) +++ trunk/library/classes/Gems/TabForm.php 2011-11-02 12:34:57 UTC (rev 165) @@ -1,5 +1,4 @@ <?php - /** * Copyright (c) 2011, Erasmus MC * All rights reserved. @@ -45,7 +44,17 @@ * @var Gems_Form_TabSubForm */ private $currentTab = null; - + + /** + * Add an element to the form, when a tab (subform) had been added, it will return + * the subform instead of the form, keep this in mind when chaining methods + * + * @param string|Zend_Form_Element $element + * @param string $name + * @param array|Zend_Config $options + * @throws Zend_Form_Exception on invalid element + * @return Gems_TabForm|Gems_Form_TabSubForm + */ public function addElement($element, $name = null, $options = null) { if ($this->currentTab) { @@ -54,7 +63,14 @@ return parent::addElement($element, $name, $options); } } - + + /** + * Add a tab to the form + * + * @param string $name + * @param string $title + * @return Gems_Form_TabSubForm + */ public function addTab($name, $title) { if ($title instanceof MUtil_Html_Sequence) $title = $title->render($form->getView()); @@ -64,6 +80,16 @@ return $tab; } + /** + * Add an element to the form, when a tab (subform) had been added, it will return + * the subform instead of the form, keep this in mind when chaining methods + * + * @param array $elements + * @param string $name + * @param array|Zend_Config $options + * @return Gems_TabForm|Gems_Form_TabSubForm + * @throws Zend_Form_Exception if no valid elements provided + */ public function addDisplayGroup(array $elements, $name, $options = null) { if ($this->currentTab) { return $this->currentTab->addDisplayGroup($elements, $name, $options); @@ -80,6 +106,13 @@ } } + /** + * Return a display group, use recursive search in subforms to provide a transparent experience + * with tabs + * + * @param string $name + * @return Zend_Form_DisplayGroup|null + */ public function getDisplayGroup($name) { if ($group = parent::getDisplayGroup($name)) { @@ -95,6 +128,13 @@ } } + /** + * Retrieve a single element, use recursive search in subforms to provide a transparent experience + * with tabs + * + * @param string $name + * @return Zend_Form_Element|null + */ public function getElement($name) { if ($element = parent::getElement($name)) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <gem...@li...> - 2011-11-04 12:47:07
|
Revision: 183 http://gemstracker.svn.sourceforge.net/gemstracker/?rev=183&view=rev Author: mennodekker Date: 2011-11-04 12:47:01 +0000 (Fri, 04 Nov 2011) Log Message: ----------- Minor refactoring to be able to execute patches from the upgrader that is being built Modified Paths: -------------- trunk/library/classes/Gems/Default/DatabaseAction.php trunk/library/classes/Gems/Util/DatabasePatcher.php Modified: trunk/library/classes/Gems/Default/DatabaseAction.php =================================================================== --- trunk/library/classes/Gems/Default/DatabaseAction.php 2011-11-04 11:39:43 UTC (rev 182) +++ trunk/library/classes/Gems/Default/DatabaseAction.php 2011-11-04 12:47:01 UTC (rev 183) @@ -351,8 +351,6 @@ $data['db_level'] = $data['level']; $form->getElement('db_level')->setValue($data['db_level']); - $this->db->query('INSERT IGNORE INTO gems__patch_levels (gpl_level, gpl_created) VALUES (?, CURRENT_TIMESTAMP)', $data['level']); - $this->addMessage(sprintf($this->_('%d patch(es) executed.'), $changed)); } Modified: trunk/library/classes/Gems/Util/DatabasePatcher.php =================================================================== --- trunk/library/classes/Gems/Util/DatabasePatcher.php 2011-11-04 11:39:43 UTC (rev 182) +++ trunk/library/classes/Gems/Util/DatabasePatcher.php 2011-11-04 12:47:01 UTC (rev 183) @@ -130,14 +130,22 @@ 'gpa_sql' => $statement ); } - } + } } } } } - public function executePatch($patch, $ignoreCompleted = true, $ignoreExecuted = false) + /** + * Executes db patches for the given $patchLevel + * + * @param int $patchLevel Only execute patches for this patchlevel + * @param boolean $ignoreCompleted Set to yes to skip patches that where already completed + * @param boolean $ignoreExecuted Set to yes to skip patches that where already executed (this includes the ones that are executed but not completed) + * @return int The number of executed patches + */ + public function executePatch($patchLevel, $ignoreCompleted = true, $ignoreExecuted = false) { $sql = 'SELECT gpa_id_patch, gpa_sql, gpa_completed FROM gems__patches WHERE gpa_level = ?'; if ($ignoreCompleted) { @@ -151,7 +159,7 @@ $current = new Zend_Db_Expr('CURRENT_TIMESTAMP'); $executed = 0; - $patches = $this->db->fetchAll($sql, $patch); + $patches = $this->db->fetchAll($sql, $patchLevel); foreach ($patches as $patch) { $data = array(); @@ -176,6 +184,11 @@ $executed++; } + //Update the patchlevel only when we have executed at least one patch + if ($executed>0) { + $this->db->query('INSERT IGNORE INTO gems__patch_levels (gpl_level, gpl_created) VALUES (?, CURRENT_TIMESTAMP)', $patchLevel); + } + return $executed; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <gem...@li...> - 2011-11-04 12:49:23
|
Revision: 184 http://gemstracker.svn.sourceforge.net/gemstracker/?rev=184&view=rev Author: mennodekker Date: 2011-11-04 12:49:12 +0000 (Fri, 04 Nov 2011) Log Message: ----------- Start for #34, still needs a controller and more testing but the basics are there Modified Paths: -------------- trunk/library/classes/Gems/Loader.php Added Paths: ----------- trunk/library/classes/Gems/Upgrades.php trunk/library/classes/Gems/UpgradesAbstract.php Modified: trunk/library/classes/Gems/Loader.php =================================================================== --- trunk/library/classes/Gems/Loader.php 2011-11-04 12:47:01 UTC (rev 183) +++ trunk/library/classes/Gems/Loader.php 2011-11-04 12:49:12 UTC (rev 184) @@ -1,6 +1,4 @@ <?php - - /** * Copyright (c) 2011, Erasmus MC * All rights reserved. @@ -90,6 +88,12 @@ /** * + * @var Gems_Upgrades + */ + protected $upgrades; + + /** + * * @var Gems_User_UserLoader */ protected $userLoader; @@ -183,6 +187,15 @@ /** * + * @return Gems_Upgrades + */ + public function getUpgrades() + { + return $this->_getClass('upgrades'); + } + + /** + * * @param string $login_name * @param int $organization Only used when more than one organization uses this $login_name * @return Gems_User_UserAbstract Added: trunk/library/classes/Gems/Upgrades.php =================================================================== --- trunk/library/classes/Gems/Upgrades.php (rev 0) +++ trunk/library/classes/Gems/Upgrades.php 2011-11-04 12:49:12 UTC (rev 184) @@ -0,0 +1,71 @@ +<?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. + * + * Short description of file + * + * @package Gems + * @subpackage Upgrades + * @copyright Copyright (c) 2011 Erasmus MC + * @license New BSD License + * @version $Id: Sample.php 215 2011-07-12 08:52:54Z michiel $ + */ + +/** + * Short description for Upgrades + * + * Long description for class Upgrades (if any)... + * + * @package Gems + * @subpackage Upgrades + * @copyright Copyright (c) 2011 Erasmus MC + * @license New BSD License + * @since Class available since version 1.5 + */ +class Gems_Upgrades extends Gems_UpgradesAbstract +{ + public function __construct() + { + //Important, ALWAYS run the contruct of our parent object + parent::__construct(); + + //Now set the context + $this->setContext('gems'); + //And add our patches + $this->register('Upgrade143to15'); + } + + + /** + * To upgrade from 143 to 15 we need to do some work: + * 1. execute db patches + */ + public function Upgrade143to15() + { + $this->patcher->executePatch(42); + return true; + } +} \ No newline at end of file Added: trunk/library/classes/Gems/UpgradesAbstract.php =================================================================== --- trunk/library/classes/Gems/UpgradesAbstract.php (rev 0) +++ trunk/library/classes/Gems/UpgradesAbstract.php 2011-11-04 12:49:12 UTC (rev 184) @@ -0,0 +1,282 @@ +<?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. + * + * Short description of file + * + * @package Gems + * @subpackage Upgrades + * @copyright Copyright (c) 2011 Erasmus MC + * @license New BSD License + * @version $Id: Sample.php 215 2011-07-12 08:52:54Z michiel $ + */ + +/** + * Short description for Upgrades + * + * Long description for class Upgrades (if any)... + * + * @package Gems + * @subpackage Upgrades + * @copyright Copyright (c) 2011 Erasmus MC + * @license New BSD License + * @since Class available since version 1.5 + */ +class Gems_UpgradesAbstract extends Gems_Loader_TargetLoaderAbstract +{ + protected $_context = null; + + protected $_upgradeStack = array(); + + protected $_messages = array(); + + protected $upgradeFile; + + /** + * @var Zend_Config_Ini + */ + protected $_info; + + /** + * @var Zend_Db_Adapter_Abstract + */ + public $db; + + /** + * @var GemsEscort + */ + public $escort; + + /** + * @var Gems_Loader + */ + public $loader; + + /** + * + * @var Gems_Util_DatabasePatcher + */ + public $patcher; + + /** + * @var Zend_Translate_Adapter + */ + public $translate; + + public function __construct() + { + //First get a GemsEscort instance, as we might need that a lot (and it can not be injected) + $this->escort = GemsEscort::getInstance(); + + $this->upgradeFile = GEMS_ROOT_DIR . str_replace('/', DIRECTORY_SEPARATOR , '/var/settings/upgrades.ini'); + if(!file_exists($this->upgradeFile)) { + touch($this->upgradeFile); + } + $this->_info = new Zend_Config_Ini($this->upgradeFile, null, array('allowModifications' => true)); + } + + /** + * Proxy to the translate object + * + * @param string $messageId + * @param type $locale + * @return string + */ + protected function _($messageId, $locale = null) + { + return $this->translate->_($messageId, $locale); + } + + /** + * Add a message to the stack + * + * @param string $message + */ + protected function addMessage($message) + { + $this->_messages[] = $message; + } + + /** + * Now we have the requests answered, add the DatabasePatcher as it needs the db object + * + * @return boolean + */ + public function checkRegistryRequestsAnswers() { + //As an upgrade almost always includes executing db patches, make a DatabasePatcher object available + $this->patcher = new Gems_Util_DatabasePatcher($this->db, 'patches.sql', $this->escort->getDatabasePaths()); + //No load all patches, and save the resulting changed patches for later (not used yet) + $changed = $this->patcher->uploadPatches($this->loader->getVersions()->getBuild()); + + return true; + } + + /** + * Reset the message stack + */ + protected function clearMessages() + { + $this->_messages = array(); + } + + public function execute($context, $to = null, $from = null) + { + if(is_null($to)) { + $to = count($this->_upgradeStack[$context]); + } + if(is_null($from)) { + $from = $this->getLevel($context); + } + $from = max(1, $from); + + $this->addMessage(sprintf($this->_('Trying upgrade for %s from level %s to level %s'), $context, $from, $to)); + + $success = false; + for($level = $from; $level<=$to; $level++) { + if (isset($this->_upgradeStack[$context][$level]) && is_callable($this->_upgradeStack[$context][$level])) { + $this->addMessage(sprintf($this->_('Trying upgrade for %s to level %s'), $context, $level)); + if (call_user_func($this->_upgradeStack[$context][$level])) { + $success = $level; + $this->addMessage('OK'); + } else { + $this->addMessage('FAILED'); + break; + } + } + } + if ($success) { + $this->setLevel($context, $success); + } + return $success; + } + + public function getContext() { + return $this->_context; + } + + public function getLevel($context) + { + if(isset($this->_info->$context)) { + return $this->_info->$context; + } else { + return 0; + } + } + + /** + * Get the highest level for the given context + * + * @param string|null $context + * @return int + */ + public function getMaxLevel($context = null) + { + if (! $context) { + $context = $this->getContext(); + } + + if (isset($this->_upgradeStack[$context])) { + $values = array_keys($this->_upgradeStack[$context]); + $values[] = 0; + $index = intval(max($values)); + return $index; + } else { + return 0; + + } + } + + public function getMessages() + { + return $this->_messages; + } + + public function getUpgrades($requestedContext = null) + { + $result = array(); + foreach($this->_upgradeStack as $context => $content) { + $row = array(); + $row['context'] = $context; + $row['maxLevel'] = $this->getMaxLevel($context); + $row['level'] = $this->getLevel($context); + $result[$context] = $row; + } + + if (is_null($requestedContext)) { + return $result; + } else { + if (isset($result[$requestedContext])) { + return $result[$requestedContext]; + } + } + } + + public function register($callback, $index = null, $context = null) + { + if (is_string($callback)) { + $callback = array($this, $callback); + } + if (is_callable($callback)) { + if (! $context) { + $context = $this->getContext(); + } + + if (isset($this->_upgradeStack[$context])) { + $key = array_search($callback, $this->_upgradeStack[$context]); + if ($key !== false) { + $index = $key; + } + } else { + $this->_upgradeStack[$context] = array(); + } + + if (is_null($index)) { + $index = $this->getMaxLevel($context); + $index++; + } + + $this->_upgradeStack[$context][$index] = $callback; + + return true; + } + return false; + } + + public function setContext($context) { + $this->_context = $context; + } + + protected function setLevel($context, $level = null, $force = false) + { + if (!is_null($level) && + $this->_info->$context != $level && + ($force || $this->_info->$context < $level)) { + $this->_info->$context = $level; + $writer = new Zend_Config_Writer_Ini(); + $writer->write($this->upgradeFile, $this->_info); + } + } +} \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <gem...@li...> - 2011-11-07 15:30:30
|
Revision: 188 http://gemstracker.svn.sourceforge.net/gemstracker/?rev=188&view=rev Author: mennodekker Date: 2011-11-07 15:30:23 +0000 (Mon, 07 Nov 2011) Log Message: ----------- Allow optional parameters in a menuItem Further improvements for #34 Modified Paths: -------------- trunk/library/classes/Gems/Menu/SubMenuItem.php trunk/library/classes/Gems/Upgrades.php trunk/library/classes/Gems/UpgradesAbstract.php Modified: trunk/library/classes/Gems/Menu/SubMenuItem.php =================================================================== --- trunk/library/classes/Gems/Menu/SubMenuItem.php 2011-11-07 13:48:32 UTC (rev 187) +++ trunk/library/classes/Gems/Menu/SubMenuItem.php 2011-11-07 15:30:23 UTC (rev 188) @@ -127,8 +127,8 @@ private function _applyParameterSource($source, $paramFunction, array &$parameters) { // Fill in required parameters - if ($this->_requiredParameters) { - foreach ($this->_requiredParameters as $param => $name) { + if ($this->_parameters && is_array($this->_parameters)) { + foreach ($this->_parameters as $param => $name) { $default = isset($parameters[$param]) ? $parameters[$param] : null; @@ -491,18 +491,35 @@ $params = MUtil_Ra::pairs(func_get_args()); if (true === $this->_parameters) { - $this->_parameters = new MUtil_Lazy_ArrayWrap(); + $this->_parameters = array(); } foreach ($params as $param => $name) { if (is_int($param)) { $param = $name; } $this->_requiredParameters[$param] = $name; - $this->_parameters[$param] = MUtil_Lazy::L($name); + $this->_parameters[$param] = $name; } return $this; } + public function addOptionalParameters($arrayOrKey1 = null, $altName1 = null) + { + $params = MUtil_Ra::pairs(func_get_args()); + + if (true === $this->_parameters) { + $this->_parameters = array(); + } + foreach ($params as $param => $name) { + if (is_int($param)) { + $param = $name; + } + //$this->_requiredParameters[$param] = $name; + $this->_parameters[$param] = $name; + } + return $this; + } + public function addParameters($arrayOrKey1 = null, $key2 = null) { $param = MUtil_Ra::args(func_get_args()); Modified: trunk/library/classes/Gems/Upgrades.php =================================================================== --- trunk/library/classes/Gems/Upgrades.php 2011-11-07 13:48:32 UTC (rev 187) +++ trunk/library/classes/Gems/Upgrades.php 2011-11-07 15:30:23 UTC (rev 188) @@ -55,7 +55,7 @@ //Now set the context $this->setContext('gems'); //And add our patches - $this->register('Upgrade143to15'); + $this->register('Upgrade143to15', 'Upgrade from 1.43 to 1.5'); } Modified: trunk/library/classes/Gems/UpgradesAbstract.php =================================================================== --- trunk/library/classes/Gems/UpgradesAbstract.php 2011-11-07 13:48:32 UTC (rev 187) +++ trunk/library/classes/Gems/UpgradesAbstract.php 2011-11-07 15:30:23 UTC (rev 188) @@ -148,17 +148,26 @@ $to = $this->getMaxLevel($context); } if(is_null($from)) { - $from = $this->getLevel($context); + $from = $this->getNextLevel(); + + if ($from > $to) { + $this->addMessage($this->_('Already at max. level.')); + return $to; + } } - $from = max(1, $from); + $from = max(1, intval($from)); + $to = intval($to); $this->addMessage(sprintf($this->_('Trying upgrade for %s from level %s to level %s'), $context, $from, $to)); $success = false; - for($level = $from; $level<=$to; $level++) { - if (isset($this->_upgradeStack[$context][$level]) && is_callable($this->_upgradeStack[$context][$level])) { - $this->addMessage(sprintf($this->_('Trying upgrade for %s to level %s'), $context, $level)); - if (call_user_func($this->_upgradeStack[$context][$level])) { + $upgrades = $this->_upgradeStack[$context]; + ksort($upgrades); + $this->_upgradeStack[$context] = $upgrades; + foreach($this->_upgradeStack[$context] as $level => $upgrade) { + if (($level > $from && $level <= $to)) { + $this->addMessage(sprintf($this->_('Trying upgrade for %s to level %s: %s'), $context, $level, $this->_upgradeStack[$context][$level]['info'])); + if (call_user_func($upgrade['upgrade'])) { $success = $level; $this->addMessage('OK'); } else { @@ -209,6 +218,38 @@ } } + /** + * Get the next level for a given level and context + * + * When context is null, it will get the current context + * When level is null, it will get the current level + * + * @param type $level + * @param type $context + * @return type + */ + public function getNextLevel($context = null, $level = null) { + if (is_null($context)) { + $context = $this->getContext(); + } + if (is_null($level)) { + $level = $this->getLevel($context); + } + + //Get all the levels + $currentContext = $this->_upgradeStack[$context]; + ksort($currentContext); + $levels = array_keys($this->_upgradeStack[$context]); + //Find the index of the current one + $current = array_search($level, $levels); + + //And if it is present, return the next level + if (isset($levels[$current++])) return $levels[$current++]; + + //Else return current level +1 (doesn't exist anyway) + return $level++; + } + public function getMessages() { return $this->_messages; @@ -251,7 +292,7 @@ } } - public function register($callback, $index = null, $context = null) + public function register($callback, $info = null, $index = null, $context = null) { if (is_string($callback)) { $callback = array(get_class($this), $callback); @@ -275,7 +316,8 @@ $index++; } - $this->_upgradeStack[$context][$index] = $callback; + $this->_upgradeStack[$context][$index]['upgrade'] = $callback; + $this->_upgradeStack[$context][$index]['info'] = $info; return true; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <gem...@li...> - 2011-11-08 13:31:41
|
Revision: 194 http://gemstracker.svn.sourceforge.net/gemstracker/?rev=194&view=rev Author: mennodekker Date: 2011-11-08 13:31:35 +0000 (Tue, 08 Nov 2011) Log Message: ----------- Added possible deprecated comment in Toke fixed Tracker->createRespondentTrack when no $respTrackData was given Modified Paths: -------------- trunk/library/classes/Gems/Tracker/Token.php trunk/library/classes/Gems/Tracker.php Modified: trunk/library/classes/Gems/Tracker/Token.php =================================================================== --- trunk/library/classes/Gems/Tracker/Token.php 2011-11-08 12:46:17 UTC (rev 193) +++ trunk/library/classes/Gems/Tracker/Token.php 2011-11-08 13:31:35 UTC (rev 194) @@ -118,7 +118,7 @@ protected $survey; /** - * + * @deprecated MD: 20111108 Found no reference and defined class is missing. Remove? * @var Gems_Tracker_Track */ protected $track; Modified: trunk/library/classes/Gems/Tracker.php =================================================================== --- trunk/library/classes/Gems/Tracker.php 2011-11-08 12:46:17 UTC (rev 193) +++ trunk/library/classes/Gems/Tracker.php 2011-11-08 13:31:35 UTC (rev 194) @@ -235,7 +235,7 @@ * @param array $trackFieldsData * @return Gems_Tracker_RespondentTrack The newly created track */ - public function createRespondentTrack($patientId, $organizationId, $trackId, $userId, $respTrackData = null, array $trackFieldsData = array()) + public function createRespondentTrack($patientId, $organizationId, $trackId, $userId, $respTrackData = array(), array $trackFieldsData = array()) { $trackEngine = $this->getTrackEngine($trackId); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <gem...@li...> - 2011-11-15 09:37:23
|
Revision: 215 http://gemstracker.svn.sourceforge.net/gemstracker/?rev=215&view=rev Author: mennodekker Date: 2011-11-15 09:37:16 +0000 (Tue, 15 Nov 2011) Log Message: ----------- Almost done putting Auth back in, checkpassword still to be removed Modified Paths: -------------- trunk/library/classes/Gems/Auth.php trunk/library/classes/Gems/Default/IndexAction.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/UserDefinitionInterface.php Added Paths: ----------- trunk/library/classes/Gems/Auth/ trunk/library/classes/Gems/Auth/Adapter/ trunk/library/classes/Gems/Auth/Adapter/Callback.php Added: trunk/library/classes/Gems/Auth/Adapter/Callback.php =================================================================== --- trunk/library/classes/Gems/Auth/Adapter/Callback.php (rev 0) +++ trunk/library/classes/Gems/Auth/Adapter/Callback.php 2011-11-15 09:37:16 UTC (rev 215) @@ -0,0 +1,90 @@ +<?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. + * + * Short description of file + * + * @package Gems + * @subpackage Auth + * @copyright Copyright (c) 2011 Erasmus MC + * @license New BSD License + * @version $Id: Sample.php 215 2011-07-12 08:52:54Z michiel $ + */ + +/** + * Short description for Callback + * + * Long description for class Callback (if any)... + * + * @package Gems + * @subpackage Auth + * @copyright Copyright (c) 2011 Erasmus MC + * @license New BSD License + * @since Class available since version 1.0 + * @deprecated Class deprecated since version 2.0 + */ +class Gems_Auth_Adapter_Callback implements Zend_Auth_Adapter_Interface +{ + private $_callback; + private $_identity; + private $_params; + + /** + * Create an auth adapter from a callback + * + * Ideally the callback should return a Zend_Auth_Result, when not it should + * return true or false and in that case this adapter will wrap the result + * in a Zend_Auth_Result + * + * @param type $callback A valid callback + * @param type $identity The identity to use + * @param type $params Array of parameters needed for the callback + */ + public function __construct($callback, $identity, $params) + { + $this->_callback = $callback; + $this->_identity = $identity; + $this->_params = $params; + } + + /** + * Perform the authenticate attempt + * + * @return Zend_Auth_Result + */ + public function authenticate() + { + $result = call_user_func_array($this->_callback, $this->_params); + if ( !($result instanceof Zend_Auth_Result)) { + if ($result === true) { + $result = new Zend_Auth_Result(Zend_Auth_Result::SUCCESS, $this->_identity); + } else { + $result = new Zend_Auth_Result(Zend_Auth_Result::FAILURE, $this->_identity); + } + } + return $result; + } +} \ No newline at end of file Modified: trunk/library/classes/Gems/Auth.php =================================================================== --- trunk/library/classes/Gems/Auth.php 2011-11-15 08:18:52 UTC (rev 214) +++ trunk/library/classes/Gems/Auth.php 2011-11-15 09:37:16 UTC (rev 215) @@ -57,7 +57,7 @@ */ protected $_messageTemplates = array( self::ERROR_DATABASE_NOT_INSTALLED => 'Installation not complete! Login is not yet possible!', - self::ERROR_PASSWORD_DELAY => 'Your account is temporarily blocked, please wait %s minutes' + self::ERROR_PASSWORD_DELAY => 'Your account is temporarily blocked, please wait %s seconds' ); /** @@ -92,37 +92,76 @@ return new Zend_Auth_Result($code, null, (array) $messages); } - public function authenticate(Zend_Auth_Adapter_Interface $adapter, $username = '') { + public function authenticate(Zend_Auth_Adapter_Interface $adapter, $formValues) { try { - /** - * Lookup last failed login and number of failed logins - */ - try { - $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 - $results = 0; - MUtil_Echo::r(GemsEscort::getInstance()->translate->_('Please update the database')); - } + $login_name = $formValues['userlogin']; + $organization = $formValues['organization']; + $sql = "SELECT gula_failed_logins, gula_last_failed FROM gems__user_login_attemps WHERE gula_login = ? AND gula_id_organization = ?"; + $values = $this->db->fetchRow($sql, array($login_name, $organization)); - $delay = pow($results['gul_failed_logins'], $this->_delayFactor); - $remaining = ($results['gul_last_failed'] + $delay) - time(); + if (! $values) { + $values = array(); + $values['gula_login'] = $login_name; + $values['gula_id_organization'] = $organization; + $values['gula_failed_logins'] = 0; + $values['gula_last_failed'] = null; + } elseif ($values['gula_failed_logins'] > 0) { + // Get the datetime + $last = new MUtil_Date($values['gula_last_failed'], Zend_Date::ISO_8601); - if ($results['gul_failed_logins'] > 0 && $remaining > 0) { - //$this->_obscureValue = false; - $result = $this->_error(self::ERROR_PASSWORD_DELAY, ceil($remaining / 60)); + // How long to wait until we can ignore the previous failed attempt + $delay = pow($values['gula_failed_logins'], GemsEscort::getInstance()->project->getAccountDelayFactor()); + + if (abs($last->diffSeconds()) <= $delay) { + // Response gets slowly slower + $sleepTime = min($values['gula_failed_logins'], 10); + sleep($sleepTime); + $remaining = $delay - abs($last->diffSeconds()) - $sleepTime; + if ($remaining>0) { + $result = $this->_error(self::ERROR_PASSWORD_DELAY, $remaining); + } + } } - } catch (Zend_Db_Exception $zde) { - $result = $this->_error(self::ERROR_DATABASE_NOT_INSTALLED); + } catch (Zend_Db_Exception $e) { + // Fall through as this does not work if the database upgrade did not run + // MUtil_Echo::r($e); } - if (!isset($result)) { - //Ok we are done without errors, now delegate to the Zend_Auth_Adapter + // We only forward to auth adapter when we have no timeout to prevent hammering the auth system + if (! isset($result) ) { $result = parent::authenticate($adapter); } + if ($result->isValid()) { + $values['gula_failed_logins'] = 0; + $values['gula_last_failed'] = null; + } else { + if ($values['gula_failed_logins']) { + // Only increment when we have no password delay + if ($result->getCode() <> self::ERROR_PASSWORD_DELAY) { + $values['gula_failed_logins'] += 1; + $values['gula_last_failed'] = new Zend_Db_Expr('CURRENT_TIMESTAMP'); + } + } else { + $values['gula_failed_logins'] = 1; + $values['gula_last_failed'] = new Zend_Db_Expr('CURRENT_TIMESTAMP'); + } + $values['gula_failed_logins'] = max($values['gula_failed_logins'], 1); + } + + try { + if (isset($values['gula_login'])) { + $this->db->insert('gems__user_login_attemps', $values); + } else { + $where = $this->db->quoteInto('gula_login = ? AND ', $login_name); + $where .= $this->db->quoteInto('gula_id_organization = ?', $organization); + $this->db->update('gems__user_login_attemps', $values, $where); + } + } catch (Zend_Db_Exception $e) { + // Fall through as this does not work if the database upgrade did not run + // MUtil_Echo::r($e); + } + //Now localize $result = $this->localize($result); Modified: trunk/library/classes/Gems/Default/IndexAction.php =================================================================== --- trunk/library/classes/Gems/Default/IndexAction.php 2011-11-15 08:18:52 UTC (rev 214) +++ trunk/library/classes/Gems/Default/IndexAction.php 2011-11-15 09:37:16 UTC (rev 215) @@ -184,7 +184,7 @@ $element->setAttrib('size', 10); $element->setAttrib('maxlength', 20); $element->setRequired(true); - $element->addValidator(new Gems_User_LoginPasswordValidator($this->loader->getUserLoader(), 'userlogin', 'organization', $this->translate)); + //$element->addValidator(new Gems_User_LoginPasswordValidator($this->loader->getUserLoader(), 'userlogin', 'organization', $this->translate)); return $element; } @@ -284,31 +284,42 @@ $user = $this->loader->getUser($request->getParam('userlogin'), $request->getParam('organization')); if ($user->isActive()) { - $user->setAsCurrentUser(); + $formValues = $form->getValues(); + $authResult = $user->authenticate($formValues); - /** - * Fix current locale / organization in cookies - */ - Gems_Cookies::setLocale($user->getLocale(), $this->basepath->getBasePath()); - Gems_Cookies::setOrganization($user->getOrganizationId(), $this->basepath->getBasePath()); + if ($authResult->isValid()) { - /** - * Ready - */ - $this->addMessage(sprintf($this->_('Login successful, welcome %s.'), $user->getFullName())); + $user->setAsCurrentUser(); - /** - * Log the login - */ - Gems_AccessLog::getLog($this->db)->log("index.login", $this->getRequest(), null, $user->getUserId(), true); + $user->afterLogin($form->getValues()); - if ($previousRequestParameters = $this->session->previousRequestParameters) { - $this->_reroute(array('controller' => $previousRequestParameters['controller'], 'action' => $previousRequestParameters['action']), false); + /** + * Fix current locale / organization in cookies + */ + 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.'), $user->getFullName())); + + /** + * Log the login + */ + 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); + } else { + // This reroutes to the first available menu page after login + $this->_reroute(array('controller' => null, 'action' => null), true); + } + return; } else { - // This reroutes to the first available menu page after login - $this->_reroute(array('controller' => null, 'action' => null), true); + $errors = $authResult->getMessages(); + $this->addMessage($errors); } - return; } } else { $errors = $form->getErrors(); Modified: trunk/library/classes/Gems/User/NoLoginDefinition.php =================================================================== --- trunk/library/classes/Gems/User/NoLoginDefinition.php 2011-11-15 08:18:52 UTC (rev 214) +++ trunk/library/classes/Gems/User/NoLoginDefinition.php 2011-11-15 09:37:16 UTC (rev 215) @@ -74,4 +74,15 @@ //'user_organization_id' => 0, //REMOVED AS IT BREAKS STORING LAST ORGANIZATION ); } + + public function getAuthAdapter($formValues) + { + $adapter = new Gems_Auth_Adapter_Callback(array(get_class(),'alwaysFalse'), $formValues['userlogin'], $formValues); + return $adapter; + } + + private function alwaysFalse($params) { + $result = new Zend_Auth_Result(Zend_Auth_Result::FAILURE, $params['userlogin']); + return false; + } } Modified: trunk/library/classes/Gems/User/OldStaffUserDefinition.php =================================================================== --- trunk/library/classes/Gems/User/OldStaffUserDefinition.php 2011-11-15 08:18:52 UTC (rev 214) +++ trunk/library/classes/Gems/User/OldStaffUserDefinition.php 2011-11-15 09:37:16 UTC (rev 215) @@ -178,4 +178,75 @@ { return md5($password); } + + public function getAuthAdapter($formValues) + { + $adapter = new Zend_Auth_Adapter_DbTable(null, 'gems__staff', 'gsf_login', 'gsf_password'); + + $pwd_hash = $this->hashPassword($formValues['password']); + + $select = $adapter->getDbSelect(); + $select->where('gsf_active = 1') + ->where('gsf_id_organization = ?', $formValues['organization']); + + $adapter->setIdentity($formValues['userlogin']) + ->setCredential($pwd_hash); + + return $adapter; + } + + /** + * Perform UserDefinition specific post-login logic + * + * @param Zend_Auth_Result $authResult + * @return void + */ + public function afterLogin($authResult, $formValues) + { + if ($authResult->isValid()) { + $userData = $this->getUserData($formValues['userlogin'], $formValues['organization']); + $staff_id = $userData['user_id']; + + $sql = 'SELECT gul_id_user FROM gems__user_logins WHERE gul_can_login = 1 AND gul_login = ? AND gul_id_organization = ?'; + + try { + $user_id = $this->db->fetchOne($sql, array($login_name, $organization)); + + $currentTimestamp = new Zend_Db_Expr('CURRENT_TIMESTAMP'); + + // Move to USER_STAFF + $values['gup_id_user'] = $user_id; + $values['gup_password'] = $this->project->getValueHash($password); + $values['gup_reset_key'] = null; + $values['gup_reset_requested'] = null; + $values['gup_reset_required'] = 0; + $values['gup_changed'] = $currentTimestamp ; + $values['gup_changed_by'] = $staff_id; + $values['gup_created'] = $currentTimestamp ; + $values['gup_created_by'] = $staff_id; + + $this->db->insert('gems__user_passwords', $values); + + // Update user class + $values = array(); + $values['gul_user_class'] = Gems_User_UserLoader::USER_STAFF; + $values['gul_changed'] = $currentTimestamp ; + $values['gul_changed_by'] = $staff_id; + $this->db->update('gems__user_logins', $values, $this->db->quoteInto('gul_id_user = ?', $user_id)); + + // Remove old password + $values = array(); + $values['gsf_password'] = null; + $values['gsf_changed'] = $currentTimestamp ; + $values['gsf_changed_by'] = $user_id; + + $this->db->update('gems__staff', $values, $this->db->quoteInto('gsf_id_user = ?', $staff_id)); + + } catch (Zend_Db_Exception $e) { + // Fall through as this does not work if the database upgrade did not run + // MUtil_Echo::r($e); + + } + } + } } Modified: trunk/library/classes/Gems/User/ProjectUserDefinition.php =================================================================== --- trunk/library/classes/Gems/User/ProjectUserDefinition.php 2011-11-15 08:18:52 UTC (rev 214) +++ trunk/library/classes/Gems/User/ProjectUserDefinition.php 2011-11-15 09:37:16 UTC (rev 215) @@ -86,4 +86,10 @@ 'allowedOrgs' => array($organization => 'SUPER ADMIN') ); } + + public function getAuthAdapter($formValues) + { + $adapter = new Gems_Auth_Adapter_Callback(array($this->project,'checkSuperAdminPassword'), $formValues['userlogin'], $formValues['password']); + return $adapter; + } } Modified: trunk/library/classes/Gems/User/StaffUserDefinition.php =================================================================== --- trunk/library/classes/Gems/User/StaffUserDefinition.php 2011-11-15 08:18:52 UTC (rev 214) +++ trunk/library/classes/Gems/User/StaffUserDefinition.php 2011-11-15 09:37:16 UTC (rev 215) @@ -252,4 +252,21 @@ return $this; } + + public function getAuthAdapter($formValues) + { + $adapter = new Zend_Auth_Adapter_DbTable($this->db, 'gems__user_passwords', 'gul_login', 'gup_password'); + + $pwd_hash = $this->hashPassword($formValues['password']); + + $select = $adapter->getDbSelect(); + $select->join('gems__user_logins', 'gup_id_user = gul_id_user', array()) + ->where('gul_can_login = 1') + ->where('gul_id_organization = ?', $formValues['organization']); + + $adapter->setIdentity($formValues['userlogin']) + ->setCredential($pwd_hash); + + return $adapter; + } } Modified: trunk/library/classes/Gems/User/User.php =================================================================== --- trunk/library/classes/Gems/User/User.php 2011-11-15 08:18:52 UTC (rev 214) +++ trunk/library/classes/Gems/User/User.php 2011-11-15 09:37:16 UTC (rev 215) @@ -48,6 +48,12 @@ { /** * + * @var Zend_Auth_Result + */ + private $_authResult; + + /** + * * @var ArrayObject or Zend_Session_Namespace */ private $_vars; @@ -173,6 +179,34 @@ } /** + * Perform project specific after login logic here, can also delegate to the user definition + * + * @return void + */ + public function afterLogin($formValues) { + if (is_callable(array($this->definition, 'afterLogin'))) { + $this->definition->afterLogin($this->_authResult, $formValues); + } + } + + /** + * Authenticate a users credentials using the submitted form + * + * @param array $formValues the array containing all formvalues from the login form + * @return boolean + */ + public function authenticate($formValues) + { + $auth = Gems_Auth::getInstance(); + $adapter = $this->definition->getAuthAdapter($formValues); + $authResult = $auth->authenticate($adapter, $formValues); + + $this->_authResult = $authResult; + + return $authResult; + } + + /** * Return true if a password reset key can be created. * * @return boolean Modified: trunk/library/classes/Gems/User/UserDefinitionInterface.php =================================================================== --- trunk/library/classes/Gems/User/UserDefinitionInterface.php 2011-11-15 08:18:52 UTC (rev 214) +++ trunk/library/classes/Gems/User/UserDefinitionInterface.php 2011-11-15 09:37:16 UTC (rev 215) @@ -88,6 +88,13 @@ public function checkPasswordResetKey(Gems_User_User $user, $key); /** + * Returns an initialized Zend_Auth_Adapter_Interface + * + * @return Zend_Auth_Adapter_Interface + */ + public function getAuthAdapter($formValues); + + /** * Return a password reset key * * @param Gems_User_User $user The user to create a key for. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <gem...@li...> - 2011-11-15 10:29:50
|
Revision: 217 http://gemstracker.svn.sourceforge.net/gemstracker/?rev=217&view=rev Author: mennodekker Date: 2011-11-15 10:29:43 +0000 (Tue, 15 Nov 2011) Log Message: ----------- And finally remove the checkpassword, and obsolete validators Modified Paths: -------------- trunk/library/classes/Gems/Default/IndexAction.php trunk/library/classes/Gems/Default/OptionAction.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/UserDefinitionInterface.php trunk/library/classes/Gems/User/UserLoader.php Removed Paths: ------------- trunk/library/classes/Gems/User/LoginPasswordValidator.php trunk/library/classes/Gems/User/UserPasswordValidator.php Modified: trunk/library/classes/Gems/Default/IndexAction.php =================================================================== --- trunk/library/classes/Gems/Default/IndexAction.php 2011-11-15 09:44:12 UTC (rev 216) +++ trunk/library/classes/Gems/Default/IndexAction.php 2011-11-15 10:29:43 UTC (rev 217) @@ -184,7 +184,6 @@ $element->setAttrib('size', 10); $element->setAttrib('maxlength', 20); $element->setRequired(true); - //$element->addValidator(new Gems_User_LoginPasswordValidator($this->loader->getUserLoader(), 'userlogin', 'organization', $this->translate)); return $element; } Modified: trunk/library/classes/Gems/Default/OptionAction.php =================================================================== --- trunk/library/classes/Gems/Default/OptionAction.php 2011-11-15 09:44:12 UTC (rev 216) +++ trunk/library/classes/Gems/Default/OptionAction.php 2011-11-15 10:29:43 UTC (rev 217) @@ -98,7 +98,6 @@ $element->setAttrib('maxlength', 20); $element->setRenderPassword(true); $element->setRequired(true); - $element->addValidator(new Gems_User_UserPasswordValidator($user, $this->translate)); $form->addElement($element); } @@ -131,16 +130,26 @@ /**************** * Process form * ****************/ - if ($this->_request->isPost() && $form->isValid($_POST)) { - $user->setPassword($_POST['new_password']); + if ($this->_request->isPost()) { + if ($form->isValid($_POST)) { + $authResult = $user->authenticate(array('userlogin' => $user->getLoginName(), + 'password' => $_POST['old_password'], + 'organization' =>$user->getOrganizationId())); + if ($authResult->isValid()) { + $user->setPassword($_POST['new_password']); - $this->addMessage($this->_('New password is active.')); - $this->_reroute(array($this->getRequest()->getActionKey() => 'edit')); + $this->addMessage($this->_('New password is active.')); + $this->_reroute(array($this->getRequest()->getActionKey() => 'edit')); + } else { + if (isset($_POST['old_password'])) { + if ($_POST['old_password'] === strtoupper($_POST['old_password'])) { + $this->addMessage($this->_('Caps Lock seems to be on!')); + } else { + $errors = $authResult->getMessages(); + $this->addMessage($errors); - } else { - if (isset($_POST['old_password'])) { - if ($_POST['old_password'] === strtoupper($_POST['old_password'])) { - $this->addMessage($this->_('Caps Lock seems to be on!')); + } + } } } $form->populate($_POST); Deleted: trunk/library/classes/Gems/User/LoginPasswordValidator.php =================================================================== --- trunk/library/classes/Gems/User/LoginPasswordValidator.php 2011-11-15 09:44:12 UTC (rev 216) +++ trunk/library/classes/Gems/User/LoginPasswordValidator.php 2011-11-15 10:29:43 UTC (rev 217) @@ -1,140 +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 -{ - /** - * Field containing user login - * - * @var string - */ - private $_loginField = 'userlogin'; - - /** - * Field containing organization id. - * - * @var string - */ - private $_organizationField = 'organization'; - - /** - * - * @var Gems_User_UserLoader - */ - private $_userLoader; - - /** - * - * @var Zend_Translate - */ - private $_translate; - - /** - * - * @var boolean - */ - private $_valid = false; - - /** - * - * @param Gems_User_UserLoader $loader - * @param type $loginField Field in form containing login name - * @param string $organizationField Field in form containing organization - * @param Zend_Translate $translate Optional translator - */ - public function __construct(Gems_User_UserLoader $loader, $loginField, $organizationField, Zend_Translate $translate = null) - { - $this->_userLoader = $loader; - $this->_loginField = $loginField; - $this->_organizationField = $organizationField; - $this->_translate = $translate ? $translate : new MUtil_Translate_Adapter_Potemkin(); - } - - /** - * 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 (isset($context[$this->_loginField], $context[$this->_organizationField])) { - $this->_valid = $this->_userLoader->checkPassword($context[$this->_loginField], $context[$this->_organizationField], $value); - } else { - $this->_valid = false; - } - - return $this->_valid; - } - - /** - * 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() - { - if ($this->_valid) { - return array(); - - } else { - return array($this->_translate->_('Combination of username password not found.')); - } - - - } -} Modified: trunk/library/classes/Gems/User/NoLoginDefinition.php =================================================================== --- trunk/library/classes/Gems/User/NoLoginDefinition.php 2011-11-15 09:44:12 UTC (rev 216) +++ trunk/library/classes/Gems/User/NoLoginDefinition.php 2011-11-15 10:29:43 UTC (rev 217) @@ -46,18 +46,16 @@ */ class Gems_User_NoLoginDefinition extends Gems_User_UserDefinitionAbstract { - /** - * Checks the password for the specified $login_name and $organization. - * - * @param string $login_name - * @param int $organization - * @param string $password - * @return boolean True if the password is correct. - */ - public function checkPassword($login_name, $organization, $password) - { + private function alwaysFalse($params) { + $result = new Zend_Auth_Result(Zend_Auth_Result::FAILURE, $params['userlogin']); return false; } + + public function getAuthAdapter($formValues) + { + $adapter = new Gems_Auth_Adapter_Callback(array(get_class(),'alwaysFalse'), $formValues['userlogin'], $formValues); + return $adapter; + } /** * Returns a user object, that may be empty if the user is unknown. @@ -74,15 +72,4 @@ //'user_organization_id' => 0, //REMOVED AS IT BREAKS STORING LAST ORGANIZATION ); } - - public function getAuthAdapter($formValues) - { - $adapter = new Gems_Auth_Adapter_Callback(array(get_class(),'alwaysFalse'), $formValues['userlogin'], $formValues); - return $adapter; - } - - private function alwaysFalse($params) { - $result = new Zend_Auth_Result(Zend_Auth_Result::FAILURE, $params['userlogin']); - return false; - } } Modified: trunk/library/classes/Gems/User/OldStaffUserDefinition.php =================================================================== --- trunk/library/classes/Gems/User/OldStaffUserDefinition.php 2011-11-15 09:44:12 UTC (rev 216) +++ trunk/library/classes/Gems/User/OldStaffUserDefinition.php 2011-11-15 10:29:43 UTC (rev 217) @@ -58,23 +58,22 @@ * @var Gems_Project_ProjectSettings */ protected $project; - + /** - * Checks the password for the specified $login_name and $organization. + * Perform UserDefinition specific post-login logic * - * @param string $login_name - * @param int $organization - * @param string $password - * @return boolean True if the password is correct. + * @param Zend_Auth_Result $authResult + * @return void */ - public function checkPassword($login_name, $organization, $password) + public function afterLogin($authResult, $formValues) { - $pwd_hash = $this->hashPassword($password); + if ($authResult->isValid()) { + $login_name = $formValues['userlogin']; + $organization = $formValues['organization']; + $password = $formValues['password']; + $userData = $this->getUserData($formValues['userlogin'], $formValues['organization']); + $staff_id = $userData['user_id']; - $sql = "SELECT gsf_id_user FROM gems__staff WHERE gsf_active = 1 AND gsf_login = ? AND gsf_id_organization = ? AND gsf_password = ?"; - - if ($staff_id = $this->db->fetchOne($sql, array($login_name, $organization, $pwd_hash))) { - $sql = 'SELECT gul_id_user FROM gems__user_logins WHERE gul_can_login = 1 AND gul_login = ? AND gul_id_organization = ?'; try { @@ -115,10 +114,23 @@ // MUtil_Echo::r($e); } - - return true; } + } + public function getAuthAdapter($formValues) + { + $adapter = new Zend_Auth_Adapter_DbTable(null, 'gems__staff', 'gsf_login', 'gsf_password'); + + $pwd_hash = $this->hashPassword($formValues['password']); + + $select = $adapter->getDbSelect(); + $select->where('gsf_active = 1') + ->where('gsf_id_organization = ?', $formValues['organization']); + + $adapter->setIdentity($formValues['userlogin']) + ->setCredential($pwd_hash); + + return $adapter; } /** @@ -178,78 +190,4 @@ { return md5($password); } - - public function getAuthAdapter($formValues) - { - $adapter = new Zend_Auth_Adapter_DbTable(null, 'gems__staff', 'gsf_login', 'gsf_password'); - - $pwd_hash = $this->hashPassword($formValues['password']); - - $select = $adapter->getDbSelect(); - $select->where('gsf_active = 1') - ->where('gsf_id_organization = ?', $formValues['organization']); - - $adapter->setIdentity($formValues['userlogin']) - ->setCredential($pwd_hash); - - return $adapter; - } - - /** - * Perform UserDefinition specific post-login logic - * - * @param Zend_Auth_Result $authResult - * @return void - */ - public function afterLogin($authResult, $formValues) - { - if ($authResult->isValid()) { - $login_name = $formValues['userlogin']; - $organization = $formValues['organization']; - $password = $formValues['password']; - $userData = $this->getUserData($formValues['userlogin'], $formValues['organization']); - $staff_id = $userData['user_id']; - - $sql = 'SELECT gul_id_user FROM gems__user_logins WHERE gul_can_login = 1 AND gul_login = ? AND gul_id_organization = ?'; - - try { - $user_id = $this->db->fetchOne($sql, array($login_name, $organization)); - - $currentTimestamp = new Zend_Db_Expr('CURRENT_TIMESTAMP'); - - // Move to USER_STAFF - $values['gup_id_user'] = $user_id; - $values['gup_password'] = $this->project->getValueHash($password); - $values['gup_reset_key'] = null; - $values['gup_reset_requested'] = null; - $values['gup_reset_required'] = 0; - $values['gup_changed'] = $currentTimestamp ; - $values['gup_changed_by'] = $staff_id; - $values['gup_created'] = $currentTimestamp ; - $values['gup_created_by'] = $staff_id; - - $this->db->insert('gems__user_passwords', $values); - - // Update user class - $values = array(); - $values['gul_user_class'] = Gems_User_UserLoader::USER_STAFF; - $values['gul_changed'] = $currentTimestamp ; - $values['gul_changed_by'] = $staff_id; - $this->db->update('gems__user_logins', $values, $this->db->quoteInto('gul_id_user = ?', $user_id)); - - // Remove old password - $values = array(); - $values['gsf_password'] = null; - $values['gsf_changed'] = $currentTimestamp ; - $values['gsf_changed_by'] = $user_id; - - $this->db->update('gems__staff', $values, $this->db->quoteInto('gsf_id_user = ?', $staff_id)); - - } catch (Zend_Db_Exception $e) { - // Fall through as this does not work if the database upgrade did not run - // MUtil_Echo::r($e); - - } - } - } -} +} \ No newline at end of file Modified: trunk/library/classes/Gems/User/ProjectUserDefinition.php =================================================================== --- trunk/library/classes/Gems/User/ProjectUserDefinition.php 2011-11-15 09:44:12 UTC (rev 216) +++ trunk/library/classes/Gems/User/ProjectUserDefinition.php 2011-11-15 10:29:43 UTC (rev 217) @@ -52,17 +52,10 @@ */ protected $project; - /** - * Checks the password for the specified $login_name and $organization. - * - * @param string $login_name - * @param int $organization - * @param string $password - * @return boolean True if the password is correct. - */ - public function checkPassword($login_name, $organization, $password) + public function getAuthAdapter($formValues) { - return $this->project->checkSuperAdminPassword($password); + $adapter = new Gems_Auth_Adapter_Callback(array($this->project,'checkSuperAdminPassword'), $formValues['userlogin'], $formValues['password']); + return $adapter; } /** @@ -86,10 +79,4 @@ 'allowedOrgs' => array($organization => 'SUPER ADMIN') ); } - - public function getAuthAdapter($formValues) - { - $adapter = new Gems_Auth_Adapter_Callback(array($this->project,'checkSuperAdminPassword'), $formValues['userlogin'], $formValues['password']); - return $adapter; - } -} +} \ No newline at end of file Modified: trunk/library/classes/Gems/User/StaffUserDefinition.php =================================================================== --- trunk/library/classes/Gems/User/StaffUserDefinition.php 2011-11-15 09:44:12 UTC (rev 216) +++ trunk/library/classes/Gems/User/StaffUserDefinition.php 2011-11-15 10:29:43 UTC (rev 217) @@ -92,29 +92,6 @@ } /** - * Checks the password for the specified $login_name and $organization. - * - * @param string $login_name - * @param int $organization - * @param string $password - * @return boolean True if the password is correct. - */ - public function checkPassword($login_name, $organization, $password) - { - $pwd_hash = $this->hashPassword($password); - - $sql = "SELECT gup_password - FROM gems__user_passwords INNER JOIN gems__user_logins ON gup_id_user = gul_id_user - WHERE gul_can_login = 1 AND gul_login = ? AND gul_id_organization = ?"; - - $db_pwd = $this->db->fetchOne($sql, array($login_name, $organization)); - - // MUtil_Echo::track($password, $pwd_hash, $db_pwd); - - return ($pwd_hash == $db_pwd); - } - - /** * Check whether a reset key is really linked to a user. * * @param Gems_User_User $user The user the key was created for (hopefully). @@ -136,6 +113,23 @@ return false; } + public function getAuthAdapter($formValues) + { + $adapter = new Zend_Auth_Adapter_DbTable($this->db, 'gems__user_passwords', 'gul_login', 'gup_password'); + + $pwd_hash = $this->hashPassword($formValues['password']); + + $select = $adapter->getDbSelect(); + $select->join('gems__user_logins', 'gup_id_user = gul_id_user', array()) + ->where('gul_can_login = 1') + ->where('gul_id_organization = ?', $formValues['organization']); + + $adapter->setIdentity($formValues['userlogin']) + ->setCredential($pwd_hash); + + return $adapter; + } + /** * Return a password reset key * @@ -252,21 +246,4 @@ return $this; } - - public function getAuthAdapter($formValues) - { - $adapter = new Zend_Auth_Adapter_DbTable($this->db, 'gems__user_passwords', 'gul_login', 'gup_password'); - - $pwd_hash = $this->hashPassword($formValues['password']); - - $select = $adapter->getDbSelect(); - $select->join('gems__user_logins', 'gup_id_user = gul_id_user', array()) - ->where('gul_can_login = 1') - ->where('gul_id_organization = ?', $formValues['organization']); - - $adapter->setIdentity($formValues['userlogin']) - ->setCredential($pwd_hash); - - return $adapter; - } -} +} \ No newline at end of file Modified: trunk/library/classes/Gems/User/User.php =================================================================== --- trunk/library/classes/Gems/User/User.php 2011-11-15 09:44:12 UTC (rev 216) +++ trunk/library/classes/Gems/User/User.php 2011-11-15 10:29:43 UTC (rev 217) @@ -227,17 +227,6 @@ } /** - * Checks the password for this user and handle the login security. - * - * @param string $password - * @return boolean True if the password is correct. - */ - public function checkPassword($password) - { - return $this->userLoader->checkPassword($this->getLoginName(), $this->getOrganizationId(), $password); - } - - /** * Check whether a reset key is really linked to this user. * * @param string The key Modified: trunk/library/classes/Gems/User/UserDefinitionInterface.php =================================================================== --- trunk/library/classes/Gems/User/UserDefinitionInterface.php 2011-11-15 09:44:12 UTC (rev 216) +++ trunk/library/classes/Gems/User/UserDefinitionInterface.php 2011-11-15 10:29:43 UTC (rev 217) @@ -69,16 +69,6 @@ public function canSetPassword(Gems_User_User $user = null); /** - * Checks the password for the specified $login_name and $organization. - * - * @param string $login_name - * @param int $organization - * @param string $password - * @return boolean True if the password is correct. - */ - public function checkPassword($login_name, $organization, $password); - - /** * Check whether a reset key is really linked to a user. * * @param Gems_User_User $user The user the key was created for (hopefully). Modified: trunk/library/classes/Gems/User/UserLoader.php =================================================================== --- trunk/library/classes/Gems/User/UserLoader.php 2011-11-15 09:44:12 UTC (rev 216) +++ trunk/library/classes/Gems/User/UserLoader.php 2011-11-15 10:29:43 UTC (rev 217) @@ -114,76 +114,6 @@ protected static $organizationStore; /** - * Checks the password for the specified $login_name and $organization and - * handles the login security. - * - * @param string $login_name - * @param int $organization - * @param string $password - * @return boolean True if the password is correct. - */ - public function checkPassword($login_name, $organization, $password) - { - // MUtil_Echo::track($login_name, $organization, $password); - $defName = $this->getUserClassName($login_name, $organization); - $definition = $this->_getClass($defName); - - $success = $definition->checkPassword($login_name, $organization, $password); - - try { - $sql = "SELECT gula_failed_logins, gula_last_failed FROM gems__user_login_attemps WHERE gula_login = ? AND gula_id_organization = ?"; - $values = $this->db->fetchRow($sql, array($login_name, $organization)); - - if (! $values) { - $values = array(); - $values['gula_login'] = $login_name; - $values['gula_id_organization'] = $organization; - $values['gula_failed_logins'] = 0; - $values['gula_last_failed'] = null; - } - if ($success) { - $values['gula_failed_logins'] = 0; - $values['gula_last_failed'] = null; - } else { - if ($values['gula_failed_logins']) { - // Get the datetime - $last = new MUtil_Date($values['gula_last_failed'], Zend_Date::ISO_8601); - - // How long to wait until we can ignore the previous failed attempt - $delay = pow($values['gula_failed_logins'], $this->project->getAccountDelayFactor()); - - if (abs($last->diffSeconds()) <= $delay) { - // Response gets slowly slower - sleep(min($values['gula_failed_logins'], 10)); - - $values['gula_failed_logins'] += 1; - - } else { - $values['gula_failed_logins'] = 1; - } - } else { - $values['gula_failed_logins'] = 1; - } - $values['gula_failed_logins'] = max($values['gula_failed_logins'], 1); - $values['gula_last_failed'] = new Zend_Db_Expr('CURRENT_TIMESTAMP'); - } - - if (isset($values['gula_login'])) { - $this->db->insert('gems__user_login_attemps', $values); - } else { - $where = $this->db->quoteInto('gula_login = ? AND ', $login_name); - $where .= $this->db->quoteInto('gula_id_organization = ?', $organization); - $this->db->update('gems__user_login_attemps', $values, $where); - } - - } catch (Zend_Db_Exception $e) { - // Fall through as this does not work if the database upgrade did not run - // MUtil_Echo::r($e); - } - return $success; - } - - /** * Should be called after answering the request to allow the Target * to check if all required registry values have been set correctly. * Deleted: trunk/library/classes/Gems/User/UserPasswordValidator.php =================================================================== --- trunk/library/classes/Gems/User/UserPasswordValidator.php 2011-11-15 09:44:12 UTC (rev 216) +++ trunk/library/classes/Gems/User/UserPasswordValidator.php 2011-11-15 10:29:43 UTC (rev 217) @@ -1,118 +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_UserPasswordValidator implements Zend_Validate_Interface -{ - /** - * - * @var Gems_User_User - */ - private $_user; - - /** - * - * @var Zend_Translate - */ - private $_translate; - - /** - * - * @var boolean - */ - private $_valid = false; - - /** - * - * @param Gems_User_User $user The user to check - * @param Zend_Translate $translate Optional translator - */ - public function __construct(Gems_User_User $user, Zend_Translate $translate = null) - { - $this->_user = $user; - $this->_translate = $translate ? $translate : new MUtil_Translate_Adapter_Potemkin(); - } - - /** - * 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()) - { - $this->_valid = $this->_user->checkPassword($value); - - return $this->_valid; - } - - /** - * 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() - { - if ($this->_valid) { - return array(); - - } else { - return array($this->_translate->_('Wrong password.')); - } - - - } -} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <gem...@li...> - 2011-11-15 12:38:30
|
Revision: 219 http://gemstracker.svn.sourceforge.net/gemstracker/?rev=219&view=rev Author: matijsdejong Date: 2011-11-15 12:38:23 +0000 (Tue, 15 Nov 2011) Log Message: ----------- Organizations are now stored in cache Modified Paths: -------------- trunk/library/classes/Gems/Loader.php trunk/library/classes/Gems/User/Organization.php trunk/library/classes/Gems/User/UserLoader.php Modified: trunk/library/classes/Gems/Loader.php =================================================================== --- trunk/library/classes/Gems/Loader.php 2011-11-15 11:05:57 UTC (rev 218) +++ trunk/library/classes/Gems/Loader.php 2011-11-15 12:38:23 UTC (rev 219) @@ -1,4 +1,5 @@ <?php + /** * Copyright (c) 2011, Erasmus MC * All rights reserved. Modified: trunk/library/classes/Gems/User/Organization.php =================================================================== --- trunk/library/classes/Gems/User/Organization.php 2011-11-15 11:05:57 UTC (rev 218) +++ trunk/library/classes/Gems/User/Organization.php 2011-11-15 12:38:23 UTC (rev 219) @@ -46,27 +46,90 @@ * @license New BSD License * @since Class available since version 1.5 */ -class Gems_User_Organization +class Gems_User_Organization extends Gems_Registry_TargetAbstract { /** + * The default organization data for 'no organization'. * * @var array */ + protected $_noOrganization = array( + 'gor_id_organization' => 1, + 'gor_name' => 'NO ORGANIZATION', + 'gor_code' => null, + 'gor_style' => null, + 'gor_iso_lang' => 'en', + 'gor_active' => 0, + ); + + /** + * + * @var array + */ protected $_organizationData; /** + * + * @var int + */ + protected $_organizationId; + + /** + * + * @var Zend_Cache_Core + */ + protected $cache; + + /** + * + * @var Zend_Db_Adapter_Abstract + */ + protected $db; + + /** * Creates the organization object. * - * @param array $organizationData + * @param int $organizationId */ - public function __construct(array $organizationData) + public function __construct($organizationId) { - $this->_organizationData = $organizationData; + $this->_organizationId = $organizationId; } /** + * 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 are missing. + */ + public function checkRegistryRequestsAnswers() + { + if ($this->cache) { + $cacheId = GEMS_PROJECT_NAME . '__' . __CLASS__ . '__' . $this->_organizationId; + $this->_organizationData = $this->cache->load($cacheId); + } else { + $cacheId = false; + } + + if (! $this->_organizationData) { + $this->_organizationData = $this->db->fetchRow('SELECT * FROM gems__organizations WHERE gor_id_organization = ? LIMIT 1', $this->_organizationId); + + if (! $this->_organizationData) { + $this->_organizationData = $this->_noOrganization; + } + + if ($cacheId) { + $this->cache->save($this->_organizationData, $cacheId); + } + } + + return is_array($this->_organizationData) && parent::checkRegistryRequestsAnswers(); + } + + + /** * Get the style attribute. - * + * * @return string */ public function getStyle() Modified: trunk/library/classes/Gems/User/UserLoader.php =================================================================== --- trunk/library/classes/Gems/User/UserLoader.php 2011-11-15 11:05:57 UTC (rev 218) +++ trunk/library/classes/Gems/User/UserLoader.php 2011-11-15 12:38:23 UTC (rev 219) @@ -55,20 +55,6 @@ const USER_STAFF = 'StaffUser'; /** - * The default organization data for 'no organization'. - * - * @var array - */ - protected static $_noOrganization = array( - 'gor_id_organization' => 1, - 'gor_name' => 'NO ORGANIZATION', - 'gor_code' => null, - 'gor_style' => null, - 'gor_iso_lang' => 'en', - 'gor_active' => 0, - ); - - /** * 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. @@ -174,38 +160,17 @@ */ public function getOrganization($organizationId = null) { - if (! self::$organizationStore) { - self::$organizationStore = new Zend_Session_Namespace('gems.' . GEMS_PROJECT_NAME . '.organizations'); - } + static $organizations = array(); if (null === $organizationId) { $organizationId = intval(self::$currentUser->getOrganizationId()); } - if (! self::$organizationStore->__isset($organizationId)) { - - // We are not sure the is a database at this moment - try { - $data = $this->db->fetchRow('SELECT * FROM gems__organizations WHERE gor_id_organization = ? LIMIT 1', $organizationId); - } catch (Zend_Db_Exception $e) { - $data = false; - } - if (! $data) { - // Use default - $data = self::$_noOrganization; - - // But do attempt to get the last added organization. - foreach (self::$organizationStore->getIterator() as $key => $value) { - if ($key !== 0) { - $organizationId = $key; - $data = self::$organizationStore->__get($key); - } - } - } - self::$organizationStore->__set($organizationId, $data); + if (! isset($organizations[$organizationId])) { + $organizations[$organizationId] = $this->_loadClass('Organization', true, array($organizationId)); } - return new Gems_User_Organization(self::$organizationStore->__get($organizationId)); + return $organizations[$organizationId]; } /** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <gem...@li...> - 2011-11-15 14:28:53
|
Revision: 220 http://gemstracker.svn.sourceforge.net/gemstracker/?rev=220&view=rev Author: mennodekker Date: 2011-11-15 14:28:47 +0000 (Tue, 15 Nov 2011) Log Message: ----------- Regenerate sessionId on logout Changed organization object to allow ->org_id etc. for easy access to content docblock fix for result of user->authenticate Modified Paths: -------------- trunk/library/classes/Gems/Default/IndexAction.php trunk/library/classes/Gems/User/Organization.php trunk/library/classes/Gems/User/User.php Modified: trunk/library/classes/Gems/Default/IndexAction.php =================================================================== --- trunk/library/classes/Gems/Default/IndexAction.php 2011-11-15 12:38:23 UTC (rev 219) +++ trunk/library/classes/Gems/Default/IndexAction.php 2011-11-15 14:28:47 UTC (rev 220) @@ -336,6 +336,7 @@ $this->addMessage(sprintf($this->_('Good bye: %s.'), $user->getFullName())); $user->unsetAsCurrentUser(); + Zend_Session::regenerateId(); $this->_reroute(array('action' => 'index'), true); } Modified: trunk/library/classes/Gems/User/Organization.php =================================================================== --- trunk/library/classes/Gems/User/Organization.php 2011-11-15 12:38:23 UTC (rev 219) +++ trunk/library/classes/Gems/User/Organization.php 2011-11-15 14:28:47 UTC (rev 220) @@ -97,6 +97,25 @@ } /** + * Returns a callable if a method is called as a variable + * or the value from the organizationData if it exists + * + * @param string $name + * @return Callable + */ + public function __get($name) + { + if (method_exists($this, $name)) { + // Return a callable + return array($this, $name); + } elseif (isset($this->_organizationData[$name])) { + return $this->_organizationData[$name]; + } + + throw new Gems_Exception_Coding("Unknown method '$name' requested as callable."); + } + + /** * Should be called after answering the request to allow the Target * to check if all required registry values have been set correctly. * Modified: trunk/library/classes/Gems/User/User.php =================================================================== --- trunk/library/classes/Gems/User/User.php 2011-11-15 12:38:23 UTC (rev 219) +++ trunk/library/classes/Gems/User/User.php 2011-11-15 14:28:47 UTC (rev 220) @@ -193,7 +193,7 @@ * Authenticate a users credentials using the submitted form * * @param array $formValues the array containing all formvalues from the login form - * @return boolean + * @return Zend_Auth_Result */ public function authenticate($formValues) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <gem...@li...> - 2011-11-15 15:35:33
|
Revision: 221 http://gemstracker.svn.sourceforge.net/gemstracker/?rev=221&view=rev Author: mennodekker Date: 2011-11-15 15:35:22 +0000 (Tue, 15 Nov 2011) Log Message: ----------- On update organization, the cache is invalidated Modified Paths: -------------- trunk/library/classes/Gems/Default/OrganizationAction.php trunk/library/classes/Gems/User/Organization.php Modified: trunk/library/classes/Gems/Default/OrganizationAction.php =================================================================== --- trunk/library/classes/Gems/Default/OrganizationAction.php 2011-11-15 14:28:47 UTC (rev 220) +++ trunk/library/classes/Gems/Default/OrganizationAction.php 2011-11-15 15:35:22 UTC (rev 221) @@ -43,6 +43,13 @@ { public $autoFilter = false; + public function afterSave(array $data, $isNew) + { + $org = $this->loader->getOrganization($data['gor_id_organization']); + $org->invalidateCache(); + return parent::afterSave($data, $isNew); + } + public function changeUiAction() { $request = $this->getRequest(); Modified: trunk/library/classes/Gems/User/Organization.php =================================================================== --- trunk/library/classes/Gems/User/Organization.php 2011-11-15 14:28:47 UTC (rev 220) +++ trunk/library/classes/Gems/User/Organization.php 2011-11-15 15:35:22 UTC (rev 221) @@ -116,6 +116,15 @@ } /** + * Get the cacheId for the organization + * + * @return string + */ + private function _getCacheId() { + return GEMS_PROJECT_NAME . '__' . __CLASS__ . '__' . $this->_organizationId; + } + + /** * Should be called after answering the request to allow the Target * to check if all required registry values have been set correctly. * @@ -124,7 +133,7 @@ public function checkRegistryRequestsAnswers() { if ($this->cache) { - $cacheId = GEMS_PROJECT_NAME . '__' . __CLASS__ . '__' . $this->_organizationId; + $cacheId = $this->_getCacheId(); $this->_organizationData = $this->cache->load($cacheId); } else { $cacheId = false; @@ -155,4 +164,11 @@ { return $this->_organizationData['gor_style']; } + + public function invalidateCache() { + if ($this->cache) { + $cacheId = $this->_getCacheId(); + $this->cache->remove($cacheId); + } + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <gem...@li...> - 2011-11-17 17:19:43
|
Revision: 231 http://gemstracker.svn.sourceforge.net/gemstracker/?rev=231&view=rev Author: matijsdejong Date: 2011-11-17 17:19:37 +0000 (Thu, 17 Nov 2011) Log Message: ----------- Added validation to Round editor Started on password weakness check Updated documentation on Pdf Modified Paths: -------------- trunk/library/classes/Gems/Pdf.php trunk/library/classes/Gems/Tracker/Engine/TrackEngineAbstract.php trunk/library/classes/Gems/User/UserDefinitionAbstract.php Modified: trunk/library/classes/Gems/Pdf.php =================================================================== --- trunk/library/classes/Gems/Pdf.php 2011-11-17 16:19:26 UTC (rev 230) +++ trunk/library/classes/Gems/Pdf.php 2011-11-17 17:19:37 UTC (rev 231) @@ -26,24 +26,24 @@ * 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. - */ - -/** - * File description of Pdf * - * @author Matijs de Jong <mj...@ma...> - * @since 1.1 - * @version 1.1 - * @package Gems + * + * @package Gems * @subpackage Pdf + * @author Matijs de Jong <mj...@ma...> + * @copyright Copyright (c) 2011 Erasmus MC + * @license New BSD License + * @version $Id$ */ /** - * Class description of Pdf + * Gems standaard Pdf utility functions * - * @author Matijs de Jong <mj...@ma...> - * @package Gems + * @package Gems * @subpackage PDf + * @copyright Copyright (c) 2011 Erasmus MC + * @license New BSD License + * @since Class available since version 1.0 */ class Gems_Pdf extends Gems_Registry_TargetAbstract { Modified: trunk/library/classes/Gems/Tracker/Engine/TrackEngineAbstract.php =================================================================== --- trunk/library/classes/Gems/Tracker/Engine/TrackEngineAbstract.php 2011-11-17 16:19:26 UTC (rev 230) +++ trunk/library/classes/Gems/Tracker/Engine/TrackEngineAbstract.php 2011-11-17 17:19:37 UTC (rev 231) @@ -532,7 +532,7 @@ return $elements; } - + /** * Returns an associative array of the fields in this track * @@ -541,13 +541,13 @@ public function getFields() { $this->_ensureTrackFields(); - + $fields = array(); - + foreach ($this->_trackFields as $field) { $fields[$field['gtf_id_field']] = $field['gtf_field_name']; } - + return $fields; } @@ -703,7 +703,7 @@ } $model->set('gro_id_survey', 'label', $this->_('Survey'), 'multiOptions', $this->util->getTrackData()->getAllSurveys()); - $model->set('gro_id_order', 'label', $this->_('Order'), 'default', 10); + $model->set('gro_id_order', 'label', $this->_('Order'), 'default', 10, 'validators[]', $model->createUniqueValidator(array('gro_id_order', 'gro_id_track'))); $model->set('gro_round_description', 'label', $this->_('Description'), 'size', '30'); //, 'minlength', 4, 'required', true); $model->set('gro_changed_event', 'label', $this->_('After change'), 'multiOptions', $this->events->listRoundChangedEvents()); $model->set('gro_active', 'label', $this->_('Active'), 'multiOptions', $this->util->getTranslated()->getYesNo(), 'elementClass', 'checkbox'); Modified: trunk/library/classes/Gems/User/UserDefinitionAbstract.php =================================================================== --- trunk/library/classes/Gems/User/UserDefinitionAbstract.php 2011-11-17 16:19:26 UTC (rev 230) +++ trunk/library/classes/Gems/User/UserDefinitionAbstract.php 2011-11-17 17:19:37 UTC (rev 231) @@ -111,6 +111,17 @@ } /** + * Check for password weakness. + * + * @param string $password + * @return mixed String or array of strings containing warning messages + */ + public function isPasswordWeak($password) + { + + } + + /** * Set the password, if allowed for this user type. * * @param Gems_User_User $user The user whose password to change This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <gem...@li...> - 2011-11-18 17:08:35
|
Revision: 238 http://gemstracker.svn.sourceforge.net/gemstracker/?rev=238&view=rev Author: matijsdejong Date: 2011-11-18 17:08:28 +0000 (Fri, 18 Nov 2011) Log Message: ----------- Organization code is now used FIrst version of PasswordChecker.php, not yet integrated with working code. Modified Paths: -------------- trunk/library/classes/Gems/Default/OrganizationAction.php trunk/library/classes/Gems/Project/ProjectSettings.php trunk/library/classes/Gems/User/Organization.php trunk/library/classes/Gems/User/User.php trunk/library/classes/Gems/User/UserDefinitionAbstract.php trunk/library/classes/Gems/User/UserLoader.php Added Paths: ----------- trunk/library/classes/Gems/User/PasswordChecker.php Modified: trunk/library/classes/Gems/Default/OrganizationAction.php =================================================================== --- trunk/library/classes/Gems/Default/OrganizationAction.php 2011-11-18 15:11:59 UTC (rev 237) +++ trunk/library/classes/Gems/Default/OrganizationAction.php 2011-11-18 17:08:28 UTC (rev 238) @@ -159,6 +159,7 @@ $model->set('gor_name', 'description', 'ENGLISH please! Use translation file to translate.'); $model->set('gor_url', 'description', 'ENGLISH link preferred. Use translation file to translate.'); $model->set('gor_task', 'description', 'ENGLISH please! Use translation file to translate.'); + $model->set('gor_code', 'label', $this->_('Code name'), 'size', 10, 'description', $this->_('Only for programmers.')); } Gems_Model::setChangeFieldsByPrefix($model, 'gor'); Modified: trunk/library/classes/Gems/Project/ProjectSettings.php =================================================================== --- trunk/library/classes/Gems/Project/ProjectSettings.php 2011-11-18 15:11:59 UTC (rev 237) +++ trunk/library/classes/Gems/Project/ProjectSettings.php 2011-11-18 17:08:28 UTC (rev 238) @@ -91,6 +91,20 @@ $this->checkRequiredValues(); } + protected function _getPasswordRules(array $current, array $keys, array &$rules) + { + foreach ($current as $key => $value) { + if (is_array($value)) { + // Only act when this is in the set of key values + if (isset($keys[strtolower($key)])) { + $this->_getPasswordRules($value, $keys, $rules); + } + } else { + $rules[$key] = $value; + } + } + } + /** * This function checks for the required project settings. * @@ -181,6 +195,26 @@ } /** + * + * @param string $userDefinition + * @param string $role + * @return array + */ + public function getPasswordRules($userDefinition, $role) + { + $args = MUtil_Ra::flatten(func_get_args()); + $args = array_change_key_case(array_flip(array_filter($args))); + //MUtil_Echo::track($args); + + $rules = array(); + if (isset($this->passwords) && is_array($this->passwords)) { + $this->_getPasswordRules($this->passwords, $args, $rules); + } + + return $rules; + } + + /** * Returns the super admin name, if any * * @return string Modified: trunk/library/classes/Gems/User/Organization.php =================================================================== --- trunk/library/classes/Gems/User/Organization.php 2011-11-18 15:11:59 UTC (rev 237) +++ trunk/library/classes/Gems/User/Organization.php 2011-11-18 17:08:28 UTC (rev 238) @@ -154,6 +154,15 @@ return is_array($this->_organizationData) && parent::checkRegistryRequestsAnswers(); } + /** + * Get the style attribute. + * + * @return string + */ + public function getCode() + { + return $this->_organizationData['gor_code']; + } /** * Get the style attribute. Added: trunk/library/classes/Gems/User/PasswordChecker.php =================================================================== --- trunk/library/classes/Gems/User/PasswordChecker.php (rev 0) +++ trunk/library/classes/Gems/User/PasswordChecker.php 2011-11-18 17:08:28 UTC (rev 238) @@ -0,0 +1,225 @@ +<?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_PasswordChecker extends MUtil_Registry_TargetAbstract +{ + /** + * + * @var array + */ + protected $_errors = array(); + + /** + * + * @var Gems_Project_ProjectSettings + */ + protected $project; + + /** + * + * @var Zend_Translate + */ + protected $translate; + + /** + * + * @var Gems_User_User $user + */ + protected $user; + + /** + * + * @param type $errorMsg + */ + protected function _addError($errorMsg) + { + $this->_errors[] = $errorMsg; + } + + + /** + * Test the password for minimum number of upper case characters. + * + * @param mixed $parameter + * @param string $password + */ + protected function capsCount($parameter, $password) + { + $len = intval($parameter); + $results = array(); + if (preg_match_all('/[A-Z]/', $password, $results) < $len) { + $this->_addError(sprintf( + $this->translate->plural('A password should contain at least one uppercase character.', 'A password should contain at least %d uppercase characters.', $len), + $len)); + } + } + + /** + * Test the password for minimum number of lower case characters. + * + * @param mixed $parameter + * @param string $password + */ + protected function lowerCount($parameter, $password) + { + $len = intval($parameter); + $results = array(); + if (preg_match_all('/[a-z]/', $password, $results) < $len) { + $this->_addError(sprintf( + $this->translate->plural('A password should contain at least one lowercase character.', 'A password should contain at least %d lowercase characters.', $len), + $len)); + } + } + + /** + * Test the password for minimum length. + * + * @param mixed $parameter + * @param string $password + */ + protected function minLength($parameter, $password) + { + $len = intval($parameter); + if (strlen($password) < $len) { + $this->_addError(sprintf($this->translate->_('A password should be at least %d characters long.'), $len)); + } + } + + /** + * Test the password for minimum number non letter characters. + * + * @param mixed $parameter + * @param string $password + */ + protected function notAlphaCount($parameter, $password) + { + $len = intval($parameter); + $results = array(); + $count = preg_match_all('/[A-Za-z]/', $password, $results); + if (strlen($password) - $count < $len) { + $this->_addError(sprintf( + $this->translate->plural('A password should contain at least one not alphabetic character.', 'A password should contain at least %d not alphabetic characters.', $len), + $len)); + } + } + + /** + * Test the password for minimum number not alphanumeric characters. + * + * @param mixed $parameter + * @param string $password + */ + protected function notAlphaNumCount($parameter, $password) + { + $len = intval($parameter); + $results = array(); + $count = preg_match_all('/[A-Za-z]/', $password, $results); + if (strlen($password) - $count < $len) { + $this->_addError(sprintf( + $this->translate->plural('A password should contain at least one not alphanumeric character.', 'A password should contain at least %d not alphanumeric characters.', $len), + $len)); + } + } + + /** + * The password should not contain the name of the user or the login name. + * + * @param mixed $parameter + * @param string $password + */ + protected function notTheName($parameter, $password) + { + $on = $parameter != 0; + if ($on) { + $lpwd = strtolower($password); + + if (false !== strpos($lpwd, strtolower($this->user->getLoginName()))) { + $this->_addError($this->translate->_('A password should not contain the login name.')); + } + } + } + + /** + * Test the password for minimum number of numeric characters. + * + * @param mixed $parameter + * @param string $password + */ + protected function numCount($parameter, $password) + { + $len = intval($parameter); + $results = array(); + if (preg_match_all('/[0-9]/', $password, $results) < $len) { + $this->_addError(sprintf( + $this->translate->plural('A password should contain at least one number.', 'A password should contain at least %d numbers.', $len), + $len)); + } + } + + /** + * Check for password weakness. + * + * @param Gems_User_User $user The user for e.g. name checks + * @param string $password + * @return mixed String or array of strings containing warning messages + */ + public function reportPasswordWeakness(Gems_User_User $user, $password) + { + $this->_errors = array(); + $this->user = $user; + + $rules = $this->project->getPasswordRules($user->getOrganizationCode(), $user->getRoles()); + + // MUtil_Echo::track($rules); + foreach ($rules as $rule => $parameter) { + if (method_exists($this, $rule)) { + $this->$rule($parameter, $password); + } + } + + return $this->_errors; + } +} Modified: trunk/library/classes/Gems/User/User.php =================================================================== --- trunk/library/classes/Gems/User/User.php 2011-11-18 15:11:59 UTC (rev 237) +++ trunk/library/classes/Gems/User/User.php 2011-11-18 17:08:28 UTC (rev 238) @@ -60,6 +60,12 @@ /** * + * @var MUtil_Acl + */ + protected $acl; + + /** + * * @var Gems_User_UserDefinitionInterface */ protected $definition; @@ -202,7 +208,7 @@ $authResult = $auth->authenticate($adapter, $formValues); $this->_authResult = $authResult; - + return $authResult; } @@ -349,6 +355,18 @@ } /** + * Gets the (optional) organization code. + * + * @return string + */ + public function getOrganizationCode() + { + $organizationId = $this->getOrganizationId(); + + return $this->userLoader->getOrganization($organizationId)->getCode(); + } + + /** * Return a password reset key * * @return string @@ -369,6 +387,16 @@ } /** + * Returns the current user role. + * + * @return string + */ + public function getRoles() + { + return $this->acl->getRoleAndParents($this->getRole()); + } + + /** * Returns the user id, that identifies this user within this installation. * * One user id might be connected to multiple logins for multiple organizations. Modified: trunk/library/classes/Gems/User/UserDefinitionAbstract.php =================================================================== --- trunk/library/classes/Gems/User/UserDefinitionAbstract.php 2011-11-18 15:11:59 UTC (rev 237) +++ trunk/library/classes/Gems/User/UserDefinitionAbstract.php 2011-11-18 17:08:28 UTC (rev 238) @@ -111,17 +111,6 @@ } /** - * Check for password weakness. - * - * @param string $password - * @return mixed String or array of strings containing warning messages - */ - public function isPasswordWeak($password) - { - - } - - /** * Set the password, if allowed for this user type. * * @param Gems_User_User $user The user whose password to change Modified: trunk/library/classes/Gems/User/UserLoader.php =================================================================== --- trunk/library/classes/Gems/User/UserLoader.php 2011-11-18 15:11:59 UTC (rev 237) +++ trunk/library/classes/Gems/User/UserLoader.php 2011-11-18 17:08:28 UTC (rev 238) @@ -277,6 +277,20 @@ } /** + * Check for password weakness. + * + * @param Gems_User_User $user The user for e.g. name checks + * @param string $password + * @return mixed String or array of strings containing warning messages + */ + public function reportPasswordWeakness(Gems_User_User $user, $password) + { + $checker = $this->_getClass('passwordChecker'); + + return $checker->reportPasswordWeakness($user, $password); + } + + /** * Sets a new user as the current user. * * @param Gems_User_User $user This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <gem...@li...> - 2011-11-21 11:22:21
|
Revision: 251 http://gemstracker.svn.sourceforge.net/gemstracker/?rev=251&view=rev Author: michieltcs Date: 2011-11-21 11:22:10 +0000 (Mon, 21 Nov 2011) Log Message: ----------- Refs #454 - introduce throttling in AskAction Modified Paths: -------------- trunk/library/classes/Gems/Default/AskAction.php trunk/library/classes/Gems/Project/ProjectSettings.php Modified: trunk/library/classes/Gems/Default/AskAction.php =================================================================== --- trunk/library/classes/Gems/Default/AskAction.php 2011-11-21 10:58:55 UTC (rev 250) +++ trunk/library/classes/Gems/Default/AskAction.php 2011-11-21 11:22:10 UTC (rev 251) @@ -215,9 +215,35 @@ $form->addElement($element); if ($this->_request->isPost()) { - if ($form->isValid($_POST)) { + $throttleSettings = $this->project->getAskThrottleSettings(); + + // Prune the database for (very) old attempts + $this->db->query("DELETE FROM gems__token_attempts WHERE gta_datetime < DATE_SUB(NOW(), INTERVAL ? second)", + $throttleSettings['period'] * 20); + + // Retrieve the number of failed attempts that occurred within the specified window + $attemptData = $this->db->fetchRow("SELECT COUNT(1) AS attempts, UNIX_TIMESTAMP(MAX(gta_datetime)) AS last " . + "FROM gems__token_attempts WHERE gta_datetime > DATE_SUB(NOW(), INTERVAL ? second)", $throttleSettings['period']); + + $remainingDelay = ($attemptData['last'] + $throttleSettings['delay']) - time(); + + if ($attemptData['attempts'] > $throttleSettings['threshold'] && $remainingDelay > 0) { + $this->escort->logger->log("Possible token brute force attack, throttling for $remainingDelay seconds", Zend_Log::ERR); + + $this->addMessage($this->_('The server is currently busy, please wait a while and try again.')); + } else if ($form->isValid($_POST)) { $this->_forward('forward'); return; + } else { + if (isset($_POST[MUtil_Model::REQUEST_ID])) { + $this->db->insert( + 'gems__token_attempts', + array( + 'gta_id_token' => $_POST[MUtil_Model::REQUEST_ID], + 'gta_ip_address' => $this->getRequest()->getClientIp() + ) + ); + } } } elseif ($id = $this->_getParam(MUtil_Model::REQUEST_ID)) { $form->populate(array(MUtil_Model::REQUEST_ID => $id)); Modified: trunk/library/classes/Gems/Project/ProjectSettings.php =================================================================== --- trunk/library/classes/Gems/Project/ProjectSettings.php 2011-11-21 10:58:55 UTC (rev 250) +++ trunk/library/classes/Gems/Project/ProjectSettings.php 2011-11-21 11:22:10 UTC (rev 251) @@ -236,6 +236,30 @@ return $this->defaultSessionTimeout; } } + + /** + * Returns an array with throttling settings for the ask + * controller + * + * @return array + */ + public function getAskThrottleSettings() + { + // Check for the 'askThrottle' config section + if (!empty($this->askThrottle)) { + return $this->askThrottle; + } else { + // Set some sensible defaults + // Detection window: 15 minutes + // Threshold: 20 requests per minute + // Delay: 10 seconds + $throttleSettings = array( + 'period' => 15 * 60, + 'threshold' => 15 * 20, + 'delay' => 10 + ); + } + } /** * Returns the super admin name, if any This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <gem...@li...> - 2011-11-21 15:51:58
|
Revision: 255 http://gemstracker.svn.sourceforge.net/gemstracker/?rev=255&view=rev Author: mennodekker Date: 2011-11-21 15:51:49 +0000 (Mon, 21 Nov 2011) Log Message: ----------- Modified Paths: -------------- trunk/library/classes/Gems/TabForm.php trunk/library/classes/Gems/Tracker/Token/TokenSelect.php Modified: trunk/library/classes/Gems/TabForm.php =================================================================== --- trunk/library/classes/Gems/TabForm.php 2011-11-21 13:02:57 UTC (rev 254) +++ trunk/library/classes/Gems/TabForm.php 2011-11-21 15:51:49 UTC (rev 255) @@ -57,7 +57,7 @@ */ public function addElement($element, $name = null, $options = null) { - if ($this->currentTab) { + if ($this->currentTab && !($element instanceof Zend_Form_Element_Hidden)) { return $this->currentTab->addElement($element, $name, $options); } else { return parent::addElement($element, $name, $options); Modified: trunk/library/classes/Gems/Tracker/Token/TokenSelect.php =================================================================== --- trunk/library/classes/Gems/Tracker/Token/TokenSelect.php 2011-11-21 13:02:57 UTC (rev 254) +++ trunk/library/classes/Gems/Tracker/Token/TokenSelect.php 2011-11-21 15:51:49 UTC (rev 255) @@ -100,7 +100,9 @@ */ public function andReceptionCodes($fields = '*') { - $this->sql_select->join('gems__reception_codes', 'gto_reception_code = grc_id_reception_code'); + $this->sql_select->join('gems__reception_codes', + 'gto_reception_code = grc_id_reception_code', + $fields); return $this; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <gem...@li...> - 2011-11-22 15:08:45
|
Revision: 268 http://gemstracker.svn.sourceforge.net/gemstracker/?rev=268&view=rev Author: michieltcs Date: 2011-11-22 15:08:39 +0000 (Tue, 22 Nov 2011) Log Message: ----------- Refs #307 - Add support for admin.ipRanges setting Modified Paths: -------------- trunk/library/classes/Gems/Project/ProjectSettings.php trunk/library/classes/Gems/User/ProjectUserDefinition.php Modified: trunk/library/classes/Gems/Project/ProjectSettings.php =================================================================== --- trunk/library/classes/Gems/Project/ProjectSettings.php 2011-11-22 14:43:01 UTC (rev 267) +++ trunk/library/classes/Gems/Project/ProjectSettings.php 2011-11-22 15:08:39 UTC (rev 268) @@ -286,6 +286,18 @@ } /** + * Returns the super admin password, if it exists + * + * @return string + */ + public function getSuperAdminIPRanges() + { + if (isset($this->admin['ipRanges'])) { + return $this->admin['ipRanges']; + } + } + + /** * Returns a salted hash on the * * @param string $value The value to hash Modified: trunk/library/classes/Gems/User/ProjectUserDefinition.php =================================================================== --- trunk/library/classes/Gems/User/ProjectUserDefinition.php 2011-11-22 14:43:01 UTC (rev 267) +++ trunk/library/classes/Gems/User/ProjectUserDefinition.php 2011-11-22 15:08:39 UTC (rev 268) @@ -76,7 +76,7 @@ 'user_style' => 'gems', 'user_organization_id' => $organization, 'user_organization_name' => 'SUPER ADMIN', - 'user_allowed_ip_ranges' => '', + 'user_allowed_ip_ranges' => $this->project->getSuperAdminIPRanges(), 'allowedOrgs' => array($organization => 'SUPER ADMIN') ); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <gem...@li...> - 2011-11-28 10:49:58
|
Revision: 294 http://gemstracker.svn.sourceforge.net/gemstracker/?rev=294&view=rev Author: matijsdejong Date: 2011-11-28 10:49:52 +0000 (Mon, 28 Nov 2011) Log Message: ----------- Organizations can now be told they have respondents/ Modified Paths: -------------- trunk/library/classes/Gems/Default/RespondentAction.php trunk/library/classes/Gems/User/Organization.php Modified: trunk/library/classes/Gems/Default/RespondentAction.php =================================================================== --- trunk/library/classes/Gems/Default/RespondentAction.php 2011-11-28 10:41:05 UTC (rev 293) +++ trunk/library/classes/Gems/Default/RespondentAction.php 2011-11-28 10:49:52 UTC (rev 294) @@ -176,6 +176,11 @@ public function afterSave(array $data, $isNew) { + if ($isNew) { + // Tell the organization it has at least one user + $org = $this->loader->getOrganization($data['gr2o_id_organization']); + $org->setHasRespondents($data['grs_id_user']); + } $this->openedRespondent($data['gr2o_patient_nr'], $data['gr2o_id_organization'], $data['grs_id_user']); return true; } Modified: trunk/library/classes/Gems/User/Organization.php =================================================================== --- trunk/library/classes/Gems/User/Organization.php 2011-11-28 10:41:05 UTC (rev 293) +++ trunk/library/classes/Gems/User/Organization.php 2011-11-28 10:49:52 UTC (rev 294) @@ -281,10 +281,42 @@ return $this->_organizationData['gor_welcome']; } + /** + * Empty the cache of the organization + * + * @return Gems_User_Organization (continutation pattern) + */ public function invalidateCache() { if ($this->cache) { $cacheId = $this->_getCacheId(); $this->cache->remove($cacheId); } + return $this; } + + /** + * Tell the organization there is at least one respondent attached to it. + * + * Does nothing if this is already known. + * + * @param int $userId The current user + * @return Gems_User_Organization (continutation pattern) + */ + public function setHasRespondents($userId) + { + if (0 == $this->_organizationData['gor_has_respondents']) { + $this->_organizationData['gor_has_respondents'] = 1; + + $values['gor_has_respondents'] = 1; + $values['gor_changed'] = new Zend_Db_Expr('CURRENT_TIMESTAMP'); + $values['gor_changed_by'] = $userId; + + $where = $this->db->quoteInto('gor_id_organization = ?', $this->_organizationId); + + $this->db->update('gems__organizations', $values, $where); + $this->invalidateCache(); + } + + return $this; + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <gem...@li...> - 2011-12-15 11:26:31
|
Revision: 355 http://gemstracker.svn.sourceforge.net/gemstracker/?rev=355&view=rev Author: mennodekker Date: 2011-12-15 11:26:22 +0000 (Thu, 15 Dec 2011) Log Message: ----------- StaffAction now uses it's own model instead of the joinmodel and now handles saving the password field when needed, no dependency on adding a password field to the model anymore possible improvements: handle creation of a user without setting a password (generate one and send), sending welcome email?, reset password on first login etc. Modified Paths: -------------- trunk/library/classes/Gems/Default/StaffAction.php trunk/library/classes/Gems/Model.php trunk/library/classes/Gems/User/UserLoader.php Modified: trunk/library/classes/Gems/Default/StaffAction.php =================================================================== --- trunk/library/classes/Gems/Default/StaffAction.php 2011-12-13 21:00:25 UTC (rev 354) +++ trunk/library/classes/Gems/Default/StaffAction.php 2011-12-15 11:26:22 UTC (rev 355) @@ -111,15 +111,7 @@ $definition = $this->loader->getUserLoader()->getUserDefinition($data['gul_user_class'].'Definition'); if ($definition->canSetPassword()) { - //@@TODO: Should we handle it like this? The userdef has a setpassword method... - if ($definition instanceof Gems_User_StaffUserDefinition) { - Gems_Model::addUserPassword($model); - $passwordField = 'gup_password'; - $model->setOnSave($passwordField, array($this->project, 'getValueHash')); - } elseif ($definition instanceof Gems_User_OldStaffUserDefinition) { - $passwordField = 'gsf_password'; - $model->setOnSave($passwordField, array($this, 'getOldPasswordHash')); - } + $passwordField = 'fld_password'; } $model->set('gsf_id_primary_group', 'multiOptions', MUtil_Lazy::call($dbLookup->getAllowedStaffGroups)); Modified: trunk/library/classes/Gems/Model.php =================================================================== --- trunk/library/classes/Gems/Model.php 2011-12-13 21:00:25 UTC (rev 354) +++ trunk/library/classes/Gems/Model.php 2011-12-15 11:26:22 UTC (rev 355) @@ -222,7 +222,7 @@ public function getStaffModel() { - $model = new Gems_Model_JoinModel('staff', 'gems__staff', 'gsf'); + $model = $this->_loadClass('StaffModel', true); $this->addUserLogin($model, 'gsf_login', 'gsf_id_organization'); $this->setAsGemsUserId($model, 'gsf_id_user'); Modified: trunk/library/classes/Gems/User/UserLoader.php =================================================================== --- trunk/library/classes/Gems/User/UserLoader.php 2011-12-13 21:00:25 UTC (rev 354) +++ trunk/library/classes/Gems/User/UserLoader.php 2011-12-15 11:26:22 UTC (rev 355) @@ -249,10 +249,10 @@ protected function getUserClassInfo($login_name, $organization) { if ((null == $login_name) || (null == $organization)) { - return array('NoLoginDefinition', $organization); + return array(self::USER_NOLOGIN . 'Definition', $organization); } if ($this->isProjectUser($login_name)) { - return array('ProjectUserDefinition', $organization); + return array(self::USER_PROJECT . 'Definition', $organization); } try { @@ -324,7 +324,7 @@ return array(self::USER_OLD_STAFF . 'Definition', $organization); } - return array('NoLoginDefinition', $organization); + return array(self::USER_NOLOGIN . 'Definition', $organization); } protected function isProjectUser($login_name) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |