You can subscribe to this list here.
| 2011 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
(84) |
Oct
(70) |
Nov
(164) |
Dec
(71) |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 2012 |
Jan
(52) |
Feb
(77) |
Mar
(70) |
Apr
(58) |
May
(81) |
Jun
(74) |
Jul
(87) |
Aug
(30) |
Sep
(45) |
Oct
(37) |
Nov
(51) |
Dec
(31) |
| 2013 |
Jan
(47) |
Feb
(29) |
Mar
(40) |
Apr
(33) |
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
|
From: <gem...@li...> - 2011-11-14 12:10:59
|
Revision: 205
http://gemstracker.svn.sourceforge.net/gemstracker/?rev=205&view=rev
Author: matijsdejong
Date: 2011-11-14 12:10:52 +0000 (Mon, 14 Nov 2011)
Log Message:
-----------
Merged changes from main branch
Modified Paths:
--------------
branches/newUser2/classes/Gems/Cookies.php
branches/newUser2/classes/Gems/Default/DatabaseAction.php
branches/newUser2/classes/Gems/Default/UpgradeAction.php
branches/newUser2/classes/Gems/Tracker/Token.php
branches/newUser2/classes/Gems/Tracker.php
branches/newUser2/classes/Gems/UpgradesAbstract.php
branches/newUser2/classes/GemsEscort.php
Property Changed:
----------------
branches/newUser2/
Property changes on: branches/newUser2
___________________________________________________________________
Modified: svn:mergeinfo
- /branches/newUser:113-150
/trunk/library:177-190
+ /branches/newUser:113-150
/trunk/library:177-190,192-195
Modified: branches/newUser2/classes/Gems/Cookies.php
===================================================================
--- branches/newUser2/classes/Gems/Cookies.php 2011-11-14 11:58:57 UTC (rev 204)
+++ branches/newUser2/classes/Gems/Cookies.php 2011-11-14 12:10:52 UTC (rev 205)
@@ -46,7 +46,7 @@
*/
class Gems_Cookies
{
- const LOCALE_COOKIE = 'gems_locale';
+ const LOCALE_COOKIE = 'gems_locale';
const ORGANIZATION_COOKIE = 'gems_organization';
/**
Modified: branches/newUser2/classes/Gems/Default/DatabaseAction.php
===================================================================
--- branches/newUser2/classes/Gems/Default/DatabaseAction.php 2011-11-14 11:58:57 UTC (rev 204)
+++ branches/newUser2/classes/Gems/Default/DatabaseAction.php 2011-11-14 12:10:52 UTC (rev 205)
@@ -382,7 +382,7 @@
$table->setAsFormLayout($form, true, true);
$table['tbody'][0][0]->class = 'label'; // Is only one row with formLayout, so all in output fields get class.
- if ($links = $this->createMenuLinks(10)) {
+ if ($links = $this->createMenuLinks(1)) {
$table->tf(); // Add empty cell, no label
$linksCell = $table->tf($links);
}
Modified: branches/newUser2/classes/Gems/Default/UpgradeAction.php
===================================================================
--- branches/newUser2/classes/Gems/Default/UpgradeAction.php 2011-11-14 11:58:57 UTC (rev 204)
+++ branches/newUser2/classes/Gems/Default/UpgradeAction.php 2011-11-14 12:10:52 UTC (rev 205)
@@ -92,7 +92,7 @@
if ($menuItem = $this->menu->find(array('controller' => $this->_getParam('controller'), 'action' => 'show', 'allowed' => true))) {
$this->html->br();
- $this->html[] = $menuItem->toActionLinkLower($this->getRequest(), array('id'=>$context));
+ $this->html[] = $menuItem->toActionLinkLower($this->getRequest(), array('id'=>$context), $this->_('Back'));
}
}
@@ -181,6 +181,10 @@
} else {
$this->html[] = sprintf($this->_('Context %s not found!'), $context);
}
+
+ if ($parentItem = $this->menu->getCurrent()->getParent()) {
+ $this->html[] = $parentItem->toActionLink($this->getRequest(), $this->_('Cancel'));
+ }
}
public function getTopicTitle() {
Modified: branches/newUser2/classes/Gems/Tracker/Token.php
===================================================================
--- branches/newUser2/classes/Gems/Tracker/Token.php 2011-11-14 11:58:57 UTC (rev 204)
+++ branches/newUser2/classes/Gems/Tracker/Token.php 2011-11-14 12:10:52 UTC (rev 205)
@@ -119,12 +119,6 @@
/**
*
- * @var Gems_Tracker_Track
- */
- protected $track;
-
- /**
- *
* @var Gems_Tracker
*/
protected $tracker;
Modified: branches/newUser2/classes/Gems/Tracker.php
===================================================================
--- branches/newUser2/classes/Gems/Tracker.php 2011-11-14 11:58:57 UTC (rev 204)
+++ branches/newUser2/classes/Gems/Tracker.php 2011-11-14 12:10:52 UTC (rev 205)
@@ -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);
Modified: branches/newUser2/classes/Gems/UpgradesAbstract.php
===================================================================
--- branches/newUser2/classes/Gems/UpgradesAbstract.php 2011-11-14 11:58:57 UTC (rev 204)
+++ branches/newUser2/classes/Gems/UpgradesAbstract.php 2011-11-14 12:10:52 UTC (rev 205)
@@ -25,8 +25,6 @@
* (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
@@ -35,10 +33,10 @@
*/
/**
- * Short description for Upgrades
+ * This class can take care of handling upgrades that can not be achieved by a
+ * simple db patch. For example adding an extra attribute to all token tables
+ * in LimeSurvey needs a simple loop.
*
- * Long description for class Upgrades (if any)...
- *
* @package Gems
* @subpackage Upgrades
* @copyright Copyright (c) 2011 Erasmus MC
@@ -142,6 +140,18 @@
$this->_messages = array();
}
+ /**
+ * Execute upgrades for the given $context
+ *
+ * When no $to or $from are given, the given $context will be upgraded from the current level
+ * to the max level. Otherwise the $from and/or $to will be used to determine what upgrades
+ * to execute.
+ *
+ * @param string $context The context to execute the upgrades for
+ * @param int|null $to The level to upgrade to
+ * @param int|null $from The level to start the upgrade on
+ * @return false|int The achieved upgrade level or false on failure
+ */
public function execute($context, $to = null, $from = null)
{
if(is_null($to)) {
@@ -182,21 +192,32 @@
return $success;
}
+ /**
+ * Retrieve the current context
+ *
+ * @return string
+ */
public function getContext() {
return $this->_context;
}
+ /**
+ * Get the current upgrade level for the given $context
+ *
+ * @param string $context
+ * @return int
+ */
public function getLevel($context)
{
if(isset($this->_info->$context)) {
- return $this->_info->$context;
+ return intval($this->_info->$context);
} else {
return 0;
}
}
/**
- * Get the highest level for the given context
+ * Get the highest level for the given $context
*
* @param string|null $context
* @return int
@@ -251,6 +272,11 @@
return ++$level;
}
+ /**
+ * Get all messages that were recorded during the upgrade process
+ *
+ * @return array
+ */
public function getMessages()
{
return $this->_messages;
@@ -273,6 +299,12 @@
return array();
}
+ /**
+ * Retrieve info about the $requestedContext or all contexts when omitted
+ *
+ * @param string $requestedContext
+ * @return array
+ */
public function getUpgradesInfo($requestedContext = null)
{
$result = array();
@@ -293,6 +325,19 @@
}
}
+ /**
+ * Register an upgrade in the stack, it can be executed by using $this->execute
+ *
+ * Index and context are optional and will be generated when omitted. For the
+ * user interface to be clear $info should provide a good description of what
+ * the upgrade does.
+ *
+ * @param array|string $callback A valid callback, either string for a method of the current class or array otherwise
+ * @param string $info A descriptive message about what this upgrade does
+ * @param int $index The number of the upgrade
+ * @param string $context The context to which this upgrade applies
+ * @return boolean
+ */
public function register($callback, $info = null, $index = null, $context = null)
{
if (is_string($callback)) {
@@ -325,10 +370,27 @@
return false;
}
+ /**
+ * Change the active context
+ *
+ * Usefull when adding upgrades in the construct to save typing
+ *
+ * @param string $context
+ */
public function setContext($context) {
$this->_context = $context;
}
+ /**
+ * Set the upgrade level for the given $context to a certain level
+ *
+ * Will only update when the $level is higher than the achieved level, unless
+ * when $force = true when it will always update.
+ *
+ * @param string $context
+ * @param int $level
+ * @param boolean $force
+ */
protected function setLevel($context, $level = null, $force = false)
{
if (!is_null($level) &&
Modified: branches/newUser2/classes/GemsEscort.php
===================================================================
--- branches/newUser2/classes/GemsEscort.php 2011-11-14 11:58:57 UTC (rev 204)
+++ branches/newUser2/classes/GemsEscort.php 2011-11-14 12:10:52 UTC (rev 205)
@@ -1059,6 +1059,7 @@
*/
public function getCurrentOrganization()
{
+ /*
if ($this instanceof Gems_Project_Organization_MultiOrganizationInterface) {
return $this->getUserOrganization();
}
@@ -1066,11 +1067,12 @@
if ($this instanceof Gems_Project_Organization_SingleOrganizationInterface) {
return $this->getRespondentOrganization();
}
+ */
if (isset($this->session->user_organization_id)) {
return $this->session->user_organization_id;
} else {
- return 0;
+ return Gems_Cookies::getOrganization(Zend_Controller_Front::getInstance()->getRequest());
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <gem...@li...> - 2011-11-14 11:59:04
|
Revision: 204
http://gemstracker.svn.sourceforge.net/gemstracker/?rev=204&view=rev
Author: matijsdejong
Date: 2011-11-14 11:58:57 +0000 (Mon, 14 Nov 2011)
Log Message:
-----------
#31 ready, respondents login can be added
Modified Paths:
--------------
branches/newUser2/classes/Gems/Default/IndexAction.php
branches/newUser2/classes/Gems/Default/OptionAction.php
branches/newUser2/classes/Gems/User/StaffUserDefinition.php
branches/newUser2/classes/Gems/User/User.php
branches/newUser2/classes/Gems/User/UserDefinitionAbstract.php
branches/newUser2/classes/Gems/User/UserDefinitionInterface.php
branches/newUser2/classes/GemsEscort.php
Modified: branches/newUser2/classes/Gems/Default/IndexAction.php
===================================================================
--- branches/newUser2/classes/Gems/Default/IndexAction.php 2011-11-14 10:21:54 UTC (rev 203)
+++ branches/newUser2/classes/Gems/Default/IndexAction.php 2011-11-14 11:58:57 UTC (rev 204)
@@ -105,6 +105,16 @@
}
/**
+ * Returns an element for keeping a reset key.
+ *
+ * @return Zend_Form_Element_Hidden
+ */
+ protected function _getKeyElement()
+ {
+ return new Zend_Form_Element_Hidden('key');
+ }
+
+ /**
* Returns a login form
*
* @return Gems_Form
@@ -187,6 +197,7 @@
protected function _getResetForm()
{
$form = $this->_getBasicForm($this->_('Reset password for %s application'));
+ $form->addElement($this->_getKeyElement());
$form->addElement($this->_getOrganizationElement());
$form->addElement($this->_getUserLoginElement());
$form->addElement($this->_getSubmitButton($this->_('Reset password')));
@@ -326,42 +337,25 @@
$this->view->setScriptPath(GEMS_LIBRARY_DIR . '/views/scripts' );
$request = $this->getRequest();
- if ($key = $request->getParam('key')) {
- /*
- $sql = $this->db->quoteInto("SELECT gus_id_user, gsf_email FROM gems__users INNER JOIN gems__staff ON gus_id_user = gsf_id_user WHERE gus_reset_key = ?", $key);
- $result = $this->db->fetchRow($sql);
+ $form = $this->_getResetForm();
+ if ($request->isPost() && $form->isValid($request->getPost())) {
- if (!empty($result)) {
- // generate new password
- $password = $this->escort->getRandomPassword();
- $passwordHash = $this->escort->passwordHash(null, $password, false);
+ $user = $this->loader->getUser($request->getParam('userlogin'), $request->getParam('organization'));
- $mail->setSubject('New password');
- $mail->setBodyText('Your new password has been generated. Your new password is: ' . $password);
-
- $mail->addTo($result['gsf_email']);
-
- try {
- $mail->send();
- $this->addMessage($this->_('An e-mail was sent containing your new password'));
- $this->db->update('gems__users', array('gus_reset_key' => new Zend_Db_Expr('NULL'), 'gus_reset_requested' => new Zend_Db_Expr('NULL'), 'gus_password' => $passwordHash), 'gus_id_user = ' . $result['gus_id_user']);
- $this->_reroute(array('action' => 'index'), true);
- } catch (Exception $e) {
- $this->addMessage($this->_('Unable to send e-mail'));
- throw $e;
- }
- } else {
- $this->addMessage($this->_('Unknown request'));
- } // */
-
- } else {
- $form = $this->_getResetForm();
- if ($request->isPost() && $form->isValid($request->getPost())) {
-
- $user = $this->loader->getUser($request->getParam('userlogin'), $request->getParam('organization'));
-
- If ($user->canResetPassword()) {
-
+ If ($user->canResetPassword()) {
+ if ($key = $request->getParam('key')) {
+ // Key has been passed by mail
+ if ($user->checkPasswordResetKey($key)) {
+ $user->setPasswordResetRequired(true);
+ $user->setAsCurrentUser();
+ $this->addMessage($this->_('Reset accepted, enter your new password.'));
+ $user->gotoStartPage($this->menu, $request);
+ return;
+ } else {
+ $this->addMessage($this->_('This key timed out or does not belong to this user.'));
+ }
+ } else {
+ // P{ass mail by key
$mail = new MUtil_Mail();
$mail->setFrom('mj...@ma...');
$mail->addTo($user->getEmailAddress(), $user->getFullName());
@@ -375,22 +369,26 @@
$url = $this->util->getCurrentURI('index/resetpassword/key/' . $key);
- $mail->setSubject('Password reset requested');
- $mail->setBodyText('To reset your password, please click this link: ' . $url);
+ $mail->setSubject($this->_('Password reset requested'));
+ $mail->setBodyText(sprintf($this->_('To reset your password for %s, please click this link: %s'), GEMS_PROJECT_NAME_UC, $url));
try {
$mail->send();
- $this->addMessage($this->_('Follow the instructions in the e-mail.'));
+ $this->addMessage($this->_('We sent you an e-mail with a reset link. Click on the link in the e-mail.'));
} catch (Exception $e) {
$this->addMessage($this->_('Unable to send e-mail.'));
throw $e;
}
- } else {
- $this->addMessage($this->_('No such user found or no e-mail address known or user cannot be reset.'));
}
+ } else {
+ $this->addMessage($this->_('No such user found or no e-mail address known or user cannot be reset.'));
}
- $this->view->form = $form;
}
+ if ($request->getParam('key')) {
+ $this->addMessage($this->_('We received your password reset key.'));
+ $this->addMessage($this->_('Please enter the organization and username belonging to this key.'));
+ }
+ $this->view->form = $form;
}
}
Modified: branches/newUser2/classes/Gems/Default/OptionAction.php
===================================================================
--- branches/newUser2/classes/Gems/Default/OptionAction.php 2011-11-14 10:21:54 UTC (rev 203)
+++ branches/newUser2/classes/Gems/Default/OptionAction.php 2011-11-14 11:58:57 UTC (rev 204)
@@ -85,7 +85,9 @@
return;
}
- if ($user->hasPassword()) {
+ if ($user->isPasswordResetRequired()) {
+ $this->menu->setVisible(false);
+ } elseif ($user->hasPassword()) {
// Field current password
//
// This is only used when the password is already set, which may not always be the case
@@ -151,7 +153,7 @@
$table->setAsFormLayout($form, true, true);
$table['tbody'][0][0]->class = 'label'; // Is only one row with formLayout, so all in output fields get class.
- if ($links = $this->createMenuLinks()) {
+ if (! $user->isPasswordResetRequired() && ($links = $this->createMenuLinks())) {
$table->tf(); // Add empty cell, no label
$linksCell = $table->tf($links);
}
Modified: branches/newUser2/classes/Gems/User/StaffUserDefinition.php
===================================================================
--- branches/newUser2/classes/Gems/User/StaffUserDefinition.php 2011-11-14 10:21:54 UTC (rev 203)
+++ branches/newUser2/classes/Gems/User/StaffUserDefinition.php 2011-11-14 11:58:57 UTC (rev 204)
@@ -115,6 +115,28 @@
}
/**
+ * Check whether a reset key is really linked to a user.
+ *
+ * @param Gems_User_User $user The user the key was created for (hopefully).
+ * @param string The key
+ * @return boolean
+ */
+ public function checkPasswordResetKey(Gems_User_User $user, $key)
+ {
+ $model = new MUtil_Model_TableModel('gems__user_passwords');
+
+ $filter['gup_id_user'] = $user->getUserLoginId();
+ $filter[] = 'DATE_ADD(gup_reset_requested, INTERVAL 24 HOUR) >= CURRENT_TIMESTAMP';
+
+ $row = $model->loadFirst($filter);
+ if ($row && $row['gup_reset_key']) {
+ return $key == $row['gup_reset_key'];
+ }
+
+ return false;
+ }
+
+ /**
* Return a password reset key
*
* @param Gems_User_User $user The user to create a key for.
@@ -127,7 +149,7 @@
$data['gup_id_user'] = $user->getUserLoginId();
- $row = $model->loadFirst($data);
+ $row = $model->loadFirst($data + array('DATE_ADD(gup_reset_requested, INTERVAL 24 HOUR) >= CURRENT_TIMESTAMP'));
if ($row && $row['gup_reset_key']) {
// Keep using the key.
$data['gup_reset_key'] = $row['gup_reset_key'];
@@ -166,6 +188,8 @@
'user_organization_id'=>'gor_id_organization',
'user_organization_name'=>'gor_name',
'user_style' => 'gor_style'))
+ ->joinLeft('gems__user_passwords', 'gul_id_user = gup_id_user',
+ array('user_password_reset' => 'gup_reset_required'))
->where('ggp_group_active = 1')
->where('gor_active = 1')
->where('gsf_active = 1')
@@ -210,8 +234,10 @@
*/
public function setPassword(Gems_User_User $user, $password)
{
- $data['gup_id_user'] = $user->getUserLoginId();
- $data['gup_reset_required'] = 0;
+ $data['gup_id_user'] = $user->getUserLoginId();
+ $data['gup_reset_key'] = null;
+ $data['gup_reset_requested'] = null;
+ $data['gup_reset_required'] = 0;
if (null === $password) {
// Passwords may be emptied.
$data['gup_password'] = null;
Modified: branches/newUser2/classes/Gems/User/User.php
===================================================================
--- branches/newUser2/classes/Gems/User/User.php 2011-11-14 10:21:54 UTC (rev 203)
+++ branches/newUser2/classes/Gems/User/User.php 2011-11-14 11:58:57 UTC (rev 204)
@@ -204,6 +204,17 @@
}
/**
+ * Check whether a reset key is really linked to this user.
+ *
+ * @param string The key
+ * @return boolean
+ */
+ public function checkPasswordResetKey($key)
+ {
+ return $this->definition->checkPasswordResetKey($this, $key);
+ }
+
+ /**
* Should be called after answering the request to allow the Target
* to check if all required registry values have been set correctly.
*
@@ -319,6 +330,16 @@
}
/**
+ * Returns the current user role.
+ *
+ * @return string
+ */
+ public function getRole()
+ {
+ return $this->_getVar('user_role');
+ }
+
+ /**
* Returns the user id, that identifies this user within this installation.
*
* One user id might be connected to multiple logins for multiple organizations.
@@ -352,6 +373,35 @@
}
/**
+ * Redirects the user to his/her start page.
+ *
+ * @param Gems_Menu $menu
+ * @param Zend_Controller_Request_Abstract $request
+ * @return Gems_Menu_SubMenuItem
+ */
+ public function gotoStartPage(Gems_Menu $menu, Zend_Controller_Request_Abstract $request)
+ {
+ if ($this->isPasswordResetRequired()) {
+ // Set menu OFF
+ $menu->setVisible(false);
+
+ $menuItem = $menu->findFirst(array($request->getControllerKey() => 'option', $request->getActionKey() => 'change-password'));
+ // This may not yet be true, but is needed for the redirect.
+ $menuItem->set('allowed', true);
+ $menuItem->set('visible', true);
+ } else {
+ $menuItem = $menu->findFirst(array('allowed' => true, 'visible' => true));
+ }
+
+ if ($menuItem) {
+ $redirector = Zend_Controller_Action_HelperBroker::getStaticHelper('redirector');
+ $redirector->gotoRoute($menuItem->toRouteUrl($request));
+ }
+
+ return $menuItem;
+ }
+
+ /**
* Return true if this user has a password.
*
* @return boolean
@@ -368,7 +418,7 @@
*/
public function hasPassword()
{
- return $this->definition->hasPassword();
+ return $this->definition->hasPassword($this);
}
/**
@@ -401,12 +451,22 @@
}
/**
+ * True when this user must enter a new password.
+ *
+ * @return boolean
+ */
+ public function isPasswordResetRequired()
+ {
+ return (boolean) $this->_getVar('user_password_reset');
+ }
+
+ /**
* Set this user as the current user.
*
* This means that the data about this user will be stored in a session.
*
* @param boolean $signalLoader Do not set, except from UserLoader
- * @return Gems_User_UserAbstract (continuation pattern)
+ * @return Gems_User_User (continuation pattern)
*/
public function setAsCurrentUser($signalLoader = true)
{
@@ -436,7 +496,7 @@
* Set the password, if allowed for this user type.
*
* @param string $password
- * @return Gems_User_UserAbstract (continuation pattern)
+ * @return Gems_User_User (continuation pattern)
*/
public function setPassword($password)
{
@@ -445,12 +505,23 @@
}
/**
+ *
+ * @param boolean $reset
+ * @return Gems_User_User (continuation pattern)
+ */
+ public function setPasswordResetRequired($reset = true)
+ {
+ $this->_setVar('user_password_reset', (boolean) $reset);
+ return $this;
+ }
+
+ /**
* Unsets this user as the current user.
*
* This means that the data about this user will no longer be stored in a session.
*
* @param boolean $signalLoader Do not set, except from UserLoader
- * @return Gems_User_UserAbstract (continuation pattern)
+ * @return Gems_User_User (continuation pattern)
*/
public function unsetAsCurrentUser($signalLoader = true)
{
Modified: branches/newUser2/classes/Gems/User/UserDefinitionAbstract.php
===================================================================
--- branches/newUser2/classes/Gems/User/UserDefinitionAbstract.php 2011-11-14 10:21:54 UTC (rev 203)
+++ branches/newUser2/classes/Gems/User/UserDefinitionAbstract.php 2011-11-14 11:58:57 UTC (rev 204)
@@ -77,6 +77,18 @@
}
/**
+ * Check whether a reset key is really linked to a user.
+ *
+ * @param Gems_User_User $user The user the key was created for (hopefully).
+ * @param string The key
+ * @return string
+ */
+ public function checkPasswordResetKey(Gems_User_User $user, $key)
+ {
+ throw new Gems_Exception_Coding(sprintf('A password reset key cannot be issued for %s users.', get_class($this)));
+ }
+
+ /**
* Return a password reset key
*
* @param Gems_User_User $user The user to create a key for.
Modified: branches/newUser2/classes/Gems/User/UserDefinitionInterface.php
===================================================================
--- branches/newUser2/classes/Gems/User/UserDefinitionInterface.php 2011-11-14 10:21:54 UTC (rev 203)
+++ branches/newUser2/classes/Gems/User/UserDefinitionInterface.php 2011-11-14 11:58:57 UTC (rev 204)
@@ -79,6 +79,15 @@
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).
+ * @param string The key
+ * @return string
+ */
+ public function checkPasswordResetKey(Gems_User_User $user, $key);
+
+ /**
* Return a password reset key
*
* @param Gems_User_User $user The user to create a key for.
Modified: branches/newUser2/classes/GemsEscort.php
===================================================================
--- branches/newUser2/classes/GemsEscort.php 2011-11-14 10:21:54 UTC (rev 203)
+++ branches/newUser2/classes/GemsEscort.php 2011-11-14 11:58:57 UTC (rev 204)
@@ -1440,12 +1440,15 @@
*/
public function routeShutdown(Zend_Controller_Request_Abstract $request)
{
+ $loader = $this->getLoader();
+ $user = $loader->getCurrentUser();
+
// MUtil_Echo::r($request->getParams(), 'params');
// MUtil_Echo::r($request->getUserParams(), 'userparams');
// Load the menu. As building the menu can depend on all resources and the request, we do it here.
//
// PS: The REQUEST is needed because otherwise the locale for translate is not certain.
- $this->menu = $this->getLoader()->createMenu($this);
+ $this->menu = $loader->createMenu($this);
$this->_updateVariable('menu');
/**
@@ -1453,7 +1456,7 @@
* directory with the name lock.txt
*/
if ($this->getUtil()->getMaintenanceLock()->isLocked()) {
- if ($this->session->user_id && $this->session->user_role !== 'master') {
+ if ($user->isActive() && $user->getRole() !== 'master') {
//Still allow logoff so we can relogin as master
if (!('index' == $request->getControllerName() && 'logoff' == $request->getActionName())) {
$this->setError(
@@ -1461,6 +1464,7 @@
401,
$this->_('System is in maintenance mode'));
}
+ $user->unsetAsCurrentUser();
} else {
$this->addMessage($this->_('System is in maintenance mode'));
MUtil_Echo::r($this->_('System is in maintenance mode'));
@@ -1470,12 +1474,7 @@
// Gems does not use index/index
if (('index' == $request->getControllerName()) && ('index' == $request->getActionName())) {
// Instead Gems routes to the first available menu item when this is the request target
- if ($menuItem = $this->menu->findFirst(array('allowed' => true, 'visible' => true))) {
- $redirector = Zend_Controller_Action_HelperBroker::getStaticHelper('redirector');
- $redirector->gotoRoute($menuItem->toRouteUrl($request));
- //$menuItem->applyToRequest($request);
- //$this->setControllerDirectory($request); // Maybe the controller directory to be used changed
- } else {
+ if (! $user->gotoStartPage($this->menu, $request)) {
$this->setError(
$this->_('No access to site.'),
401,
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <gem...@li...> - 2011-11-14 10:22:00
|
Revision: 203
http://gemstracker.svn.sourceforge.net/gemstracker/?rev=203&view=rev
Author: matijsdejong
Date: 2011-11-14 10:21:54 +0000 (Mon, 14 Nov 2011)
Log Message:
-----------
Bug found when moving pulse installation
Modified Paths:
--------------
branches/newUser2/classes/Gems/Email/TemplateMailer.php
Modified: branches/newUser2/classes/Gems/Email/TemplateMailer.php
===================================================================
--- branches/newUser2/classes/Gems/Email/TemplateMailer.php 2011-11-11 17:48:42 UTC (rev 202)
+++ branches/newUser2/classes/Gems/Email/TemplateMailer.php 2011-11-14 10:21:54 UTC (rev 203)
@@ -516,7 +516,7 @@
$cdata['grco_address'] = substr($to, 0, 120);
$cdata['grco_sender'] = substr($from, 0, 120);
- $cdata['grco_id_message'] = $this->_templateId;
+ $cdata['grco_id_message'] = $this->_templateId ? $this->_templateId : null;
$cdata['grco_changed'] = $this->_changeDate;
$cdata['grco_changed_by'] = $uid;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <gem...@li...> - 2011-11-11 17:48:50
|
Revision: 202
http://gemstracker.svn.sourceforge.net/gemstracker/?rev=202&view=rev
Author: matijsdejong
Date: 2011-11-11 17:48:42 +0000 (Fri, 11 Nov 2011)
Log Message:
-----------
Continuing #31: reset password now does send the mail, but the mail cannot be handled yet.
Extended possibilities of UserDefinitionInterface.php
Found bug in DatabaseModelAbstract.php: did not handle non-date strings well.
Modified Paths:
--------------
branches/newUser2/classes/Gems/Cookies.php
branches/newUser2/classes/Gems/Default/IndexAction.php
branches/newUser2/classes/Gems/Default/OptionAction.php
branches/newUser2/classes/Gems/Project/ProjectSettings.php
branches/newUser2/classes/Gems/User/StaffUserDefinition.php
branches/newUser2/classes/Gems/User/User.php
branches/newUser2/classes/Gems/User/UserDefinitionAbstract.php
branches/newUser2/classes/Gems/User/UserDefinitionInterface.php
branches/newUser2/classes/Gems/User/UserLoader.php
branches/newUser2/classes/MUtil/Model/DatabaseModelAbstract.php
Modified: branches/newUser2/classes/Gems/Cookies.php
===================================================================
--- branches/newUser2/classes/Gems/Cookies.php 2011-11-11 11:41:20 UTC (rev 201)
+++ branches/newUser2/classes/Gems/Cookies.php 2011-11-11 17:48:42 UTC (rev 202)
@@ -26,7 +26,7 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
- *
+ *
* @package Gems
* @subpackage Cookies
* @author Matijs de Jong <mj...@ma...>
@@ -127,7 +127,9 @@
*/
public static function setOrganization($organization, $basepath = '/')
{
- // Set the cookie for 30 days
- return self::set(self::ORGANIZATION_COOKIE, $organization, 30, $basepath);
+ if ($organization) {
+ // Set the cookie for 30 days
+ return self::set(self::ORGANIZATION_COOKIE, $organization, 30, $basepath);
+ }
}
}
Modified: branches/newUser2/classes/Gems/Default/IndexAction.php
===================================================================
--- branches/newUser2/classes/Gems/Default/IndexAction.php 2011-11-11 11:41:20 UTC (rev 201)
+++ branches/newUser2/classes/Gems/Default/IndexAction.php 2011-11-11 17:48:42 UTC (rev 202)
@@ -66,20 +66,84 @@
public $menu;
/**
- * New version of login form
+ * @var Gems_Project_ProjectSettings
+ */
+ public $project;
+
+ /**
+ * Returns a link for the token input page.
*
+ * @return MUtil_Form_Element_Html
+ */
+ protected function _getAskTokenLinkElement()
+ {
+ // Veld token
+ $element = new MUtil_Form_Element_Html('askToken');
+ $element->br();
+ $element->actionLink(array('controller' => 'ask', 'action' => 'token'), $this->_('Enter your token...'));
+
+ return $element;
+ }
+
+ /**
+ * Returns a basic form for this action.
+ *
+ * @param $description Optional description, %s is filled with project name.
* @return Gems_Form
*/
- protected function _getLoginForm()
+ protected function _getBasicForm($description = null)
{
Gems_Html::init();
- $delayFactor = (isset($this->project->account) && isset($this->project->account['delayFactor']) ? $this->project->account['delayFactor'] : null);
-
$form = new Gems_Form(array('labelWidthFactor' => $this->labelWidthFactor));
$form->setMethod('post');
- $form->setDescription(sprintf($this->_('Login to %s application'), $this->project->name));
+ if ($description) {
+ $form->setDescription(sprintf($description, $this->project->getName()));
+ }
+ return $form;
+ }
+
+ /**
+ * Returns a login form
+ *
+ * @return Gems_Form
+ */
+ protected function _getLoginForm()
+ {
+ $form = $this->_getBasicForm($this->_('Login to %s application'));
+ $form->addElement($this->_getOrganizationElement());
+ $form->addElement($this->_getUserLoginElement());
+ $form->addElement($this->_getPasswordElement());
+ $form->addElement($this->_getSubmitButton($this->_('Login')));
+ $form->addElement($this->_getAskTokenLinkElement());
+ $form->addElement($this->_getResetLinkElement());
+
+ return $form;
+ }
+
+ /**
+ * Returns a link to the login page
+ *
+ * @return MUtil_Form_Element_Html
+ */
+ protected function _getLoginLinkElement()
+ {
+ // Reset password
+ $element = new MUtil_Form_Element_Html('resetPassword');
+ $element->br();
+ $element->actionLink(array('controller' => 'index', 'action' => 'login'), $this->_('Back to login'));
+
+ return $element;
+ }
+
+ /**
+ * Returns an element for determining / selecting the organization.
+ *
+ * @return Zend_Form_Element_Xhtml
+ */
+ protected function _getOrganizationElement()
+ {
if ($this->escort instanceof Gems_Project_Organization_SingleOrganizationInterface) {
$element = new Zend_Form_Element_Hidden('organization');
$element->setValue($this->escort->getRespondentOrganization());
@@ -93,16 +157,17 @@
$element->setValue($this->escort->getCurrentOrganization());
}
}
- $form->addElement($element);
- // Veld inlognaam
- $element = new Zend_Form_Element_Text('userlogin');
- $element->setLabel($this->_('Username'));
- $element->setAttrib('size', 10);
- $element->setAttrib('maxlength', 20);
- $element->setRequired(true);
- $form->addElement($element);
+ return $element;
+ }
+ /**
+ * Returns a password element.
+ *
+ * @return Zend_Form_Element_Password
+ */
+ protected function _getPasswordElement()
+ {
// Veld password
$element = new Zend_Form_Element_Password('password');
$element->setLabel($this->_('Password'));
@@ -110,38 +175,86 @@
$element->setAttrib('maxlength', 20);
$element->setRequired(true);
$element->addValidator(new Gems_User_LoginPasswordValidator($this->loader->getUserLoader(), 'userlogin', 'organization', $this->translate));
- $form->addElement($element);
- // Submit knop
- $element = new Zend_Form_Element_Submit('button');
- $element->setLabel($this->_('Login'));
- $element->setAttrib('class', 'button');
- $form->addElement($element);
+ return $element;
+ }
- // Veld token
- $element = new MUtil_Form_Element_Html('askToken');
- $element->br();
- $element->actionLink(array('controller' => 'ask', 'action' => 'token'), $this->_('Enter your token...'));
- $form->addElement($element);
+ /**
+ * Gets a reset password form.
+ *
+ * @return Gems_Form
+ */
+ protected function _getResetForm()
+ {
+ $form = $this->_getBasicForm($this->_('Reset password for %s application'));
+ $form->addElement($this->_getOrganizationElement());
+ $form->addElement($this->_getUserLoginElement());
+ $form->addElement($this->_getSubmitButton($this->_('Reset password')));
+ $form->addElement($this->_getLoginLinkElement());
+ return $form;
+ }
+
+ /**
+ * Returns a link to the reset password page
+ *
+ * @return MUtil_Form_Element_Html
+ */
+ protected function _getResetLinkElement()
+ {
// Reset password
$element = new MUtil_Form_Element_Html('resetPassword');
$element->br();
$element->actionLink(array('controller' => 'index', 'action' => 'resetpassword'), $this->_('Lost password'));
- $form->addElement($element);
- return $form;
+ return $element;
}
- // Dummy: always rerouted by GemsEscort
+ /**
+ * Returns a submit button.
+ *
+ * @param string $label
+ * @return Zend_Form_Element_Submit
+ */
+ protected function _getSubmitButton($label)
+ {
+ // Submit knop
+ $element = new Zend_Form_Element_Submit('button');
+ $element->setLabel($label);
+ $element->setAttrib('class', 'button');
+
+ return $element;
+ }
+
+ /**
+ * Returns a login name element.
+ *
+ * @return Zend_Form_Element_Text
+ */
+ protected function _getUserLoginElement()
+ {
+ // Veld inlognaam
+ $element = new Zend_Form_Element_Text('userlogin');
+ $element->setLabel($this->_('Username'));
+ $element->setAttrib('size', 10);
+ $element->setAttrib('maxlength', 20);
+ $element->setRequired(true);
+
+ return $element;
+ }
+
+ /**
+ * Dummy: always rerouted by GemsEscort
+ */
public function indexAction() { }
+ /**
+ * Default login page
+ */
public function loginAction()
{
- /**
- * If already logged in, try to redirect to the first allowed and visible menu item
- * if that fails, try to reroute to respondent/index
- */
+ // If already logged in, try to redirect to the first allowed and visible menu item
+ // if that fails, try to reroute to respondent/index
if ($this->loader->getCurrentUser()->isActive()) {
if ($menuItem = $this->menu->findFirst(array('allowed' => true, 'visible' => true))) {
$redirector = Zend_Controller_Action_HelperBroker::getStaticHelper('redirector');
@@ -153,11 +266,13 @@
$form = $this->_getLoginForm();
- if ($this->_request->isPost()) {
- if ($form->isValid($_POST, false)) {
+ $request = $this->getRequest();
+ if ($request->isPost()) {
+ if ($form->isValid($request->getPost(), false)) {
- if ($user = $this->loader->getUser($_POST['userlogin'], $_POST['organization'])) {
+ $user = $this->loader->getUser($request->getParam('userlogin'), $request->getParam('organization'));
+ if ($user->isActive()) {
$user->setAsCurrentUser();
/**
@@ -182,93 +297,37 @@
// This reroutes to the first available menu page after login
$this->_reroute(array('controller' => null, 'action' => null), true);
}
+ return;
}
} else {
$errors = $form->getErrors();
-
- $this->view->form = $form;
}
- } else {
- $this->view->form = $form;
}
+ $this->view->form = $form;
}
+ /**
+ * Default logoff action
+ */
public function logoffAction()
{
$user = $this->loader->getCurrentUser();
$this->addMessage(sprintf($this->_('Good bye: %s.'), $user->getFullName()));
$user->unsetAsCurrentUser();
- // Gems_Auth::getInstance()->clearIdentity();
$this->_reroute(array('action' => 'index'), true);
}
- protected function _getResetForm()
- {
- $form = new Gems_Form(array('labelWidthFactor' => $this->labelWidthFactor));
- $form->setMethod('post');
- $form->setDescription(sprintf($this->_('Reset password for %s application'), $this->project->name));
-
- // Veld inlognaam
- $element = new Zend_Form_Element_Text('userlogin');
- $element->setLabel($this->_('Username'));
- $element->setAttrib('size', 10);
- $element->setAttrib('maxlength', 20);
- $element->setRequired(true);
- $form->addElement($element);
-
- // Submit knop
- $element = new Zend_Form_Element_Submit('button');
- $element->setLabel($this->_('Reset password'));
- $element->setAttrib('class', 'button');
- $form->addElement($element);
-
- return $form;
- }
-
+ /**
+ * Reset password page.
+ */
public function resetpasswordAction()
{
$this->view->setScriptPath(GEMS_LIBRARY_DIR . '/views/scripts' );
- $form = $this->_getResetForm();
- $mail = new MUtil_Mail();
- $mail->setFrom('no...@er...');
-
- if (isset($this->escort->project->email) && isset($this->escort->project->email['bcc'])) {
- $mail->addBcc($this->escort->project->email['bcc']);
- }
-
- /*
-
- if ($this->_request->isPost() && $form->isValid($_POST)) {
- $sql = $this->db->quoteInto("SELECT gus_id_user, gsf_email, gus_reset_key, DATEDIFF(NOW(), gus_reset_requested) AS gsf_days FROM gems__users INNER JOIN gems__staff ON gus_id_user = gsf_id_user WHERE gus_login = ?", $_POST['userlogin']);
- $result = $this->db->fetchRow($sql);
-
- if (empty($result) || empty($result['gsf_email'])) {
- $this->addMessage($this->_('No such user found or no e-mail address known'));
- } else if (!empty($result['gus_reset_key']) && $result['gsf_days'] < 1) {
- $this->addMessage($this->_('Reset e-mail already sent, please try again after 24 hours'));
- } else {
- $email = $result['gsf_email'];
- $key = md5(time() . $email);
- $url = $this->util->getCurrentURI('index/resetpassword/key/' . $key);
-
- $this->db->update('gems__user_logins', array('gus_reset_key' => $key, 'gus_reset_requested' => new Zend_Db_Expr('NOW()')), 'gus_id_user = ' . $result['gus_id_user']);
-
- $mail->setSubject('Password reset requested');
- $mail->setBodyText('To reset your password, please click this link: ' . $url);
-
- $mail->addTo($email);
-
- try {
- $mail->send();
- $this->addMessage($this->_('Follow the instructions in the e-mail'));
- } catch (Exception $e) {
- $this->addMessage($this->_('Unable to send e-mail'));
- throw $e;
- }
- }
- } else if ($key = $this->_request->getParam('key')) {
+ $request = $this->getRequest();
+ if ($key = $request->getParam('key')) {
+ /*
$sql = $this->db->quoteInto("SELECT gus_id_user, gsf_email FROM gems__users INNER JOIN gems__staff ON gus_id_user = gsf_id_user WHERE gus_reset_key = ?", $key);
$result = $this->db->fetchRow($sql);
@@ -293,9 +352,45 @@
}
} else {
$this->addMessage($this->_('Unknown request'));
+ } // */
+
+ } else {
+ $form = $this->_getResetForm();
+ if ($request->isPost() && $form->isValid($request->getPost())) {
+
+ $user = $this->loader->getUser($request->getParam('userlogin'), $request->getParam('organization'));
+
+ If ($user->canResetPassword()) {
+
+ $mail = new MUtil_Mail();
+ $mail->setFrom('mj...@ma...');
+ $mail->addTo($user->getEmailAddress(), $user->getFullName());
+
+ if (isset($this->escort->project->email) && isset($this->escort->project->email['bcc'])) {
+ $mail->addBcc($this->escort->project->email['bcc']);
+ }
+
+
+ $key = $user->getPasswordResetKey();
+
+ $url = $this->util->getCurrentURI('index/resetpassword/key/' . $key);
+
+ $mail->setSubject('Password reset requested');
+ $mail->setBodyText('To reset your password, please click this link: ' . $url);
+
+
+ try {
+ $mail->send();
+ $this->addMessage($this->_('Follow the instructions in the e-mail.'));
+ } catch (Exception $e) {
+ $this->addMessage($this->_('Unable to send e-mail.'));
+ throw $e;
+ }
+ } else {
+ $this->addMessage($this->_('No such user found or no e-mail address known or user cannot be reset.'));
+ }
}
- } // */
-
- $this->view->form = $form;
+ $this->view->form = $form;
+ }
}
}
Modified: branches/newUser2/classes/Gems/Default/OptionAction.php
===================================================================
--- branches/newUser2/classes/Gems/Default/OptionAction.php 2011-11-11 11:41:20 UTC (rev 201)
+++ branches/newUser2/classes/Gems/Default/OptionAction.php 2011-11-11 17:48:42 UTC (rev 202)
@@ -68,6 +68,9 @@
$this->loader->getUser($data['gsf_login'], $data['gsf_id_organization']);
}
+ /**
+ * Allow a user to change his / her password.
+ */
public function changePasswordAction()
{
/*************
@@ -75,11 +78,14 @@
*************/
$form = $this->createForm();
- $user = $this->loader->getCurrentUser();
+ $user = $this->loader->getCurrentUser();
- $sql = "SELECT CASE WHEN gup_password IS NULL THEN 0 ELSE 1 END FROM gems__user_passwords WHERE gup_id_user = ?";
+ if (! $user->canSetPassword()) {
+ $this->addMessage($this->_('You are not allowed to change your password.'));
+ return;
+ }
- if ($this->db->fetchOne($sql, $user->getUserLoginId())) {
+ if ($user->hasPassword()) {
// Field current password
//
// This is only used when the password is already set, which may not always be the case
@@ -124,14 +130,8 @@
* Process form *
****************/
if ($this->_request->isPost() && $form->isValid($_POST)) {
+ $user->setPassword($_POST['new_password']);
- $data['gup_id_user'] = $user->getUserLoginId();
- $data['gup_password'] = $this->project->getValueHash($_POST['new_password']);
-
- $model = new MUtil_Model_TableModel('gems__user_passwords');
- Gems_Model::setChangeFieldsByPrefix($model, 'gup', $user->getUserId());
-
- $model->save($data);
$this->addMessage($this->_('New password is active.'));
$this->_reroute(array($this->getRequest()->getActionKey() => 'edit'));
Modified: branches/newUser2/classes/Gems/Project/ProjectSettings.php
===================================================================
--- branches/newUser2/classes/Gems/Project/ProjectSettings.php 2011-11-11 11:41:20 UTC (rev 201)
+++ branches/newUser2/classes/Gems/Project/ProjectSettings.php 2011-11-11 17:48:42 UTC (rev 202)
@@ -172,6 +172,15 @@
}
/**
+ * Returns the public name of this project.
+ * @return string
+ */
+ public function getName()
+ {
+ return $this->offsetGet('name');
+ }
+
+ /**
* Returns the super admin name, if any
*
* @return string
Modified: branches/newUser2/classes/Gems/User/StaffUserDefinition.php
===================================================================
--- branches/newUser2/classes/Gems/User/StaffUserDefinition.php 2011-11-11 11:41:20 UTC (rev 201)
+++ branches/newUser2/classes/Gems/User/StaffUserDefinition.php 2011-11-11 17:48:42 UTC (rev 202)
@@ -36,8 +36,8 @@
*/
/**
+ * A standard, database stored and authenticate staff user as of version 1.5.
*
- *
* @package Gems
* @subpackage User
* @copyright Copyright (c) 2011 Erasmus MC
@@ -59,6 +59,39 @@
protected $project;
/**
+ * Return true if a password reset key can be created.
+ *
+ * Returns the setting for the definition whan no user is passed, otherwise
+ * returns the answer for this specific user.
+ *
+ * @param Gems_User_User $user Optional, the user whose password might change
+ * @return boolean
+ */
+ public function canResetPassword(Gems_User_User $user = null)
+ {
+ if ($user) {
+ // Depends on the user.
+ return $user->hasEmailAddress() && $user->canSetPassword();
+ } else {
+ return true;
+ }
+ }
+
+ /**
+ * Return true if the password can be set.
+ *
+ * Returns the setting for the definition whan no user is passed, otherwise
+ * returns the answer for this specific user.
+ *
+ * @param Gems_User_User $user Optional, the user whose password might change
+ * @return boolean
+ */
+ public function canSetPassword(Gems_User_User $user = null)
+ {
+ return true;
+ }
+
+ /**
* Checks the password for the specified $login_name and $organization.
*
* @param string $login_name
@@ -82,6 +115,33 @@
}
/**
+ * Return a password reset key
+ *
+ * @param Gems_User_User $user The user to create a key for.
+ * @return string
+ */
+ public function getPasswordResetKey(Gems_User_User $user)
+ {
+ $model = new MUtil_Model_TableModel('gems__user_passwords');
+ Gems_Model::setChangeFieldsByPrefix($model, 'gup', $user->getUserId());
+
+ $data['gup_id_user'] = $user->getUserLoginId();
+
+ $row = $model->loadFirst($data);
+ if ($row && $row['gup_reset_key']) {
+ // Keep using the key.
+ $data['gup_reset_key'] = $row['gup_reset_key'];
+ } else {
+ $data['gup_reset_key'] = $this->hashPassword(time() . $user->getEmailAddress());
+ }
+ $data['gup_reset_requested'] = new Zend_Db_Expr('CURRENT_TIMESTAMP');
+
+ $model->save($data);
+
+ return $data['gup_reset_key'];
+ }
+
+ /**
* Returns a user object, that may be empty if the user is unknown.
*
* @param string $login_name
@@ -127,4 +187,43 @@
{
return $this->project->getValueHash($password);
}
+
+ /**
+ * Return true if the user has a password.
+ *
+ * @param Gems_User_User $user The user to check
+ * @return boolean
+ */
+ public function hasPassword(Gems_User_User $user)
+ {
+ $sql = "SELECT CASE WHEN gup_password IS NULL THEN 0 ELSE 1 END FROM gems__user_passwords WHERE gup_id_user = ?";
+
+ return (boolean) $this->db->fetchOne($sql, $user->getUserLoginId());
+ }
+
+ /**
+ * Set the password, if allowed for this user type.
+ *
+ * @param Gems_User_User $user The user whose password to change
+ * @param string $password
+ * @return Gems_User_UserDefinitionInterface (continuation pattern)
+ */
+ public function setPassword(Gems_User_User $user, $password)
+ {
+ $data['gup_id_user'] = $user->getUserLoginId();
+ $data['gup_reset_required'] = 0;
+ if (null === $password) {
+ // Passwords may be emptied.
+ $data['gup_password'] = null;
+ } else {
+ $data['gup_password'] = $this->hashPassword($password);
+ }
+
+ $model = new MUtil_Model_TableModel('gems__user_passwords');
+ Gems_Model::setChangeFieldsByPrefix($model, 'gup', $user->getUserId());
+
+ $model->save($data);
+
+ return $this;
+ }
}
Modified: branches/newUser2/classes/Gems/User/User.php
===================================================================
--- branches/newUser2/classes/Gems/User/User.php 2011-11-11 11:41:20 UTC (rev 201)
+++ branches/newUser2/classes/Gems/User/User.php 2011-11-11 17:48:42 UTC (rev 202)
@@ -84,6 +84,7 @@
} else {
$this->_vars = $settings;
}
+ $this->definition = $definition;
}
/**
@@ -172,6 +173,26 @@
}
/**
+ * Return true if a password reset key can be created.
+ *
+ * @return boolean
+ */
+ public function canResetPassword()
+ {
+ return $this->isActive() && $this->definition->canResetPassword($this);
+ }
+
+ /**
+ * Return true if the password can be set.
+ *
+ * @return boolean
+ */
+ public function canSetPassword()
+ {
+ return $this->definition->canSetPassword();
+ }
+
+ /**
* Checks the password for this user and handle the login security.
*
* @param string $password
@@ -230,6 +251,16 @@
}
/**
+ * Return true if this user has a password.
+ *
+ * @return boolean
+ */
+ public function getEmailAddress()
+ {
+ return $this->_getVar('user_email');
+ }
+
+ /**
* Returns the full user name (first, prefix, last).
*
* @return string
@@ -278,6 +309,16 @@
}
/**
+ * Return a password reset key
+ *
+ * @return string
+ */
+ public function getPasswordResetKey()
+ {
+ return $this->definition->getPasswordResetKey($this);
+ }
+
+ /**
* Returns the user id, that identifies this user within this installation.
*
* One user id might be connected to multiple logins for multiple organizations.
@@ -292,6 +333,8 @@
}
/**
+ * Use ONLY in User package.
+ *
* Returns the User package user id, that is unique for each login / organization id
* combination, but does not directly identify this person.
*
@@ -309,7 +352,27 @@
}
/**
+ * Return true if this user has a password.
*
+ * @return boolean
+ */
+ public function hasEmailAddress()
+ {
+ return $this->_hasVar('user_email');
+ }
+
+ /**
+ * Return true if this user has a password.
+ *
+ * @return boolean
+ */
+ public function hasPassword()
+ {
+ return $this->definition->hasPassword();
+ }
+
+ /**
+ *
* @return boolean True when a user can log in.
*/
public function isActive()
@@ -324,7 +387,7 @@
*/
public function isCurrentUser()
{
- return $this->_getVariableStore() instanceof Zend_Session_Namespace;
+ return $this->_vars instanceof Zend_Session_Namespace;
}
/**
@@ -342,16 +405,17 @@
*
* This means that the data about this user will be stored in a session.
*
- * @return Gems_User_UserAbstract
+ * @param boolean $signalLoader Do not set, except from UserLoader
+ * @return Gems_User_UserAbstract (continuation pattern)
*/
- public function setAsCurrentUser()
+ public function setAsCurrentUser($signalLoader = true)
{
// Get the current variables
$oldStore = $this->_getVariableStore();
// When $oldStore is a Zend_Session_Namespace, then this user is already the current user.
if (! $this->isCurrentUser()) {
- $this->userLoader->getCurrentUser()->unsetAsCurrentUser();
+ $this->userLoader->unsetCurrentUser();
$this->_vars = $this->session;
@@ -359,25 +423,41 @@
$this->_vars->__set($name, $value);
}
- $this->userLoader->setCurrentUser($this);
+ if ($signalLoader) {
+ $this->userLoader->setCurrentUser($this);
+ }
}
return $this;
}
+
/**
+ * Set the password, if allowed for this user type.
+ *
+ * @param string $password
+ * @return Gems_User_UserAbstract (continuation pattern)
+ */
+ public function setPassword($password)
+ {
+ $this->definition->setPassword($this, $password);
+ return $this;
+ }
+
+ /**
* Unsets this user as the current user.
*
* This means that the data about this user will no longer be stored in a session.
*
- * @return Gems_User_UserAbstract
+ * @param boolean $signalLoader Do not set, except from UserLoader
+ * @return Gems_User_UserAbstract (continuation pattern)
*/
- public function unsetAsCurrentUser()
+ public function unsetAsCurrentUser($signalLoader = true)
{
// When $oldStore is a Zend_Session_Namespace, then this user is already the current user.
if ($this->isCurrentUser()) {
// Get the current variables
- $oldStore = $this->_getVariableStore();
+ $oldStore = $this->_vars;
$this->_vars = new ArrayObject();
$this->_vars->setFlags(ArrayObject::STD_PROP_LIST);
@@ -387,10 +467,12 @@
}
// Clean up what is there now in the session.
- $this->session->unsetAll();
+ $oldStore->unsetAll();
- // Signal the loader
- $this->userLoader->unsetCurrentUser();
+ if ($signalLoader) {
+ // Signal the loader
+ $this->userLoader->unsetCurrentUser();
+ }
}
return $this;
Modified: branches/newUser2/classes/Gems/User/UserDefinitionAbstract.php
===================================================================
--- branches/newUser2/classes/Gems/User/UserDefinitionAbstract.php 2011-11-11 11:41:20 UTC (rev 201)
+++ branches/newUser2/classes/Gems/User/UserDefinitionAbstract.php 2011-11-11 17:48:42 UTC (rev 202)
@@ -48,5 +48,66 @@
*/
abstract class Gems_User_UserDefinitionAbstract extends MUtil_Registry_TargetAbstract implements Gems_User_UserDefinitionInterface
{
+ /**
+ * Return true if a password reset key can be created.
+ *
+ * Returns the setting for the definition whan no user is passed, otherwise
+ * returns the answer for this specific user.
+ *
+ * @param Gems_User_User $user Optional, the user whose password might change
+ * @return boolean
+ */
+ public function canResetPassword(Gems_User_User $user = null)
+ {
+ return false;
+ }
+ /**
+ * Return true if the password can be set.
+ *
+ * Returns the setting for the definition whan no user is passed, otherwise
+ * returns the answer for this specific user.
+ *
+ * @param Gems_User_User $user Optional, the user whose password might change
+ * @return boolean
+ */
+ public function canSetPassword(Gems_User_User $user = null)
+ {
+ return false;
+ }
+
+ /**
+ * Return a password reset key
+ *
+ * @param Gems_User_User $user The user to create a key for.
+ * @return string
+ */
+ public function getPasswordResetKey(Gems_User_User $user)
+ {
+ throw new Gems_Exception_Coding(sprintf('A password reset key cannot be issued for %s users.', get_class($this)));
+ }
+
+ /**
+ * Return true if the user has a password.
+ *
+ * @param Gems_User_User $user The user to check
+ * @return boolean
+ */
+ public function hasPassword(Gems_User_User $user)
+ {
+ return false;
+ }
+
+ /**
+ * Set the password, if allowed for this user type.
+ *
+ * @param Gems_User_User $user The user whose password to change
+ * @param string $password
+ * @return Gems_User_UserDefinitionInterface (continuation pattern)
+ */
+ public function setPassword(Gems_User_User $user, $password)
+ {
+ throw new Gems_Exception_Coding(sprintf('The password cannot be set for %s users.', get_class($this)));
+ return $this;
+ }
}
Modified: branches/newUser2/classes/Gems/User/UserDefinitionInterface.php
===================================================================
--- branches/newUser2/classes/Gems/User/UserDefinitionInterface.php 2011-11-11 11:41:20 UTC (rev 201)
+++ branches/newUser2/classes/Gems/User/UserDefinitionInterface.php 2011-11-11 17:48:42 UTC (rev 202)
@@ -47,6 +47,28 @@
interface Gems_User_UserDefinitionInterface
{
/**
+ * Return true if a password reset key can be created.
+ *
+ * Returns the setting for the definition whan no user is passed, otherwise
+ * returns the answer for this specific user.
+ *
+ * @param Gems_User_User $user Optional, the user whose password might change
+ * @return boolean
+ */
+ public function canResetPassword(Gems_User_User $user = null);
+
+ /**
+ * Return true if the password can be set.
+ *
+ * Returns the setting for the definition whan no user is passed, otherwise
+ * returns the answer for this specific user.
+ *
+ * @param Gems_User_User $user Optional, the user whose password might change
+ * @return boolean
+ */
+ public function canSetPassword(Gems_User_User $user = null);
+
+ /**
* Checks the password for the specified $login_name and $organization.
*
* @param string $login_name
@@ -57,6 +79,14 @@
public function checkPassword($login_name, $organization, $password);
/**
+ * Return a password reset key
+ *
+ * @param Gems_User_User $user The user to create a key for.
+ * @return string
+ */
+ public function getPasswordResetKey(Gems_User_User $user);
+
+ /**
* Returns a user object, that may be empty if the user is unknown.
*
* @param string $login_name
@@ -64,4 +94,21 @@
* @return array Of data to fill the user with.
*/
public function getUserData($login_name, $organization);
+
+ /**
+ * Return true if the user has a password.
+ *
+ * @param Gems_User_User $user The user to check
+ * @return boolean
+ */
+ public function hasPassword(Gems_User_User $user);
+
+ /**
+ * Set the password, if allowed for this user type.
+ *
+ * @param Gems_User_User $user The user whose password to change
+ * @param string $password
+ * @return Gems_User_UserDefinitionInterface (continuation pattern)
+ */
+ public function setPassword(Gems_User_User $user, $password);
}
\ No newline at end of file
Modified: branches/newUser2/classes/Gems/User/UserLoader.php
===================================================================
--- branches/newUser2/classes/Gems/User/UserLoader.php 2011-11-11 11:41:20 UTC (rev 201)
+++ branches/newUser2/classes/Gems/User/UserLoader.php 2011-11-11 17:48:42 UTC (rev 202)
@@ -98,7 +98,8 @@
public function checkPassword($login_name, $organization, $password)
{
// MUtil_Echo::track($login_name, $organization, $password);
- $definition = $this->getUserClass($login_name, $organization);
+ $defName = $this->getUserClassName($login_name, $organization);
+ $definition = $this->_getClass($defName);
$success = $definition->checkPassword($login_name, $organization, $password);
@@ -196,10 +197,11 @@
{
if (! self::$currentUser) {
if ($this->session->__isset('__user_definition')) {
- $className = $this->session->__get('__user_definition');
- self::$currentUser = $this->_loadClass('User', true, array($this->session, new $className()));
+ $defName = $this->session->__get('__user_definition');
+ self::$currentUser = $this->_loadClass('User', true, array($this->session, $this->_getClass($defName)));
} else {
self::$currentUser = $this->getUser(null, null);
+ self::$currentUser->setAsCurrentUser();
}
}
@@ -215,8 +217,10 @@
*/
public function getUser($login_name, $organization)
{
- $definition = $this->getUserClass($login_name, $organization);
+ $defName = $this->getUserClassName($login_name, $organization);
+ $definition = $this->_getClass($defName);
+
$values = $definition->getUserData($login_name, $organization);
if (! isset($values['user_active'])) {
@@ -227,7 +231,7 @@
//Load the allowed organizations
$values['allowedOrgs'] = $this->getAllowedOrganizations();
}
- $values['__user_definition'] = get_class($definition);
+ $values['__user_definition'] = $defName;
return $this->_loadClass('User', true, array($values, $definition));
}
@@ -250,22 +254,22 @@
}
/**
- * Returns the user class, can be overloaded by subclasses.
+ * Returns the name of the user definition class of this user.
*
* @param string $login_name
* @param int $organization
- * @return Gems_User_UserDefinitionInterface
+ * @return string
*/
- protected function getUserClass($login_name, $organization)
+ protected function getUserClassName($login_name, $organization)
{
if ($this->isProjectUser($login_name)) {
- return $this->_getClass('ProjectUserDefinition');
+ return 'ProjectUserDefinition';
}
try {
$sql = "SELECT gul_user_class FROM gems__user_logins WHERE gul_can_login = 1 AND gul_login = ? AND gul_id_organization = ?";
if ($class = $this->db->fetchOne($sql, array($login_name, $organization))) {
- return $this->_getClass($class . 'Definition');
+ return $class . 'Definition';
}
} catch (Zend_Db_Exception $e) {
@@ -293,10 +297,10 @@
// MUtil_Echo::r($e);
}
- return $this->_getClass(self::USER_OLD_STAFF . 'Definition');
+ return self::USER_OLD_STAFF . 'Definition';
}
- return $this->_getClass('NoLoginDefinition');
+ return 'NoLoginDefinition';
}
protected function isProjectUser($login_name)
@@ -312,29 +316,30 @@
*/
public function setCurrentUser(Gems_User_User $user)
{
- $this->unsetCurrentUser();
- self::$currentUser = $user;
+ if ($user !== self::$currentUser) {
+ $this->unsetCurrentUser();
+ self::$currentUser = $user;
- // Double check in case this function was used as original
- // start for setting the user.
- if (! $user->isCurrentUser()) {
- $user->setAsCurrentUser();
+ // Double check in case this function was used as original
+ // start for setting the user.
+ if (! $user->isCurrentUser()) {
+ $user->setAsCurrentUser(true);
+ }
}
return $this;
}
/**
- * Sets a new user as the current user.
+ * Removes the current user
*
- * @param Gems_User_User $user
* @return Gems_User_UserLoader (continuation pattern)
*/
public function unsetCurrentUser()
{
// Remove if the currentUser still sees itself as the current user.
if ((self::$currentUser instanceof Gems_User_User) && self::$currentUser->isCurrentUser()) {
- self::$currentUser->unsetAsCurrentUser();
+ self::$currentUser->unsetAsCurrentUser(false);
}
self::$currentUser = null;
return $this;
Modified: branches/newUser2/classes/MUtil/Model/DatabaseModelAbstract.php
===================================================================
--- branches/newUser2/classes/MUtil/Model/DatabaseModelAbstract.php 2011-11-11 11:41:20 UTC (rev 201)
+++ branches/newUser2/classes/MUtil/Model/DatabaseModelAbstract.php 2011-11-11 17:48:42 UTC (rev 202)
@@ -598,12 +598,17 @@
public function formatSaveDate($name, $value, $new = false)
{
- if ($name) {
+ if ($name && (! ((null === $value) || ($value instanceof Zend_Db_Expr)))) {
if ($saveFormat = $this->get($name, 'storageFormat')) {
- $displayFormat = $this->get($name, 'dateFormat');
+ if ($value instanceof Zend_Date) {
+ return $value->toString($saveFormat);
+
+ } else {
+ $displayFormat = $this->get($name, 'dateFormat');
- return MUtil_Date::format($value, $saveFormat, $displayFormat);
+ return MUtil_Date::format($value, $saveFormat, $displayFormat);
+ }
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <gem...@li...> - 2011-11-11 11:41:29
|
Revision: 201
http://gemstracker.svn.sourceforge.net/gemstracker/?rev=201&view=rev
Author: matijsdejong
Date: 2011-11-11 11:41:20 +0000 (Fri, 11 Nov 2011)
Log Message:
-----------
Made a separate UserDefinitionInterface.php for each type of user for #31. Can be extended by creating new classes and stating them in gems__user_logins.
Still have to do something about lost passwords and remembering the last organization.
Modified Paths:
--------------
branches/newUser2/classes/Gems/Default/TokenPlanAction.php
branches/newUser2/classes/Gems/Loader/LoaderAbstract.php
branches/newUser2/classes/Gems/Menu/MenuAbstract.php
branches/newUser2/classes/Gems/User/User.php
branches/newUser2/classes/Gems/User/UserLoader.php
branches/newUser2/classes/MUtil/Model/FormBridge.php
branches/newUser2/configs/db/tables/gems__staff.20.sql
Added Paths:
-----------
branches/newUser2/classes/Gems/User/NoLoginDefinition.php
branches/newUser2/classes/Gems/User/OldStaffUserDefinition.php
branches/newUser2/classes/Gems/User/ProjectUserDefinition.php
branches/newUser2/classes/Gems/User/StaffUserDefinition.php
branches/newUser2/classes/Gems/User/UserDefinitionAbstract.php
branches/newUser2/classes/Gems/User/UserDefinitionInterface.php
Removed Paths:
-------------
branches/newUser2/classes/Gems/Validate/GemsPasswordUsername.php
branches/newUser2/configs/db/tables/gems__users.10.sql
Modified: branches/newUser2/classes/Gems/Default/TokenPlanAction.php
===================================================================
--- branches/newUser2/classes/Gems/Default/TokenPlanAction.php 2011-11-10 17:15:11 UTC (rev 200)
+++ branches/newUser2/classes/Gems/Default/TokenPlanAction.php 2011-11-11 11:41:20 UTC (rev 201)
@@ -351,7 +351,7 @@
COALESCE(gems__staff.gsf_first_name, ''),
COALESCE(CONCAT(' ', gems__staff.gsf_surname_prefix), '')
) AS gsf_name
- FROM gems__staff INNER JOIN gems__respondent2track ON gus_id_user = gr2t_created_by
+ FROM gems__staff INNER JOIN gems__respondent2track ON gsf_id_user = gr2t_created_by
WHERE gr2t_id_organization = $orgId AND
gr2t_active = 1";
$elements[] = $this->_createSelectElement('gr2t_created_by', $sql, $this->_('(all staff)'));
Modified: branches/newUser2/classes/Gems/Loader/LoaderAbstract.php
===================================================================
--- branches/newUser2/classes/Gems/Loader/LoaderAbstract.php 2011-11-10 17:15:11 UTC (rev 200)
+++ branches/newUser2/classes/Gems/Loader/LoaderAbstract.php 2011-11-11 11:41:20 UTC (rev 201)
@@ -115,6 +115,14 @@
throw new Gems_Exception_Coding("Unknown property '$name' requested.");
}
+ /**
+ * Returns $this->$name, creating the item if it does not yet exist.
+ *
+ * @param string $name The $name of the variable to store this object in.
+ * @param string $className Class name or null if the same as $name, prepending $this->_dirs.
+ * @param array $arguments Class initialization arguments.
+ * @return mixed Instance of $className
+ */
protected function _getClass($name, $className = null, array $arguments = array())
{
if (! isset($this->$name)) {
@@ -127,6 +135,18 @@
return $this->$name;
}
+ /**
+ * Create or loads the class. When only loading, this function returns a StaticCall object that
+ * can be invoked lazely.
+ *
+ * @see MUtil_Lazy_StaticCall
+ * @see MUtil_Registry_TargetInterface
+ *
+ * @param string $name The class name, minus the part in $this->_dirs.
+ * @param boolean $create Create the object, or only when an MUtil_Registry_TargetInterface instance.
+ * @param array $arguments Class initialization arguments.
+ * @return mixed A class instance or a MUtil_Lazy_StaticCall object
+ */
protected function _loadClass($name, $create = false, array $arguments = array())
{
// echo $name . ($create ? ' create' : ' not created') . "<br/>\n";
@@ -150,6 +170,15 @@
//print_r($this->_dirs);
}
+ /**
+ * Try the actual loading of the class.
+ *
+ * @param string $filepath The full path to the class
+ * @param string $classname The full class name.
+ * @param boolean $create Create the object, or only when an MUtil_Registry_TargetInterface instance.
+ * @param array $arguments Class initialization arguments.
+ * @return mixed Null or object of type $classname or MUtil_Lazy_StaticCall
+ */
private function _loadClassPath($filepath, $classname, $create, array $arguments)
{
// echo '_loadClassPath: ' . $this->cascade . '-' . $classname . '-' . ($create ? 1 : 0) . "<br/>\n";
Modified: branches/newUser2/classes/Gems/Menu/MenuAbstract.php
===================================================================
--- branches/newUser2/classes/Gems/Menu/MenuAbstract.php 2011-11-10 17:15:11 UTC (rev 200)
+++ branches/newUser2/classes/Gems/Menu/MenuAbstract.php 2011-11-11 11:41:20 UTC (rev 201)
@@ -385,8 +385,8 @@
$editPage = $page->addEditAction();
$delPage = $page->addDeleteAction();
if (! $this->escort->hasPrivilege('pr.staff.edit.all')) {
- $editPage->setParameterFilter('gus_id_organization', $this->escort->getCurrentOrganization());
- $delPage->setParameterFilter('gus_id_organization', $this->escort->getCurrentOrganization());
+ $editPage->setParameterFilter('gsf_id_organization', $this->escort->getCurrentOrganization());
+ $delPage->setParameterFilter('gsf_id_organization', $this->escort->getCurrentOrganization());
}
return $page;
Added: branches/newUser2/classes/Gems/User/NoLoginDefinition.php
===================================================================
--- branches/newUser2/classes/Gems/User/NoLoginDefinition.php (rev 0)
+++ branches/newUser2/classes/Gems/User/NoLoginDefinition.php 2011-11-11 11:41:20 UTC (rev 201)
@@ -0,0 +1,77 @@
+<?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_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)
+ {
+ return false;
+ }
+
+ /**
+ * Returns a user object, that may be empty if the user is unknown.
+ *
+ * @param string $login_name
+ * @param int $organization
+ * @return array Of data to fill the user with.
+ */
+ public function getUserData($login_name, $organization)
+ {
+ return array(
+ 'user_active' => false,
+ 'user_role' => 'nologin',
+ 'user_organization_id' => 0,
+ );
+ }
+}
Added: branches/newUser2/classes/Gems/User/OldStaffUserDefinition.php
===================================================================
--- branches/newUser2/classes/Gems/User/OldStaffUserDefinition.php (rev 0)
+++ branches/newUser2/classes/Gems/User/OldStaffUserDefinition.php 2011-11-11 11:41:20 UTC (rev 201)
@@ -0,0 +1,181 @@
+<?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 $
+ */
+
+/**
+ * Stub function for 1.4 style users. Tries to upgrade the user to
+ * StaffUser at every opportunity.
+ *
+ * @package Gems
+ * @subpackage User
+ * @copyright Copyright (c) 2011 Erasmus MC
+ * @license New BSD License
+ * @since Class available since version 1.5
+ */
+class Gems_User_OldStaffUserDefinition extends Gems_User_UserDefinitionAbstract
+{
+ /**
+ *
+ * @var Zend_Db_Adapter_Abstract
+ */
+ protected $db;
+
+ /**
+ *
+ * @var Gems_Project_ProjectSettings
+ */
+ 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)
+ {
+ $pwd_hash = $this->hashPassword($password);
+
+ $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 {
+ $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);
+
+ }
+
+ return true;
+ }
+
+ }
+
+ /**
+ * Returns a user object, that may be empty if the user is unknown.
+ *
+ * @param string $login_name
+ * @param int $organization
+ * @return array Of data to fill the user with.
+ */
+ public function getUserData($login_name, $organization)
+ {
+ /**
+ * Read the needed parameters from the different tables, lots of renames for backward
+ * compatibility
+ */
+ $select = new Zend_Db_Select($this->db);
+ $select->from('gems__staff', array('user_id'=>'gsf_id_user',
+ 'user_login'=>'gsf_login',
+ 'user_email'=>'gsf_email',
+ 'user_group'=>'gsf_id_primary_group',
+ 'user_locale'=>'gsf_iso_lang',
+ 'user_logout'=>'gsf_logout_on_survey'))
+ ->columns(array('user_name'=>"(concat(coalesce(concat(`gems__staff`.`gsf_first_name`,_utf8' '),_utf8''),coalesce(concat(`gems__staff`.`gsf_surname_prefix`,_utf8' '),_utf8''),coalesce(`gems__staff`.`gsf_last_name`,_utf8'')))"))
+ ->join('gems__groups', 'gsf_id_primary_group = ggp_id_group', array('user_role'=>'ggp_role'))
+ ->join('gems__organizations', 'gsf_id_organization = gor_id_organization',
+ array(
+ 'user_organization_id'=>'gor_id_organization',
+ 'user_organization_name'=>'gor_name'))
+ ->where('ggp_group_active = 1')
+ ->where('gor_active = 1')
+ ->where('gsf_active = 1')
+ ->where('gsf_login = ?')
+ ->limit(1);
+
+ // For a multi-layout project we need to select the appropriate style too,
+ // but as PATCHES may not be in effect we have to try two selects
+ $select2 = clone $select;
+ $select2->columns(array('user_style' => 'gor_style'), 'gems__organizations');
+
+ try {
+ // Fails before patch has run...
+ return $this->db->fetchRow($select2, array($login_name), Zend_Db::FETCH_ASSOC);
+
+ } catch (Zend_Db_Exception $e) {
+ // So then we try the old method
+ return $this->db->fetchRow($select, array($login_name), Zend_Db::FETCH_ASSOC);
+ }
+ }
+
+ /**
+ * Allow overruling of password hashing.
+ *
+ * @param string $password
+ * @return string
+ */
+ protected function hashPassword($password)
+ {
+ return md5($password);
+ }
+}
Added: branches/newUser2/classes/Gems/User/ProjectUserDefinition.php
===================================================================
--- branches/newUser2/classes/Gems/User/ProjectUserDefinition.php (rev 0)
+++ branches/newUser2/classes/Gems/User/ProjectUserDefinition.php 2011-11-11 11:41:20 UTC (rev 201)
@@ -0,0 +1,89 @@
+<?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_ProjectUserDefinition extends Gems_User_UserDefinitionAbstract
+{
+ /**
+ *
+ * @var Gems_Project_ProjectSettings
+ */
+ 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)
+ {
+ return $this->project->checkSuperAdminPassword($password);
+ }
+
+ /**
+ * Returns a user object, that may be empty if the user is unknown.
+ *
+ * @param string $login_name
+ * @param int $organization
+ * @return array Of data to fill the user with.
+ */
+ public function getUserData($login_name, $organization)
+ {
+ return array(
+ 'user_id' => 1,
+ 'user_login' => $login_name,
+ 'user_name' => $login_name,
+ 'user_group' => 800,
+ 'user_role' => 'master',
+ 'user_style' => 'gems',
+ 'user_organization_id' => $organization,
+ 'user_organization_name' => 'SUPER ADMIN',
+ 'allowedOrgs' => array($organization => 'SUPER ADMIN')
+ );
+ }
+}
Added: branches/newUser2/classes/Gems/User/StaffUserDefinition.php
===================================================================
--- branches/newUser2/classes/Gems/User/StaffUserDefinition.php (rev 0)
+++ branches/newUser2/classes/Gems/User/StaffUserDefinition.php 2011-11-11 11:41:20 UTC (rev 201)
@@ -0,0 +1,130 @@
+<?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_StaffUserDefinition extends Gems_User_UserDefinitionAbstract
+{
+ /**
+ *
+ * @var Zend_Db_Adapter_Abstract
+ */
+ protected $db;
+
+ /**
+ *
+ * @var Gems_Project_ProjectSettings
+ */
+ 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)
+ {
+ $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);
+ }
+
+ /**
+ * Returns a user object, that may be empty if the user is unknown.
+ *
+ * @param string $login_name
+ * @param int $organization
+ * @return array Of data to fill the user with.
+ */
+ public function getUserData($login_name, $organization)
+ {
+ $select = new Zend_Db_Select($this->db);
+ $select->from('gems__user_logins', array('user_login_id' => 'gul_id_user'))
+ ->join('gems__staff', 'gul_login = gsf_login AND gul_id_organization = gsf_id_organization', array(
+ 'user_login' => 'gsf_login',
+ 'user_id' => 'gsf_id_user',
+ 'user_email'=>'gsf_email',
+ 'user_group'=>'gsf_id_primary_group',
+ 'user_locale'=>'gsf_iso_lang',
+ 'user_logout'=>'gsf_logout_on_survey'))
+ ->columns(array('user_name'=>"(concat(coalesce(concat(`gems__staff`.`gsf_first_name`,_utf8' '),_utf8''),coalesce(concat(`gems__staff`.`gsf_surname_prefix`,_utf8' '),_utf8''),coalesce(`gems__staff`.`gsf_last_name`,_utf8'')))"))
+ ->join('gems__groups', 'gsf_id_primary_group = ggp_id_group', array('user_role'=>'ggp_role'))
+ ->join('gems__organizations', 'gul_id_organization = gor_id_organization',
+ array(
+ 'user_organization_id'=>'gor_id_organization',
+ 'user_organization_name'=>'gor_name',
+ 'user_style' => 'gor_style'))
+ ->where('ggp_group_active = 1')
+ ->where('gor_active = 1')
+ ->where('gsf_active = 1')
+ ->where('gul_can_login = 1')
+ ->where('gul_login = ?')
+ ->where('gul_id_organization = ?')
+ ->limit(1);
+
+ return $this->db->fetchRow($select, array($login_name, $organization), Zend_Db::FETCH_ASSOC);
+ }
+
+ /**
+ * Allow overruling of password hashing.
+ *
+ * @param string $password
+ * @return string
+ */
+ protected function hashPassword($password)
+ {
+ return $this->project->getValueHash($password);
+ }
+}
Modified: branches/newUser2/classes/Gems/User/User.php
===================================================================
--- branches/newUser2/classes/Gems/User/User.php 2011-11-10 17:15:11 UTC (rev 200)
+++ branches/newUser2/classes/Gems/User/User.php 2011-11-11 11:41:20 UTC (rev 201)
@@ -54,6 +54,12 @@
/**
*
+ * @var Gems_User_UserDefinitionInterface
+ */
+ protected $definition;
+
+ /**
+ *
* @var Zend_Session_Namespace
*/
protected $session;
@@ -68,8 +74,9 @@
* Creates the class for this user.
*
* @param mixed $settings Array, Zend_Session_Namespace or ArrayObject for this user.
+ * @param Gems_User_UserDefinitionInterface $definition The user class definition.
*/
- public function __construct($settings)
+ public function __construct($settings, Gems_User_UserDefinitionInterface $definition)
{
if (is_array($settings)) {
$this->_vars = new ArrayObject($settings);
@@ -172,7 +179,7 @@
*/
public function checkPassword($password)
{
- return $this->userLoader->checkPassword($this->getLoginName(), $this->getOrganizationId(), $password);
+ return $this->definition->checkPassword($this->getLoginName(), $this->getOrganizationId(), $password);
}
/**
@@ -193,10 +200,10 @@
$notCurrent = true;
foreach (array('user_id', 'user_organization_id') as $key) {
- if ($sessionStore->__isset($key) && $this->_vars->offsetGet($key)) {
+ if ($sessionStore->__isset($key) && $this->_vars->offsetExists($key)) {
$notCurrent = $sessionStore->__get($key) != $this->_vars->offsetGet($key);
} else {
- $notCurrent = $sessionStore->__isset($key) || $this->_vars->offsetGet($key);
+ $notCurrent = $sessionStore->__isset($key) || $this->_vars->offsetExists($key);
}
if ($notCurrent) {
Added: branches/newUser2/classes/Gems/User/UserDefinitionAbstract.php
===================================================================
--- branches/newUser2/classes/Gems/User/UserDefinitionAbstract.php (rev 0)
+++ branches/newUser2/classes/Gems/User/UserDefinitionAbstract.php 2011-11-11 11:41:20 UTC (rev 201)
@@ -0,0 +1,52 @@
+<?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 $
+ */
+
+/**
+ * Base class for all user definitions.
+ *
+ * Mainly to implement TargetAbstract.
+ *
+ * @package Gems
+ * @subpackage User
+ * @copyright Copyright (c) 2011 Erasmus MC
+ * @license New BSD License
+ * @since Class available since version 1.5
+ */
+abstract class Gems_User_UserDefinitionAbstract extends MUtil_Registry_TargetAbstract implements Gems_User_UserDefinitionInterface
+{
+
+}
Added: branches/newUser2/classes/Gems/User/UserDefinitionInterface.php
===================================================================
--- branches/newUser2/classes/Gems/User/UserDefinitionInterface.php (rev 0)
+++ branches/newUser2/classes/Gems/User/UserDefinitionInterface.php 2011-11-11 11:41:20 UTC (rev 201)
@@ -0,0 +1,67 @@
+<?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
+ */
+interface Gems_User_UserDefinitionInterface
+{
+ /**
+ * 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);
+
+ /**
+ * Returns a user object, that may be empty if the user is unknown.
+ *
+ * @param string $login_name
+ * @param int $organization
+ * @return array Of data to fill the user with.
+ */
+ public function getUserData($login_name, $organization);
+}
\ No newline at end of file
Modified: branches/newUser2/classes/Gems/User/UserLoader.php
===================================================================
--- branches/newUser2/classes/Gems/User/UserLoader.php 2011-11-10 17:15:11 UTC (rev 200)
+++ branches/newUser2/classes/Gems/User/UserLoader.php 2011-11-11 11:41:20 UTC (rev 201)
@@ -90,21 +90,18 @@
* Checks the password for the specified $login_name and $organization and
* handles the login security.
*
- * Do not overload this function, but use checkPasswordValidity() when you
- * need to add extra authentication types.
- *
- * @see checkPasswordValidity()
- *
* @param string $login_name
* @param int $organization
* @param string $password
* @return boolean True if the password is correct.
*/
- public final function checkPassword($login_name, $organization, $password)
+ public function checkPassword($login_name, $organization, $password)
{
// MUtil_Echo::track($login_name, $organization, $password);
- $success = $this->checkPasswordValidity($login_name, $organization, $password);
+ $definition = $this->getUserClass($login_name, $organization);
+ $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));
@@ -159,93 +156,6 @@
}
/**
- * Checks the $password for the specified $login_name and $organization
- *
- * This is the function to overrule if you want to add extra authentication types.
- *
- * @see checkPassword()
- *
- * @param string $login_name
- * @param int $organization
- * @param string $password
- * @return boolean True if the password is correct.
- */
- protected function checkPasswordValidity($login_name, $organization, $password)
- {
-
- switch ($this->getUserClass($login_name, $organization)) {
- case self::USER_PROJECT:
- return $this->project->checkSuperAdminPassword($password);
-
- case self::USER_STAFF:
- $pwd_hash = $this->project->getValueHash($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);
-
- case self::USER_OLD_STAFF:
- $pwd_hash = md5($password);
-
- $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 {
- $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'] = self::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);
-
- }
-
- return true;
- }
- }
-
- return false;
- }
-
- /**
* Should be called after answering the request to allow the Target
* to check if all required registry values have been set correctly.
*
@@ -285,162 +195,30 @@
public final function getCurrentUser()
{
if (! self::$currentUser) {
- self::$currentUser = $this->_loadClass('User', true, array($this->session));
+ if ($this->session->__isset('__user_definition')) {
+ $className = $this->session->__get('__user_definition');
+ self::$currentUser = $this->_loadClass('User', true, array($this->session, new $className()));
+ } else {
+ self::$currentUser = $this->getUser(null, null);
+ }
}
return self::$currentUser;
}
/**
- *
- * @return array
- */
- public function getNoUserArray()
- {
- return array(
- 'user_active' => false,
- 'user_role' => 'nologin',
- 'user_organization_id' => 0,
- );
- }
-
- protected function getOldStaffUser($login_name, $organization)
- {
- /**
- * Read the needed parameters from the different tables, lots of renames for backward
- * compatibility
- */
- $select = new Zend_Db_Select($this->db);
- $select->from('gems__staff', array('user_id'=>'gsf_id_user',
- 'user_login'=>'gsf_login',
- 'user_email'=>'gsf_email',
- 'user_group'=>'gsf_id_primary_group',
- 'user_locale'=>'gsf_iso_lang',
- 'user_logout'=>'gsf_logout_on_survey'))
- ->columns(array('user_name'=>"(concat(coalesce(concat(`gems__staff`.`gsf_first_name`,_utf8' '),_utf8''),coalesce(concat(`gems__staff`.`gsf_surname_prefix`,_utf8' '),_utf8''),coalesce(`gems__staff`.`gsf_last_name`,_utf8'')))"))
- ->join('gems__groups', 'gsf_id_primary_group = ggp_id_group', array('user_role'=>'ggp_role'))
- ->join('gems__organizations', 'gsf_id_organization = gor_id_organization',
- array(
- 'user_organization_id'=>'gor_id_organization',
- 'user_organization_name'=>'gor_name'))
- ->where('ggp_group_active = 1')
- ->where('gor_active = 1')
- ->where('gsf_active = 1')
- ->where('gsf_login = ?')
- ->limit(1);
-
- // For a multi-layout project we need to select the appropriate style too,
- // but as PATCHES may not be in effect we have to try two selects
- $select2 = clone $select;
- $select2->columns(array('user_style' => 'gor_style'), 'gems__organizations');
-
- try {
- // Fails before patch has run...
- return $this->db->fetchRow($select2, array($login_name), Zend_Db::FETCH_ASSOC);
-
- } catch (Zend_Db_Exception $e) {
- // So then we try the old method
- return $this->db->fetchRow($select, array($login_name), Zend_Db::FETCH_ASSOC);
- }
- }
-
- /**
- * Overrule this function to handle your own - project
- * specific = user classes.
- *
- * @param string $class Class name returned by getUserClass()
- * @param string $login_name
- * @param int $organization
- * @return array
- */
- protected function getProjectClassUser($class, $login_name, $organization)
- {
- throw new Gems_Exception_Coding(sprintf("Unknown user class '%s' found for user '%s'.", $class, $login_name));
- }
-
- /**
- *
- * @param string $login_name
- * @param int $organization
- * @return array
- */
- protected function getProjectUser($login_name, $organization)
- {
- return array(
- 'user_id' => 1,
- 'user_name' => $login_name,
- 'user_group' => 800,
- 'user_role' => 'master',
- 'user_style' => 'gems',
- 'user_organization_id' => $organization,
- 'user_organization_name' => 'SUPER ADMIN',
- 'allowedOrgs' => array($organization => 'SUPER ADMIN')
- );
- }
-
- protected function getStaffUser($login_name, $organization)
- {
- $select = new Zend_Db_Select($this->db);
- $select->from('gems__user_logins', array('user_login_id' => 'gul_id_user'))
- ->join('gems__staff', 'gul_login = gsf_login AND gul_id_organization = gsf_id_organization', array(
- 'user_login' => 'gsf_login',
- 'user_id' => 'gsf_id_user',
- 'user_email'=>'gsf_email',
- 'user_group'=>'gsf_id_primary_group',
- 'user_locale'=>'gsf_iso_lang',
- 'user_logout'=>'gsf_logout_on_survey'))
- ->columns(array('user_name'=>"(concat(coalesce(concat(`gems__staff`.`gsf_first_name`,_utf8' '),_utf8''),coalesce(concat(`gems__staff`.`gsf_surname_prefix`,_utf8' '),_utf8''),coalesce(`gems__staff`.`gsf_last_name`,_utf8'')))"))
- ->join('gems__groups', 'gsf_id_primary_group = ggp_id_group', array('user_role'=>'ggp_role'))
- ->join('gems__organizations', 'gul_id_organization = gor_id_organization',
- array(
- 'user_organization_id'=>'gor_id_organization',
- 'user_organization_name'=>'gor_name',
- 'user_style' => 'gor_style'))
- ->where('ggp_group_active = 1')
- ->where('gor_active = 1')
- ->where('gsf_active = 1')
- ->where('gul_can_login = 1')
- ->where('gul_login = ?')
- ->where('gul_id_organization = ?')
- ->limit(1);
-
- return $this->db->fetchRow($select, array($login_name, $organization), Zend_Db::FETCH_ASSOC);
- }
-
- /**
* Returns a user object, that may be empty if no user exist.
*
* @param string $login_name
* @param int $organization
* @return Gems_User_User But ! ->isActive when the user does not exist
*/
- public final function getUser($login_name, $organization)
+ public function getUser($login_name, $organization)
{
- $class = $this->getUserClass($login_name, $organization);
- switch ($class) {
- case self::USER_PROJECT:
- $values = $this->getProjectUser($login_name, $organization);
- break;
+ $definition = $this->getUserClass($login_name, $organization);
- case self::USER_STAFF:
- $values = $this->getStaffUser($login_name, $organization);
- break;
+ $values = $definition->getUserData($login_name, $organization);
- case self::USER_OLD_STAFF:
- $values = $this->getOldStaffUser($login_name, $organization);
- break;
-
- case self::USER_NOLOGIN:
- case null:
- case false:
- $values = $this->getNoUserArray();
- break;
-
- default:
- $values = $this->getProjectClassUser($class, $login_name, $organization);
- }
-
- $values['user_class'] = $class;
if (! isset($values['user_active'])) {
$values['user_active'] = true;
}
@@ -449,11 +227,13 @@
//Load the allowed organizations
$values['allowedOrgs'] = $this->getAllowedOrganizations();
}
+ $values['__user_definition'] = get_class($definition);
- return $this->_loadClass('User', true, array($values));
+ return $this->_loadClass('User', true, array($values, $definition));
}
/**
+ * Get a staff user using the $staff_id
*
* @param int $staff_id
* @return Gems_User_User But ! ->isActive when the user does not exist
@@ -474,18 +254,18 @@
*
* @param string $login_name
* @param int $organization
- * @return string
+ * @return Gems_User_UserDefinitionInterface
*/
protected function getUserClass($login_name, $organization)
{
if ($this->isProjectUser($login_name)) {
- return self::USER_PROJECT;
+ return $this->_getClass('ProjectUserDefinition');
}
try {
$sql = "SELECT gul_user_class FROM gems__user_logins WHERE gul_can_login = 1 AND gul_login = ? AND gul_id_organization = ?";
if ($class = $this->db->fetchOne($sql, array($login_name, $organization))) {
- return $class;
+ return $this->_getClass($class . 'Definition');
}
} catch (Zend_Db_Exception $e) {
@@ -513,10 +293,10 @@
// MUtil_Echo::r($e);
}
- return self::USER_OLD_STAFF;
+ return $this->_getClass(self::USER_OLD_STAFF . 'Definition');
}
- return self::USER_NOLOGIN;
+ return $this->_getClass('NoLoginDefinition');
}
protected function isProjectUser($login_name)
Deleted: branches/newUser2/classes/Gems/Validate/GemsPasswordUsername.php
===================================================================
--- branches/newUser2/classes/Gems/Validate/GemsPasswordUsername.php 2011-11-10 17:15:11 UTC (rev 200)
+++ branches/newUser2/classes/Gems/Validate/GemsPasswordUsername.php 2011-11-11 11:41:20 UTC (rev 201)
@@ -1,186 +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.
- *
- * @version $Id$
- * @package Gems
- * @subpackage Validate
- * @copyright Copyright (c) 2011 Erasmus MC
- * @license New BSD License
- */
-
-/**
- * OBSOLETE, we now use Gems_Auth with a Zend_Auth_Adapter_DbTable
- *
- * @deprecated
- * @package Gems
- * @subpackage Validate
- * @copyright Copyright (c) 2011 Erasmus MC
- * @license New BSD License
- */
-class Gems_Validate_GemsPasswordUsername extends Zend_Validate_Db_Abstract
-{
- /**
- * Error constants
- */
- const ERROR_DATABASE_NOT_INSTALLED = 'notInstalled';
- const ERROR_PASSWORD_WRONG = 'wrongPassword';
- const ERROR_PASSWORD_USERNAME_NOTFOUND = 'notFound';
- const ERROR_PASSWORD_USERNAME_NOTTHERE = 'notThere';
- const ERROR_PASSWORD_DELAY = 'blockedDelay';
-
- /**
- * @var array Message templates
- */
- protected $_messageTemplates = array(
- self::ERROR_DATABASE_NOT_INSTALLED => 'Installation not complete! Login is not yet possible!',
- self::ERROR_PASSWORD_WRONG => 'Wrong password.',
- self::ERROR_PASSWORD_USERNAME_NOTFOUND => 'Combination of username password not found.',
- self::ERROR_PASSWORD_USERNAME_NOTTHERE => 'Specify a password and username.',
- self::ERROR_PASSWORD_DELAY => 'Your account is temporarily blocked, please wait %value% minutes'
- );
-
- protected $_passwordField;
- protected $_usernameField;
-
- /**
- * Exponent to use when calculating delay
- * @var int
- */
- protected $_delayFactor = 4;
-
- /**
- * Provides basic configuration for use with Zend_Validate_Db Validators
- * Setting $exclude allows a single record to be excluded from matching.
- * The KeyFields are fields that occur as names in the context of the form and that
- * identify the current row - that can have the value.
- * A database adapter may optionally be supplied to avoid using the registered default adapter.
- *
- * @param string $usernameField The form field containing the login name
- * @param string $passwordField The form field containing the password
- * @param Zend_Db_Adapter_Abstract $adapter An optional database adapter to use.
- */
- public function __construct($usernameField, $passwordField, Zend_Db_Adapter_Abstract $adapter = null, $delayFactor = null)
- {
- parent::__construct('gems__staff', 'gsf_login', null, $adapter);
-
- $this->_usernameField = $usernameField;
- $this->_passwordField = $passwordField;
-
- if (isset($delayFactor)) {
- $this->_delayFactor = $delayFactor;
- }
- }
-
- public function isValid($value, $context = array())
- {
- if (isset($context[$this->_usernameField])) {
- $userinput = true;
- $username = $context[$this->_usernameField];
- } else {
- $userinput = false;
- $username = $this->_usernameField;
- }
- $password = isset($context[$this->_passwordField]) ? $context[$this->_passwordField] : null;
-
- if ($username && $password) {
-
- /************************************
- * Project.ini super admin password *
- ************************************/
- $escortProject = GemsEscort::getInstance()->project;
- if (isset($escortProject->admin) && $escortProject->admin['user'] == $username) {
- if ($escortProject->admin['pwd'] == $password) {
- return true;
- } else {
- $this->_error(self::ERROR_PASSWORD_USERNAME_NOTFOUND);
- return false;
- }
- }
-
- /*********************
- * Check in database *
- *********************/
-
- /**
- * Check for an adapter being defined. if not, fetch the default adapter.
- */
- if ($this->_adapter === null) {
- $this->_adapter = Zend_Db_Table_Abstract::getDefaultAdapter();
- if (null === $this->_adapter) {
- require_once 'Zend/Validate/Exception.php';
- throw new Zend_Validate_Exception('No database adapter present');
- }
- }
-
- $condition = $this->_adapter->quoteIdentifier('gsf_password') . ' = ?';
- $this->_exclude = $this->_adapter->quoteInto($condition, md5($password));
-
- try {
- /**
- * Lookup last failed login and number of failed logins
- * /
- try {
- $sql = "SELECT gus_failed_logins, UNIX_TIMESTAMP(gus_last_failed)
- AS gus_last_failed FROM {$this->_table} WHERE gus_login = ?";
- $results = $this->_adapter->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'));
- }
-
- $delay = pow($results['gus_failed_logins'], $this->_delayFactor);
- $remaining = ($results['gus_last_failed'] + $delay) - time();
-
- if ($results['gus_failed_logins'] > 0 && $remaining > 0) {
- $this->_obscureValue = false;
- $this->_error(self::ERROR_PASSWORD_DELAY, ceil($remaining / 60));
- return false;
- } // */
-
- if ($this->_query($username)) {
- return true;
- } else {
- if ($userinput) {
- $this->_error(self::ERROR_PASSWORD_USERNAME_NOTFOUND);
- } else {
- $this->_error(self::ERROR_PASSWORD_WRONG);
- }
- return false;
- }
- } catch (Zend_Db_Exception $zde) {
- $this->_error(self::ERROR_DATABASE_NOT_INSTALLED);
- return false;
- }
-
- } else {
- $this->_error(self::ERROR_PASSWORD_USERNAME_NOTTHERE);
- return false;
- }
- }
-}
Modified: branches/newUser2/classes/MUtil/Model/FormBridge.php
===================================================================
--- branches/newUser2/classes/MUtil/Model/FormBridge.php 2011-11-10 17:15:11 UTC (rev 200)
+++ branches/newUser2/classes/MUtil/Model/FormBridge.php 2011-11-11 11:41:20 UTC (rev 201)
@@ -594,7 +594,7 @@
self::DISPLAY_OPTIONS, self::TAB_OPTIONS);
if (method_exists($this->form, 'addTab')) {
- return $this->form->addTab($name, $options['value']);
+ return $this->form->addTab($name, isset($options['value']) ? $options['value'] : null);
} else {
$element = new MUtil_Form_Element_Tab($name, $options);
$this->form->addElement($element);
Modified: branches/newUser2/configs/db/tables/gems__staff.20.sql
===================================================================
--- branches/newUser2/configs/db/tables/gems__staff.20.sql 2011-11-10 17:15:11 UTC (rev 200)
+++ branches/newUser2/configs/db/tables/gems__staff.20.sql 2011-11-11 11:41:20 UTC (rev 201)
@@ -2,7 +2,7 @@
-- Table containing the project staff
--
CREATE TABLE if not exists gems__staff (
- gsf_id_user bigint unsigned not null references gems__users (gus_id_user),
+ gsf_id_user bigint unsigned not null references gems__user_ids (gui_id_user),
gsf_login varchar(20) CHARACTER SET 'utf8' COLLATE 'utf8_general_ci' not null,
gsf_id_organization bigint not null references gems__organizations (gor_id_organization),
Deleted: branches/newUser2/configs/db/tables/gems__users.10.sql
===================================================================
--- branches/newUser2/configs/db/tables/gems__users.10.sql 2011-11-10 17:15:11 UTC (rev 200)
+++ branches/newUser2/configs/db/tables/gems__users.10.sql 2011-11-11 11:41:20 UTC (rev 201)
@@ -1,31 +0,0 @@
-
--- Table containing the users that are allowed to login
---
-CREATE TABLE if not exists gems__users (
- gus_id_user bigint unsigned not null,
-
- gus_id_organization bigint not null references gems__organizations (gor_id_organization),
- gus_login varchar(30) CHARACTER SET 'utf8' COLLATE 'utf8_general_ci' not null,
-
- gus_user_class varchar(30) CHARACTER SET 'utf8' COLLATE 'utf8_general_ci' null,
- gus_active boolean not null default 1,
-
- -- Common fields for standard 'store password in Gems' logins
- -- Not every gus_user_class will use them
- gus_password varchar(32) CHARACTER SET 'utf8' COLLATE 'utf8_general_ci' null,
- gus_failed_logins int(11) unsigned not null default 0,
- gus_last_failed timestamp null,
- gus_reset_key varchar(64) CHARACTER SET 'utf8' COLLATE 'utf8_general_ci' null,
- gus_reset_requested timestamp null,
- gus_reset_required boolean not null default 0,
-
- gus_changed timestamp not null default current_timestamp on update current_timestamp,
- gus_changed_by bigint unsigned not null,
- gus_created t...
[truncated message content] |
|
From: <gem...@li...> - 2011-11-10 17:15:22
|
Revision: 200
http://gemstracker.svn.sourceforge.net/gemstracker/?rev=200&view=rev
Author: matijsdejong
Date: 2011-11-10 17:15:11 +0000 (Thu, 10 Nov 2011)
Log Message:
-----------
Almost ready with #31.
The user can edit his/her account and password.
getAllowedOrganizations moved to User and UserLoader
GemsEscort cleaned up
TODO: lost password
Modified Paths:
--------------
branches/newUser2/classes/Gems/Default/AskAction.php
branches/newUser2/classes/Gems/Default/ExportAction.php
branches/newUser2/classes/Gems/Default/IndexAction.php
branches/newUser2/classes/Gems/Default/OptionAction.php
branches/newUser2/classes/Gems/Default/OrganizationAction.php
branches/newUser2/classes/Gems/Project/Organization/MultiOrganizationInterface.php
branches/newUser2/classes/Gems/User/User.php
branches/newUser2/classes/Gems/User/UserLoader.php
branches/newUser2/classes/GemsEscort.php
Added Paths:
-----------
branches/newUser2/classes/Gems/User/UserPasswordValidator.php
Modified: branches/newUser2/classes/Gems/Default/AskAction.php
===================================================================
--- branches/newUser2/classes/Gems/Default/AskAction.php 2011-11-10 15:47:29 UTC (rev 199)
+++ branches/newUser2/classes/Gems/Default/AskAction.php 2011-11-10 17:15:11 UTC (rev 200)
@@ -82,13 +82,14 @@
/***************
* Get the url *
***************/
- $url = $token->getUrl($language, $this->session->user_id ? $this->session->user_id : $respId);
+ $user = $this->loader->getCurrentUser();
+ $url = $token->getUrl($language, $user->getUserId() ? $user->getUserId() : $respId);
/************************
* Optional user logout *
************************/
- if (isset($this->session->user_logout) && $this->session->user_logout) {
- $this->escort->afterLogout();
+ if ($user->isLogoutOnSurvey()) {
+ $user->unsetAsCurrentUser();
}
/***********************************
Modified: branches/newUser2/classes/Gems/Default/ExportAction.php
===================================================================
--- branches/newUser2/classes/Gems/Default/ExportAction.php 2011-11-10 15:47:29 UTC (rev 199)
+++ branches/newUser2/classes/Gems/Default/ExportAction.php 2011-11-10 17:15:11 UTC (rev 200)
@@ -144,7 +144,7 @@
{
//Read some data from tables, initialize defaults...
$surveys = $this->db->fetchPairs('SELECT gsu_id_survey, gsu_survey_name FROM gems__surveys WHERE gsu_active = 1 ORDER BY gsu_survey_name');
- $organizations = $this->escort->getAllowedOrganizations();
+ $organizations = $this->loader->getCurrentUser()->getAllowedOrganizations();
$types = $this->export->getExportClasses();
//Create the basic form
@@ -230,7 +230,7 @@
$answerModel = $survey->getAnswerModel($language);
//Now add the organization id => name mapping
- $answerModel->set('organizationid', 'multiOptions', $this->escort->getAllowedOrganizations());
+ $answerModel->set('organizationid', 'multiOptions', $this->loader->getCurrentUser()->getAllowedOrganizations());
if (count($answers) === 0) {
$answers[0] = array('' => sprintf($this->_('No %s found.'), $this->getTopic(0)));
Modified: branches/newUser2/classes/Gems/Default/IndexAction.php
===================================================================
--- branches/newUser2/classes/Gems/Default/IndexAction.php 2011-11-10 15:47:29 UTC (rev 199)
+++ branches/newUser2/classes/Gems/Default/IndexAction.php 2011-11-10 17:15:11 UTC (rev 200)
@@ -66,21 +66,6 @@
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.
- *
- * @param array $formValues
- * @return Zend_Auth_Adapter_Interface
- */
- protected function _getAuthAdapter($formValues) {
- $adapter = new Zend_Auth_Adapter_DbTable($this->db, 'gems__staff', 'gsf_login', 'gsf_password');
- $adapter->setIdentity($formValues['userlogin']);
- $adapter->setCredential($this->escort->passwordHash(null, $formValues['password'], false));
- return $adapter;
- }
-
- /**
* New version of login form
*
* @return Gems_Form
@@ -89,8 +74,6 @@
{
Gems_Html::init();
- $this->track[] = 'Get login form.';
-
$delayFactor = (isset($this->project->account) && isset($this->project->account['delayFactor']) ? $this->project->account['delayFactor'] : null);
$form = new Gems_Form(array('labelWidthFactor' => $this->labelWidthFactor));
Modified: branches/newUser2/classes/Gems/Default/OptionAction.php
===================================================================
--- branches/newUser2/classes/Gems/Default/OptionAction.php 2011-11-10 15:47:29 UTC (rev 199)
+++ branches/newUser2/classes/Gems/Default/OptionAction.php 2011-11-10 17:15:11 UTC (rev 200)
@@ -1,6 +1,5 @@
<?php
-
/**
* Copyright (c) 2011, Erasmus MC
* All rights reserved.
@@ -26,58 +25,47 @@
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/**
*
- * @author Matijs de Jong
- * @since 1.0
- * @version 1.1
- * @package Gems
+ *
+ * @package Gems
* @subpackage Default
+ * @author Matijs de Jong <mj...@ma...>
+ * @copyright Copyright (c) 2011 Erasmus MC
+ * @license New BSD License
+ * @version $Id$
*/
/**
*
- * @author Matijs de Jong
- * @package Gems
+ * @package Gems
* @subpackage Default
+ * @copyright Copyright (c) 2011 Erasmus MC
+ * @license New BSD License
+ * @since Class available since version 1.1
*/
class Gems_Default_OptionAction extends Gems_Controller_BrowseEditAction
{
public $autoFilter = false;
/**
- * Adds elements from the model to the bridge that creates the form.
*
- * Overrule this function to add different elements to the browse table, without
- * having to recode the core table building code.
- *
- * @param MUtil_Model_FormBridge $bridge
- * @param MUtil_Model_ModelAbstract $model
- * @param array $data The data that will later be loaded into the form
- * @param optional boolean $new Form should be for a new element
- * @return void|array When an array of new values is return, these are used to update the $data array in the calling function
+ * @var Gems_Project_ProjectSettings
*/
- protected function addFormElements(MUtil_Model_FormBridge $bridge, MUtil_Model_ModelAbstract $model, array $data, $new = false)
- {
- $bridge->addHidden( 'gus_id_user');
- $bridge->addHidden( 'gus_id_organization');
- $bridge->addHidden( 'gsf_id_user');
- $bridge->addExhibitor('gus_login', array('size' => 15, 'minlength' => 4));
- $bridge->addText( 'gsf_first_name');
- $bridge->addText( 'gsf_surname_prefix');
- $bridge->addText( 'gsf_last_name');
- $bridge->addText( 'gsf_email', array('size' => 30));
+ public $project;
- $bridge->addRadio( 'gsf_gender', 'separator', '');
-
- $bridge->addSelect( 'gsf_iso_lang', array('label' => $this->_('Language'), 'multiOptions' => $this->util->getLocalized()->getLanguages()));
- }
-
+ /**
+ * Hook to perform action after a record (with changes) was saved
+ *
+ * As the data was already saved, it can NOT be changed anymore
+ *
+ * @param array $data
+ * @param boolean $isNew
+ * @return boolean True when you want to display the default 'saved' messages
+ */
public function afterSave(array $data, $isNew)
{
- $this->escort->loadLoginInfo($data['gus_login']);
+ // Reload the current user data
+ $this->loader->getUser($data['gsf_login'], $data['gsf_id_organization']);
}
public function changePasswordAction()
@@ -87,20 +75,26 @@
*************/
$form = $this->createForm();
- $sql = "SELECT CASE WHEN gus_password IS NULL THEN 0 ELSE 1 END FROM gems__users WHERE gus_id_user = ? AND gus_id_organization = ?";
- if ($this->db->fetchOne($sql, array($this->session->user_id, $this->session->user_organization_id))) {
- // Veld current password
+ $user = $this->loader->getCurrentUser();
+
+ $sql = "SELECT CASE WHEN gup_password IS NULL THEN 0 ELSE 1 END FROM gems__user_passwords WHERE gup_id_user = ?";
+
+ if ($this->db->fetchOne($sql, $user->getUserLoginId())) {
+ // Field current password
+ //
+ // This is only used when the password is already set, which may not always be the case
+ // e.g. when using embedded login in Pulse.
$element = new Zend_Form_Element_Password('old_password');
$element->setLabel($this->_('Current password'));
$element->setAttrib('size', 10);
$element->setAttrib('maxlength', 20);
$element->setRenderPassword(true);
$element->setRequired(true);
- $element->addValidator(new Gems_Validate_GemsPasswordUsername($this->session->user_login, 'old_password', $this->db));
+ $element->addValidator(new Gems_User_UserPasswordValidator($user, $this->translate));
$form->addElement($element);
}
- // Veld new password
+ // Field new password
$element = new Zend_Form_Element_Password('new_password');
$element->setLabel($this->_('New password'));
$element->setAttrib('size', 10);
@@ -111,7 +105,7 @@
$element->addValidator(new MUtil_Validate_IsConfirmed('repeat_password', $this->_('Repeat password')));
$form->addElement($element);
- // Veld repeat password
+ // Field repeat password
$element = new Zend_Form_Element_Password('repeat_password');
$element->setLabel($this->_('Repeat password'));
$element->setAttrib('size', 10);
@@ -131,20 +125,15 @@
****************/
if ($this->_request->isPost() && $form->isValid($_POST)) {
- $data['gus_id_user'] = $this->session->user_id;
- $data['gus_id_organization'] = $this->session->user_organization_id;
- $data['gus_password'] = $this->escort->passwordHash(null, $_POST['new_password']);
+ $data['gup_id_user'] = $user->getUserLoginId();
+ $data['gup_password'] = $this->project->getValueHash($_POST['new_password']);
- $this->getModel()->save($data);
+ $model = new MUtil_Model_TableModel('gems__user_passwords');
+ Gems_Model::setChangeFieldsByPrefix($model, 'gup', $user->getUserId());
- // $data = $_POST;
- // $data['name'] = '';
- // $data['type'] = $this->_('raw');
-
- // $results = array();
- // $this->_runScript($data, $results);
+ $model->save($data);
$this->addMessage($this->_('New password is active.'));
- $this->afterSaveRoute($this->getRequest());
+ $this->_reroute(array($this->getRequest()->getActionKey() => 'edit'));
} else {
if (isset($_POST['old_password'])) {
@@ -185,23 +174,23 @@
*/
public function createModel($detailed, $action)
{
- $model = new Gems_Model_UserModel('staff', 'gems__staff', array('gus_id_user' => 'gsf_id_user'), 'gsf');
- $model->copyKeys();
+ $model = $this->loader->getModels()->getStaffModel();
- $model->set('gus_login', 'label', $this->_('Login Name'));
- $model->set('gsf_email', 'label', $this->_('E-Mail'));
- $model->set('gsf_first_name', 'label', $this->_('First name'));
- $model->set('gsf_surname_prefix', 'label', $this->_('Surname prefix'), 'description', 'de, van der, \'t, etc...');
- $model->set('gsf_last_name', 'label', $this->_('Last name'), 'required', true);
+ $model->set('gsf_login', 'label', $this->_('Login Name'), 'elementClass', 'Exhibitor');
+ $model->set('gsf_email', 'label', $this->_('E-Mail'), 'size', 30);
+ $model->set('gsf_first_name', 'label', $this->_('First name'));
+ $model->set('gsf_surname_prefix', 'label', $this->_('Surname prefix'), 'description', 'de, van der, \'t, etc...');
+ $model->set('gsf_last_name', 'label', $this->_('Last name'), 'required', true);
+ $model->set('gsf_gender', 'label', $this->_('Gender'), 'multiOptions', $this->util->getTranslated()->getGenders(),
+ 'elementClass', 'Radio', 'separator', '');
+ $model->set('gsf_iso_lang', 'label', $this->_('Language'), 'multiOptions', $this->util->getLocalized()->getLanguages());
- $model->set('gsf_gender', 'label', $this->_('Gender'), 'multiOptions', $this->util->getTranslated()->getGenders());
-
return $model;
}
public function editAction()
{
- $this->getModel()->setFilter(array('gus_id_user' => $this->session->user_id));
+ $this->getModel()->setFilter(array('gsf_id_user' => $this->loader->getCurrentUser()->getUserId()));
if ($form = $this->processForm()) {
$this->html->h3(sprintf($this->_('Options'), $this->getTopic()));
@@ -222,7 +211,7 @@
WHERE glac.glac_name = 'index.login'
ORDER BY glua.glua_created DESC LIMIT 10";
- $activity = $this->db->fetchAll($sql, $this->session->user_id);
+ $activity = $this->db->fetchAll($sql, $this->loader->getCurrentUser()->getUserId());
foreach (array_keys($activity) as $key) {
$date = new MUtil_Date($activity[$key]['glua_created']);
Modified: branches/newUser2/classes/Gems/Default/OrganizationAction.php
===================================================================
--- branches/newUser2/classes/Gems/Default/OrganizationAction.php 2011-11-10 15:47:29 UTC (rev 199)
+++ branches/newUser2/classes/Gems/Default/OrganizationAction.php 2011-11-10 17:15:11 UTC (rev 200)
@@ -50,7 +50,7 @@
$url = base64_decode($request->getParam('current_uri'));
$oldOrgId = $this->session->user_organization_id;
- $allowedOrganizations = $this->escort->getAllowedOrganizations();
+ $allowedOrganizations = $this->loader->getCurrentUser()->getAllowedOrganizations();
if ($orgId = array_search($org, $allowedOrganizations)) {
$this->session->user_organization_id = $orgId;
$this->session->user_organization_name = $allowedOrganizations[$orgId];
Modified: branches/newUser2/classes/Gems/Project/Organization/MultiOrganizationInterface.php
===================================================================
--- branches/newUser2/classes/Gems/Project/Organization/MultiOrganizationInterface.php 2011-11-10 15:47:29 UTC (rev 199)
+++ branches/newUser2/classes/Gems/Project/Organization/MultiOrganizationInterface.php 2011-11-10 17:15:11 UTC (rev 200)
@@ -1,34 +1,34 @@
<?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.
- */
-
+
/**
+ * 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.
+ */
+
+/**
* Marker interface for Pulse Projects having respondents
* in only multiple organization.
*
@@ -49,9 +49,4 @@
interface Gems_Project_Organization_MultiOrganizationInterface
{
public function getUserOrganization();
-
- /**
- * Return an array of OrgId=>OrgName with all organizations the currently logged in user has access to
- */
- public function getAllowedOrganizations($userId = null);
}
Modified: branches/newUser2/classes/Gems/User/User.php
===================================================================
--- branches/newUser2/classes/Gems/User/User.php 2011-11-10 15:47:29 UTC (rev 199)
+++ branches/newUser2/classes/Gems/User/User.php 2011-11-10 17:15:11 UTC (rev 200)
@@ -191,9 +191,19 @@
if (! $this->_vars instanceof Zend_Session_Namespace) {
$sessionStore = $this->session;
- if (($sessionStore->__get('user_name') == $this->_vars->offsetGet('user_name')) &&
- ($sessionStore->__get('user_organization_id') == $this->_vars->offsetGet('user_organization_id'))) {
+ $notCurrent = true;
+ foreach (array('user_id', 'user_organization_id') as $key) {
+ if ($sessionStore->__isset($key) && $this->_vars->offsetGet($key)) {
+ $notCurrent = $sessionStore->__get($key) != $this->_vars->offsetGet($key);
+ } else {
+ $notCurrent = $sessionStore->__isset($key) || $this->_vars->offsetGet($key);
+ }
+ if ($notCurrent) {
+ break;
+ }
+ }
+ if (! $notCurrent) {
// When this is the case, use the Zend_Session_Namespace object with the current set values
// This way changes to this user object are reflected in the CurrentUser object and vice versa.
$this->setAsCurrentUser();
@@ -203,6 +213,16 @@
}
/**
+ * Get an array of OrgId => Org Name for all allowed organizations for the current loggedin user
+ *
+ * @return array
+ */
+ public function getAllowedOrganizations()
+ {
+ return $this->_getVar('allowedOrgs');
+ }
+
+ /**
* Returns the full user name (first, prefix, last).
*
* @return string
@@ -251,7 +271,12 @@
}
/**
+ * Returns the user id, that identifies this user within this installation.
*
+ * One user id might be connected to multiple logins for multiple organizations.
+ *
+ * YES! This is the one you need, not getUserLoginId().
+ *
* @return int
*/
public function getUserId()
@@ -260,7 +285,24 @@
}
/**
+ * Returns the User package user id, that is unique for each login / organization id
+ * combination, but does not directly identify this person.
*
+ * In other words, this is not the id you use to track who changed what. It is only
+ * used by parts of the User package.
+ *
+ * @return int
+ */
+ public function getUserLoginId()
+ {
+ if ($this->_hasVar('user_login_id')) {
+ return $this->_getVar('user_login_id');
+ }
+ return 0;
+ }
+
+ /**
+ *
* @return boolean True when a user can log in.
*/
public function isActive()
@@ -279,6 +321,16 @@
}
/**
+ * True when this user requires a logout after answering a survey
+ *
+ * @return boolean
+ */
+ public function isLogoutOnSurvey()
+ {
+ return (boolean) $this->_getVar('user_logout');
+ }
+
+ /**
* Set this user as the current user.
*
* This means that the data about this user will be stored in a session.
Modified: branches/newUser2/classes/Gems/User/UserLoader.php
===================================================================
--- branches/newUser2/classes/Gems/User/UserLoader.php 2011-11-10 15:47:29 UTC (rev 199)
+++ branches/newUser2/classes/Gems/User/UserLoader.php 2011-11-10 17:15:11 UTC (rev 200)
@@ -268,6 +268,16 @@
}
/**
+ * Get an array of OrgId => Org Name for all allowed organizations for the current loggedin user
+ *
+ * @return array
+ */
+ public function getAllowedOrganizations()
+ {
+ return $this->db->fetchPairs("SELECT gor_id_organization, gor_name FROM gems__organizations WHERE gor_active = 1 ORDER BY gor_name");
+ }
+
+ /**
* Get the currently loggin in user
*
* @return Gems_User_User
@@ -319,7 +329,8 @@
->where('gsf_login = ?')
->limit(1);
- //For a multi-layout project we need to select the appropriate style too
+ // For a multi-layout project we need to select the appropriate style too,
+ // but as PATCHES may not be in effect we have to try two selects
$select2 = clone $select;
$select2->columns(array('user_style' => 'gor_style'), 'gems__organizations');
@@ -370,8 +381,9 @@
protected function getStaffUser($login_name, $organization)
{
$select = new Zend_Db_Select($this->db);
- $select->from('gems__user_logins', array('user_login' => 'gul_login'))
+ $select->from('gems__user_logins', array('user_login_id' => 'gul_id_user'))
->join('gems__staff', 'gul_login = gsf_login AND gul_id_organization = gsf_id_organization', array(
+ 'user_login' => 'gsf_login',
'user_id' => 'gsf_id_user',
'user_email'=>'gsf_email',
'user_group'=>'gsf_id_primary_group',
@@ -433,6 +445,11 @@
$values['user_active'] = true;
}
+ if (! isset($values['allowedOrgs'])) {
+ //Load the allowed organizations
+ $values['allowedOrgs'] = $this->getAllowedOrganizations();
+ }
+
return $this->_loadClass('User', true, array($values));
}
Added: branches/newUser2/classes/Gems/User/UserPasswordValidator.php
===================================================================
--- branches/newUser2/classes/Gems/User/UserPasswordValidator.php (rev 0)
+++ branches/newUser2/classes/Gems/User/UserPasswordValidator.php 2011-11-10 17:15:11 UTC (rev 200)
@@ -0,0 +1,118 @@
+<?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.'));
+ }
+
+
+ }
+}
Modified: branches/newUser2/classes/GemsEscort.php
===================================================================
--- branches/newUser2/classes/GemsEscort.php 2011-11-10 15:47:29 UTC (rev 199)
+++ branches/newUser2/classes/GemsEscort.php 2011-11-10 17:15:11 UTC (rev 200)
@@ -791,7 +791,7 @@
'controller' => 'organization',
'action' => 'change-ui'), null, true);
$orgSwitch->raw('<form method="get" action="' . $url . '"><div><input type="hidden" name="current_uri" value="' . $currentUri . '" /><select name="org" onchange="javascript:this.form.submit();">');
- foreach ($this->getAllowedOrganizations() as $id => $org) {
+ foreach ($this->getLoader()->getCurrentUser()->getAllowedOrganizations() as $id => $org) {
$selected = '';
if ($id == $this->session->user_organization_id) {
$selected = ' selected="selected"';
@@ -924,43 +924,6 @@
}
}
- public function afterLogin($userName = null)
- {
- if (empty($userName)) {
- $userName = $_POST['userlogin'];
- }
-
- /**
- * Reset number of failed logins
- */
- try {
- $sql = "UPDATE gems__user_logins SET gul_failed_logins = 0, gul_last_failed = NULL, gul_changed = CURRENT_TIMESTAMP WHERE gul_login = ?";
- $this->db->query($sql, array($userName));
- } catch (Exception $e) {
- // swallow exception
- }
- }
-
- public function afterFailedLogin()
- {
- /**
- * Store the failed login attempt
- */
- try {
- if (isset($_POST['userlogin'])) {
- $sql = "UPDATE gems__user_logins SET gul_failed_logins = gul_failed_logins + 1, gul_last_failed = NOW(), gul_changed = CURRENT_TIMESTAMP WHERE gul_login = ?";
- $this->db->query($sql, array($_POST['userlogin']));
- }
- } catch (Exception $e) {
- // swallow exception
- }
- }
-
- public function afterLogout()
- {
- $this->session->unsetAll();
- }
-
/**
* Hook 2: Called in $this->run().
*
@@ -1091,27 +1054,7 @@
}
/**
- * Get an array of OrgId => Org Name for all allowed organizations for the current loggedin user
*
- * @@TODO Make ui to store allowed orgs in staff controller and change function to read these
- *
- * @return array
- */
- public function getAllowedOrganizations($userId = null)
- {
- if (is_null($userId)) $userId = $this->session->user_id;
- if ($userId == $this->session->user_id && isset($this->session->allowedOrgs)) {
- //If user is current user, read from session
- $allowedOrganizations = $this->session->allowedOrgs;
- } else {
- $allowedOrganizations = $this->db->fetchPairs("SELECT gor_id_organization, gor_name FROM gems__organizations WHERE gor_active = 1 ORDER BY gor_name");
- }
-
- return $allowedOrganizations;
- }
-
- /**
- *
* @return int The current active organization id or 0 when not known
*/
public function getCurrentOrganization()
@@ -1137,11 +1080,9 @@
*/
public function getCurrentUserId()
{
- if (isset($this->session->user_id)) {
- return $this->session->user_id;
- } else {
- return 0;
- }
+ $id = $this->getLoader()->getCurrentUser()->getUserId();
+
+ return $id ? $id : 0;
}
public function getDatabasePaths()
@@ -1270,52 +1211,11 @@
return false;
}
- public function loadLoginInfo($userName)
- {
- /**
- * Read the needed parameters from the different tables, lots of renames for backward
- * compatibility
- */
- $select = new Zend_Db_Select($this->db);
- $select->from('gems__staff', array(
- 'user_id' => 'gsf_id_user',
- 'user_login' => 'gsf_login',
- 'user_email'=>'gsf_email',
- 'user_group'=>'gsf_id_primary_group',
- 'user_locale'=>'gsf_iso_lang',
- 'user_logout'=>'gsf_logout_on_survey'))
- ->columns(array('user_name'=>"(concat(coalesce(concat(`gems__staff`.`gsf_first_name`,_utf8' '),_utf8''),coalesce(concat(`gems__staff`.`gsf_surname_prefix`,_utf8' '),_utf8''),coalesce(`gems__staff`.`gsf_last_name`,_utf8'')))"))
- ->join('gems__groups', 'gsf_id_primary_group = ggp_id_group', array('user_role'=>'ggp_role'))
- ->join('gems__organizations', 'gus_id_organization = gor_id_organization',
- array('user_organization_id'=>'gor_id_organization', 'user_organization_name'=>'gor_name'))
- ->where('ggp_group_active = ?', 1)
- ->where('gor_active = ?', 1)
- ->where('gus_active = ?', 1)
- ->where('gus_login = ?', $userName)
- ->limit(1);
-
- //For a multi-layout project we need to select the appropriate style too
- if ($this instanceof Gems_Project_Layout_MultiLayoutInterface) {
- $select->columns(array('user_style' => 'gor_style'), 'gems__organizations');
- }
-
-
- if ($result = $this->db->fetchRow($select, array(), Zend_Db::FETCH_ASSOC)) {
- // $this->session is a session object so we cannot use $this->session = $result
- foreach ($result as $name => $value) {
- $this->session->$name = $value;
- }
-
- if ($this instanceof Gems_Project_Organization_MultiOrganizationInterface) {
- //Load the allowed organizations into the session
- $this->session->allowedOrgs = $this->getAllowedOrganizations();
- }
- }
- }
-
/**
* Return a hashed version of the input value.
*
+ * @deprecated Since 1.5
+ *
* @param string $name Optional name, is here for ModelAbstract setOnSave compatibility
* @param string $value The value to hash.
* @param boolean $new Optional is new, is here for ModelAbstract setOnSave compatibility
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <gem...@li...> - 2011-11-10 15:47:40
|
Revision: 199
http://gemstracker.svn.sourceforge.net/gemstracker/?rev=199&view=rev
Author: matijsdejong
Date: 2011-11-10 15:47:29 +0000 (Thu, 10 Nov 2011)
Log Message:
-----------
Password check no works through user as well.
Modified Paths:
--------------
branches/newUser2/classes/Gems/User/User.php
branches/newUser2/classes/Gems/User/UserLoader.php
Modified: branches/newUser2/classes/Gems/User/User.php
===================================================================
--- branches/newUser2/classes/Gems/User/User.php 2011-11-10 15:29:54 UTC (rev 198)
+++ branches/newUser2/classes/Gems/User/User.php 2011-11-10 15:47:29 UTC (rev 199)
@@ -165,6 +165,17 @@
}
/**
+ * 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);
+ }
+
+ /**
* Should be called after answering the request to allow the Target
* to check if all required registry values have been set correctly.
*
@@ -203,7 +214,7 @@
/**
* Returns the group number of the current user.
- *
+ *
* @return int
*/
public function getGroup()
Modified: branches/newUser2/classes/Gems/User/UserLoader.php
===================================================================
--- branches/newUser2/classes/Gems/User/UserLoader.php 2011-11-10 15:29:54 UTC (rev 198)
+++ branches/newUser2/classes/Gems/User/UserLoader.php 2011-11-10 15:47:29 UTC (rev 199)
@@ -539,7 +539,7 @@
if ((self::$currentUser instanceof Gems_User_User) && self::$currentUser->isCurrentUser()) {
self::$currentUser->unsetAsCurrentUser();
}
- self::$currentUser = $user;
+ self::$currentUser = null;
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-10 15:30:03
|
Revision: 198
http://gemstracker.svn.sourceforge.net/gemstracker/?rev=198&view=rev
Author: matijsdejong
Date: 2011-11-10 15:29:54 +0000 (Thu, 10 Nov 2011)
Log Message:
-----------
Small bug fixes for #31
Modified Paths:
--------------
branches/newUser2/classes/Gems/Default/StaffAction.php
branches/newUser2/classes/Gems/Project/ProjectSettings.php
branches/newUser2/classes/Gems/User/User.php
branches/newUser2/classes/Gems/User/UserLoader.php
branches/newUser2/configs/db/patches.sql
Modified: branches/newUser2/classes/Gems/Default/StaffAction.php
===================================================================
--- branches/newUser2/classes/Gems/Default/StaffAction.php 2011-11-09 12:18:27 UTC (rev 197)
+++ branches/newUser2/classes/Gems/Default/StaffAction.php 2011-11-10 15:29:54 UTC (rev 198)
@@ -98,7 +98,7 @@
case Gems_User_UserLoader::USER_STAFF:
Gems_Model::addUserPassword($model);
$passwordField = 'gup_password';
- $model->setOnSave($passwordField, array($this->project, 'getValueHash'));
+ $model->setOnSave($passwordField, array($this->project, 'getValueHashForModel'));
break;
case Gems_User_UserLoader::USER_OLD_STAFF:
Modified: branches/newUser2/classes/Gems/Project/ProjectSettings.php
===================================================================
--- branches/newUser2/classes/Gems/Project/ProjectSettings.php 2011-11-09 12:18:27 UTC (rev 197)
+++ branches/newUser2/classes/Gems/Project/ProjectSettings.php 2011-11-10 15:29:54 UTC (rev 198)
@@ -206,9 +206,26 @@
$salt = $this->offsetExists('salt') ? $this->offsetGet('salt') : '';
if (false === strpos($salt, '%s')) {
- return md5($salt . $value, false);
+ $salted = $salt . $value;
} else {
- return md5(sprintf($salt, $value), false);
+ $salted = sprintf($salt, $value);
}
+
+ // MUtil_Echo::track($value, md5($salted));
+
+ return md5($salted, false);
}
+
+ /**
+ * Returns a salted hash on the
+ *
+ * @param string $name Fieldname
+ * @param string $value The value to hash
+ * @param string $isNew True when new
+ * @return string The salted hash as a 32-character hexadecimal number.
+ */
+ public function getValueHashForModel($name, $value, $isNew = false)
+ {
+ return $this->getValueHash($value);
+ }
}
Modified: branches/newUser2/classes/Gems/User/User.php
===================================================================
--- branches/newUser2/classes/Gems/User/User.php 2011-11-09 12:18:27 UTC (rev 197)
+++ branches/newUser2/classes/Gems/User/User.php 2011-11-10 15:29:54 UTC (rev 198)
@@ -202,6 +202,16 @@
}
/**
+ * Returns the group number of the current user.
+ *
+ * @return int
+ */
+ public function getGroup()
+ {
+ return $this->_getVar('user_group');
+ }
+
+ /**
* The locale set for this user..
*
* @return string
Modified: branches/newUser2/classes/Gems/User/UserLoader.php
===================================================================
--- branches/newUser2/classes/Gems/User/UserLoader.php 2011-11-09 12:18:27 UTC (rev 197)
+++ branches/newUser2/classes/Gems/User/UserLoader.php 2011-11-10 15:29:54 UTC (rev 198)
@@ -102,6 +102,7 @@
*/
public final function checkPassword($login_name, $organization, $password)
{
+ // MUtil_Echo::track($login_name, $organization, $password);
$success = $this->checkPasswordValidity($login_name, $organization, $password);
try {
@@ -152,7 +153,7 @@
} catch (Zend_Db_Exception $e) {
// Fall through as this does not work if the database upgrade did not run
- MUtil_Echo::r($e);
+ // MUtil_Echo::r($e);
}
return $success;
}
@@ -185,6 +186,8 @@
$db_pwd = $this->db->fetchOne($sql, array($login_name, $organization));
+ // MUtil_Echo::track($password, $pwd_hash, $db_pwd);
+
return ($pwd_hash == $db_pwd);
case self::USER_OLD_STAFF:
Modified: branches/newUser2/configs/db/patches.sql
===================================================================
--- branches/newUser2/configs/db/patches.sql 2011-11-09 12:18:27 UTC (rev 197)
+++ branches/newUser2/configs/db/patches.sql 2011-11-10 15:29:54 UTC (rev 198)
@@ -285,7 +285,10 @@
SELECT gsf_login, gsf_id_organization, 'OldStaffUser',
gsf_active,
gsf_changed, gsf_changed_by, gsf_created, gsf_created_by
- FROM gems__staff WHERE (gsf_login, gsf_id_organization) NOT IN (SELECT gul_login, gul_id_organization FROM gems__user_logins);
+ FROM gems__staff WHERE gsf_login IS NOT NULL AND
+ gsf_id_organization IS NOT NULL AND
+ gsf_id_organization != 0 AND
+ (gsf_login, gsf_id_organization) NOT IN (SELECT gul_login, gul_id_organization FROM gems__user_logins);
ALTER TABLE `gems__staff` CHANGE `gsf_id_user` `gsf_id_user` BIGINT( 20 ) UNSIGNED NOT NULL;
@@ -295,6 +298,12 @@
ALTER TABLE gems__organizations ADD gor_style varchar(15) CHARACTER SET 'utf8' COLLATE 'utf8_general_ci' not null default 'gems' AFTER gor_signature;
+INSERT INTO gems__user_ids (gui_id_user, gui_created)
+ SELECT gsf_id_user, gsf_created FROM gems__staff WHERE gsf_id_user NOT IN (SELECT gui_id_user FROM gems__user_ids);
+
+INSERT INTO gems__user_ids (gui_id_user, gui_created)
+ SELECT grs_id_user, grs_created FROM gems__respondents WHERE grs_id_user NOT IN (SELECT gui_id_user FROM gems__user_ids);
+
-- PATCH: Extra information for track fields
ALTER TABLE gems__track_fields ADD gtf_field_code varchar(20) CHARACTER SET 'utf8' COLLATE 'utf8_general_ci' null AFTER gtf_field_name,
ADD gtf_field_description varchar(200) CHARACTER SET 'utf8' COLLATE 'utf8_general_ci' null AFTER gtf_field_code,
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <gem...@li...> - 2011-11-09 12:18:35
|
Revision: 197
http://gemstracker.svn.sourceforge.net/gemstracker/?rev=197&view=rev
Author: matijsdejong
Date: 2011-11-09 12:18:27 +0000 (Wed, 09 Nov 2011)
Log Message:
-----------
Continue #31: Staff kan weer gewijzigd worden. Current user is nu beter geregeld, CronAction is daardoor eenvoudiger.
Nu nog option controller, change password, password lost en de import controller.
Modified Paths:
--------------
branches/newUser2/classes/Gems/Default/CronAction.php
branches/newUser2/classes/Gems/Default/IndexAction.php
branches/newUser2/classes/Gems/Default/StaffAction.php
branches/newUser2/classes/Gems/Menu/MenuAbstract.php
branches/newUser2/classes/Gems/Model.php
branches/newUser2/classes/Gems/User/User.php
branches/newUser2/classes/Gems/User/UserLoader.php
branches/newUser2/classes/GemsEscort.php
branches/newUser2/configs/db/patches.sql
branches/newUser2/configs/db/tables/gems__staff.20.sql
Removed Paths:
-------------
branches/newUser2/classes/Gems/User/PasswordValidator.php
Modified: branches/newUser2/classes/Gems/Default/CronAction.php
===================================================================
--- branches/newUser2/classes/Gems/Default/CronAction.php 2011-11-08 19:02:26 UTC (rev 196)
+++ branches/newUser2/classes/Gems/Default/CronAction.php 2011-11-09 12:18:27 UTC (rev 197)
@@ -102,12 +102,6 @@
/**
*
- * @var Gems_User_User
- */
- public $user;
-
- /**
- *
* @var Gems_Util
*/
public $util;
@@ -159,9 +153,9 @@
public function mailJob()
{
- $userLoader = $this->loader->getUserLoader();
- $oldUserLogin = $this->user->getLoginName();
- $oldUserOrg = $this->user->getOrganizationId();
+ $userLoader = $this->loader->getUserLoader();
+ $startUser = $userLoader->getCurrentUser();
+ $user = $startUser;
$model = $this->loader->getTracker()->getTokenModel();
$mailer = new Gems_Email_TemplateMailer($this->escort);
@@ -172,10 +166,14 @@
if ($jobs) {
foreach ($jobs as $job) {
- $user = $userLoader->getUserByStaffId($job['gmj_id_user_as']);
+ if ($user->getUserId() != $job['gmj_id_user_as']) {
+ $user = $userLoader->getUserByStaffId($job['gmj_id_user_as']);
+ }
if ($user->isActive()) {
- $user->setAsCurrentUser();
+ if (! $user->isCurrentUser()) {
+ $user->setAsCurrentUser();
+ }
// Set up filter
$filter = $this->defaultFilter;
@@ -217,12 +215,16 @@
$msg = $mailer->getMessages();
if (! $msg) {
- $msg[] = $this->_('No mails sent');
+ $msg[] = $this->_('No mails sent.');
}
+ if ($mailer->bounceCheck()) {
+ array_unshift($msg, $this->_('On this test system all mail will be delivered to the from address.'));
+ }
- $this->html->append($msg);
+ $this->addMessage($msg);
- $user = $userLoader->getUser($oldUserLogin, $oldUserOrg);
- $user->setAsCurrentUser();
+ if (! $startUser->isCurrentUser()) {
+ $startUser->setAsCurrentUser();
+ }
}
}
\ No newline at end of file
Modified: branches/newUser2/classes/Gems/Default/IndexAction.php
===================================================================
--- branches/newUser2/classes/Gems/Default/IndexAction.php 2011-11-08 19:02:26 UTC (rev 196)
+++ branches/newUser2/classes/Gems/Default/IndexAction.php 2011-11-09 12:18:27 UTC (rev 197)
@@ -159,7 +159,7 @@
* If already logged in, try to redirect to the first allowed and visible menu item
* if that fails, try to reroute to respondent/index
*/
- if (isset($this->session->user_id)) {
+ if ($this->loader->getCurrentUser()->isActive()) {
if ($menuItem = $this->menu->findFirst(array('allowed' => true, 'visible' => true))) {
$redirector = Zend_Controller_Action_HelperBroker::getStaticHelper('redirector');
$redirector->gotoRoute($menuItem->toRouteUrl($this->getRequest()));
@@ -167,7 +167,6 @@
$this->_reroute(array('controller' => 'respondent', 'action'=>'index'));
}
}
- // MUtil_Echo::track(get_class($this->loader->getUser('super', null)));
$form = $this->_getLoginForm();
@@ -179,19 +178,20 @@
$user->setAsCurrentUser();
/**
- * Fix current locale
+ * Fix current locale / organization in cookies
*/
- Gems_Cookies::setLocale($this->session->user_locale, $this->basepath->getBasePath());
+ Gems_Cookies::setLocale($user->getLocale(), $this->basepath->getBasePath());
+ Gems_Cookies::setOrganization($user->getOrganizationId(), $this->basepath->getBasePath());
/**
* Ready
*/
- $this->addMessage(sprintf($this->_('Login successful, welcome %s.'), $this->session->user_name));
+ $this->addMessage(sprintf($this->_('Login successful, welcome %s.'), $user->getFullName()));
/**
* Log the login
*/
- Gems_AccessLog::getLog($this->db)->log("index.login", $this->getRequest(), null, $this->session->user_id, true);
+ Gems_AccessLog::getLog($this->db)->log("index.login", $this->getRequest(), null, $user->getUserId(), true);
if ($previousRequestParameters = $this->session->previousRequestParameters) {
$this->_reroute(array('controller' => $previousRequestParameters['controller'], 'action' => $previousRequestParameters['action']), false);
@@ -200,37 +200,6 @@
$this->_reroute(array('controller' => null, 'action' => null), true);
}
}
-
- /*/ Load login data
- $this->escort->loadLoginInfo($_POST['userlogin']);
-
- /**
- * Perform any project specific post login activities
- * /
- $this->escort->afterLogin($_POST['userlogin']);
-
- /**
- * Fix current locale
- * /
- Gems_Cookies::setLocale($this->session->user_locale, $this->basepath->getBasePath());
-
- /**
- * Ready
- * /
- $this->addMessage(sprintf($this->_('Login successful, welcome %s.'), $this->session->user_name));
-
- /**
- * Log the login
- * /
- Gems_AccessLog::getLog($this->db)->log("index.login", $this->getRequest(), null, $this->session->user_id, true);
-
- if ($previousRequestParameters = $this->session->previousRequestParameters) {
- $this->_reroute(array('controller' => $previousRequestParameters['controller'], 'action' => $previousRequestParameters['action']), false);
- } else {
- // This reroutes to the first available menu page after login
- $this->_reroute(array('controller' => null, 'action' => null), true);
- }
- } // */
} else {
$errors = $form->getErrors();
@@ -243,9 +212,11 @@
public function logoffAction()
{
- $this->addMessage($this->_('Good bye: ') . $this->session->user_name);
- Gems_Auth::getInstance()->clearIdentity();
- $this->escort->afterLogout();
+ $user = $this->loader->getCurrentUser();
+
+ $this->addMessage(sprintf($this->_('Good bye: %s.'), $user->getFullName()));
+ $user->unsetAsCurrentUser();
+ // Gems_Auth::getInstance()->clearIdentity();
$this->_reroute(array('action' => 'index'), true);
}
Modified: branches/newUser2/classes/Gems/Default/StaffAction.php
===================================================================
--- branches/newUser2/classes/Gems/Default/StaffAction.php 2011-11-08 19:02:26 UTC (rev 196)
+++ branches/newUser2/classes/Gems/Default/StaffAction.php 2011-11-09 12:18:27 UTC (rev 197)
@@ -44,6 +44,8 @@
*/
class Gems_Default_StaffAction extends Gems_Controller_BrowseEditAction
{
+ public $defaultStaffDefinition = Gems_User_UserLoader::USER_STAFF;
+
public $filterStandard = array('gsf_active' => 1);
public $sortKey = array('name' => SORT_ASC);
@@ -92,39 +94,58 @@
{
$dbLookup = $this->util->getDbLookup();
+ switch ($data['gul_user_class']) {
+ case Gems_User_UserLoader::USER_STAFF:
+ Gems_Model::addUserPassword($model);
+ $passwordField = 'gup_password';
+ $model->setOnSave($passwordField, array($this->project, 'getValueHash'));
+ break;
+
+ case Gems_User_UserLoader::USER_OLD_STAFF:
+ $passwordField = 'gsf_password';
+ $model->setOnSave($passwordField, array($this, 'getOldPasswordHash'));
+ break;
+
+ default:
+ $passwordField = false;
+ break;
+ }
+
$model->set('gsf_id_primary_group', 'multiOptions', MUtil_Lazy::call($dbLookup->getAllowedStaffGroups));
if ($new) {
$model->set('gsf_id_primary_group', 'default', $dbLookup->getDefaultGroup());
- } else {
- $model->set('gus_password', 'description', $this->_('Enter only when changing'));
- $model->setSaveWhenNotNull('gus_password');
+ } elseif ($passwordField) {
+ $model->set($passwordField, 'description', $this->_('Enter only when changing'));
+ $model->setSaveWhenNotNull($passwordField);
}
- $model->setOnSave('gus_password', array($this->escort, 'passwordHash'));
$ucfirst = new Zend_Filter_Callback('ucfirst');
- $bridge->addHidden( 'gus_id_user');
- $bridge->addHidden( 'gsf_id_user'); // Needed for e-mail validation
- $bridge->addHidden( 'gsu_user_class');
- $bridge->addText( 'gsu_login', 'size', 15, 'minlength', 4,
- 'validator', $model->createUniqueValidator('gsu_login', array('gsu_id_user')));
+ $bridge->addHidden( 'gsf_id_user');
+ $bridge->addHidden( 'gul_id_user');
+ $bridge->addHidden( 'gup_id_user');
+ $bridge->addHidden( 'gul_user_class');
+ $bridge->addText( 'gsf_login', 'size', 15, 'minlength', 4,
+ 'validator', $model->createUniqueValidator('gsf_login', array('gsf_id_user')));
// Can the organization be changed?
if ($this->escort->hasPrivilege('pr.staff.edit.all')) {
- $bridge->addHiddenMulti($model->getKeyCopyName('gus_id_organization'));
- $bridge->addSelect('gus_id_organization');
+ $bridge->addHiddenMulti($model->getKeyCopyName('gsf_id_organization'));
+ $bridge->addSelect('gsf_id_organization');
} else {
- $bridge->addExhibitor('gus_id_organization');
+ $bridge->addExhibitor('gsf_id_organization');
}
- $bridge->addPassword('gus_password',
- 'label', $this->_('Password'),
- 'minlength', $this->project->passwords['MinimumLength'],
- // 'renderPassword', true,
- 'repeatLabel', $this->_('Repeat password'),
- 'required', $new,
- 'size', 15
- );
+ if ($passwordField) {
+ $bridge->addPassword($passwordField,
+ 'label', $this->_('Password'),
+ 'minlength', $this->project->passwords['MinimumLength'],
+ // 'renderPassword', true,
+ 'repeatLabel', $this->_('Repeat password'),
+ 'required', $new,
+ 'size', 15
+ );
+ }
$bridge->addRadio( 'gsf_gender', 'separator', '');
$bridge->addText( 'gsf_first_name', 'label', $this->_('First name'));
$bridge->addFilter( 'gsf_first_name', $ucfirst);
@@ -141,8 +162,8 @@
public function afterFormLoad(array &$data, $isNew)
{
- if (array_key_exists('gus_login', $data)) {
- $this->_instanceId = $data['gus_login'];
+ if (array_key_exists('glf_login', $data)) {
+ $this->_instanceId = $data['gsf_login'];
}
$sql = "SELECT ggp_id_group,ggp_role FROM gems__groups WHERE ggp_id_group = " . (int) $data['gsf_id_primary_group'];
@@ -169,11 +190,6 @@
{
// MUtil_Model::$verbose = true;
- /* $model = new Gems_Model_UserModel('staff', 'gems__staff', array('gus_id_user' => 'gsf_id_user'), 'gsf');
- if ($detailed) {
- $model->copyKeys();
- }
- //$model->resetOrder(); */
$model = $this->loader->getModels()->getStaffModel();
$model->set('gsf_login', 'label', $this->_('Login'));
@@ -193,7 +209,7 @@
$model->set('gsf_gender', 'label', $this->_('Gender'), 'multiOptions', $this->util->getTranslated()->getGenders());
if ($detailed) {
- $model->set('gul_user_class', 'default', Gems_User_UserLoader::USER_STAFF);
+ $model->set('gul_user_class', 'default', $this->defaultStaffDefinition);
$model->set('gsf_iso_lang', 'label', $this->_('Language'), 'multiOptions', $this->util->getLocalized()->getLanguages());
$model->set('gsf_logout_on_survey', 'label', $this->_('Logout on survey'), 'multiOptions', $this->util->getTranslated()->getYesNo());
}
@@ -235,7 +251,7 @@
$filter = parent::getDataFilter($data);
if (! $this->escort->hasPrivilege('pr.staff.see.all')) {
- $filter['gus_id_organization'] = $this->escort->getCurrentOrganization();
+ $filter['gsf_id_organization'] = $this->escort->getCurrentOrganization();
}
return $filter;
}
@@ -250,25 +266,16 @@
}
/**
- * Creates from the model a MUtil_Html_TableElement for display of a single item.
+ * Return an old style (< 1.5) hashed version of the input value.
*
- * Overruled to add css classes for Gems
- *
- * @param integer $columns The number of columns to use for presentation
- * @param mixed $filter A valid filter for MUtil_Model_ModelAbstract->load()
- * @param mixed $sort A valid sort for MUtil_Model_ModelAbstract->load()
- * @return MUtil_Html_TableElement
+ * @param string $name Optional name, is here for ModelAbstract setOnSave compatibility
+ * @param string $value The value to hash.
+ * @param boolean $new Optional is new, is here for ModelAbstract setOnSave compatibility
+ * @return string The salted hash as a 32-character hexadecimal number.
*/
- public function getShowTable($columns = 1, $filter = null, $sort = null)
+ public function getOldPasswordHash($name, $value, $new)
{
- if ($this->escort->hasPrivilege('pr.staff.see.all')) {
- // Model filter has now been set.
- $data = $this->getModel()->loadFirst();
-
- $this->_setParam('gus_id_organization', $data['gus_id_organization']);
- $this->menu->getParameterSource()->offsetSet('gus_id_organization', $data['gus_id_organization']);
- }
- return parent::getShowTable($columns, $filter, $sort);
+ return md5($value);
}
public function getTopic($count = 1)
Modified: branches/newUser2/classes/Gems/Menu/MenuAbstract.php
===================================================================
--- branches/newUser2/classes/Gems/Menu/MenuAbstract.php 2011-11-08 19:02:26 UTC (rev 196)
+++ branches/newUser2/classes/Gems/Menu/MenuAbstract.php 2011-11-09 12:18:27 UTC (rev 197)
@@ -381,9 +381,9 @@
$page = $this->addPage($label, 'pr.staff', 'staff', 'index', $other);
$page->addAutofilterAction();
$page->addCreateAction();
- $page->addShowAction()->setModelParameters(2);
- $editPage = $page->addEditAction()->setModelParameters(2);
- $delPage = $page->addDeleteAction()->setModelParameters(2);
+ $page->addShowAction();
+ $editPage = $page->addEditAction();
+ $delPage = $page->addDeleteAction();
if (! $this->escort->hasPrivilege('pr.staff.edit.all')) {
$editPage->setParameterFilter('gus_id_organization', $this->escort->getCurrentOrganization());
$delPage->setParameterFilter('gus_id_organization', $this->escort->getCurrentOrganization());
Modified: branches/newUser2/classes/Gems/Model.php
===================================================================
--- branches/newUser2/classes/Gems/Model.php 2011-11-08 19:02:26 UTC (rev 196)
+++ branches/newUser2/classes/Gems/Model.php 2011-11-09 12:18:27 UTC (rev 197)
@@ -96,18 +96,28 @@
protected $util;
/**
- * Function that automatically fills changed, changed_by, created and created_by fields with a certain prefix.
+ * Link the model to the user_logins table.
*
* @param Gems_Model_JoinModel $model
- * @param string $loginField Field that links to login field.
+ * @param string $loginField Field that links to login name field.
* @param string $organizationField Field that links to the organization field.
*/
- public function addAsUserLogin(Gems_Model_JoinModel $model, $loginField, $organizationField)
+ protected function addUserLogin(Gems_Model_JoinModel $model, $loginField, $organizationField)
{
$model->addTable('gems__user_logins', array($loginField => 'gul_login', $organizationField => 'gul_id_organization'), 'gul');
}
/**
+ * Link the model to the user_passwords table.
+ *
+ * @param Gems_Model_JoinModel $model
+ */
+ public static function addUserPassword(Gems_Model_JoinModel $model)
+ {
+ $model->addLeftTable('gems__user_passwords', array('gul_id_user' => 'gup_id_user'), 'gup');
+ }
+
+ /**
* Create a Gems project wide unique user id
*
* @param string $name
@@ -152,7 +162,7 @@
{
$model = $this->_loadClass('RespondentModel', true);
- // $this->addAsUserLogin($model, $this->respondentLoginIdField, 'gr2o_id_organization');
+ // $this->addUserLogin($model, $this->respondentLoginIdField, 'gr2o_id_organization');
$this->setAsGemsUserId($model, 'grs_id_user');
return $model;
@@ -211,7 +221,7 @@
{
$model = new Gems_Model_JoinModel('staff', 'gems__staff', 'gsf');
- $this->addAsUserLogin($model, 'gsf_login', 'gsf_id_organization');
+ $this->addUserLogin($model, 'gsf_login', 'gsf_id_organization');
$this->setAsGemsUserId($model, 'gsf_id_user');
return $model;
Deleted: branches/newUser2/classes/Gems/User/PasswordValidator.php
===================================================================
--- branches/newUser2/classes/Gems/User/PasswordValidator.php 2011-11-08 19:02:26 UTC (rev 196)
+++ branches/newUser2/classes/Gems/User/PasswordValidator.php 2011-11-09 12:18:27 UTC (rev 197)
@@ -1,101 +0,0 @@
-<?php
-
-/**
- * Copyright (c) 2011, Erasmus MC
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * * Neither the name of Erasmus MC nor the
- * names of its contributors may be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY
- * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- *
- * @package Gems
- * @subpackage User
- * @author Matijs de Jong <mj...@ma...>
- * @copyright Copyright (c) 2011 Erasmus MC
- * @license New BSD License
- * @version $Id: Sample.php 203 2011-07-07 12:51:32Z matijs $
- */
-
-/**
- *
- *
- * @package Gems
- * @subpackage User
- * @copyright Copyright (c) 2011 Erasmus MC
- * @license New BSD License
- * @since Class available since version 1.5
- */
-class Gems_User_LoginPasswordValidator implements Zend_Validate_Interface
-{
- /**
- *
- * @var string
- */
- private $loginField = 'userlogin';
-
- private $organizationField = 'organization';
-
- /**
- *
- * @var Gems_User_UserLoader
- */
- private $userLoader;
-
- public function __construct(Gems_User_UserLoader $loader, Gems_User_User $user = null)
- {
- $this->userLoader = $loader;
- $this->user = $user;
- }
-
- /**
- * Returns true if and only if $value meets the validation requirements
- *
- * If $value fails validation, then this method returns false, and
- * getMessages() will return an array of messages that explain why the
- * validation failed.
- *
- * @param mixed $value
- * @param mixed $content
- * @return boolean
- * @throws Zend_Validate_Exception If validation of $value is impossible
- */
- public function isValid($value, $context = array())
- {
- if (! $this->user) {
- if (isset($context[]))
- }
- }
-
- /**
- * Returns an array of messages that explain why the most recent isValid()
- * call returned false. The array keys are validation failure message identifiers,
- * and the array values are the corresponding human-readable message strings.
- *
- * If isValid() was never called or if the most recent isValid() call
- * returned true, then this method returns an empty array.
- *
- * @return array
- */
- public function getMessages()
- {
- }
-}
Modified: branches/newUser2/classes/Gems/User/User.php
===================================================================
--- branches/newUser2/classes/Gems/User/User.php 2011-11-08 19:02:26 UTC (rev 196)
+++ branches/newUser2/classes/Gems/User/User.php 2011-11-09 12:18:27 UTC (rev 197)
@@ -172,7 +172,7 @@
*/
public function checkRegistryRequestsAnswers()
{
- if ($this->session instanceof Zend_Session_Namespace) {
+ if (! $this->session instanceof Zend_Session_Namespace) {
return false;
}
@@ -192,9 +192,29 @@
}
/**
+ * Returns the full user name (first, prefix, last).
*
* @return string
*/
+ public function getFullName()
+ {
+ return $this->_getVar('user_name');
+ }
+
+ /**
+ * The locale set for this user..
+ *
+ * @return string
+ */
+ public function getLocale()
+ {
+ return $this->_getVar('user_locale');
+ }
+
+ /**
+ *
+ * @return string
+ */
public function getLoginName()
{
return $this->_getVar('user_login');
@@ -228,6 +248,16 @@
}
/**
+ * Checks if this user is the current user
+ *
+ * @return boolean
+ */
+ public function isCurrentUser()
+ {
+ return $this->_getVariableStore() instanceof Zend_Session_Namespace;
+ }
+
+ /**
* Set this user as the current user.
*
* This means that the data about this user will be stored in a session.
@@ -240,17 +270,49 @@
$oldStore = $this->_getVariableStore();
// When $oldStore is a Zend_Session_Namespace, then this user is already the current user.
- if (! $oldStore instanceof Zend_Session_Namespace) {
+ if (! $this->isCurrentUser()) {
+ $this->userLoader->getCurrentUser()->unsetAsCurrentUser();
+
$this->_vars = $this->session;
- // Clean up what is there now.
- $this->_vars->unsetAll();
-
foreach ($oldStore as $name => $value) {
$this->_vars->__set($name, $value);
}
+
+ $this->userLoader->setCurrentUser($this);
}
return $this;
}
+
+ /**
+ * Unsets this user as the current user.
+ *
+ * This means that the data about this user will no longer be stored in a session.
+ *
+ * @return Gems_User_UserAbstract
+ */
+ public function unsetAsCurrentUser()
+ {
+ // When $oldStore is a Zend_Session_Namespace, then this user is already the current user.
+ if ($this->isCurrentUser()) {
+ // Get the current variables
+ $oldStore = $this->_getVariableStore();
+
+ $this->_vars = new ArrayObject();
+ $this->_vars->setFlags(ArrayObject::STD_PROP_LIST);
+
+ foreach ($oldStore as $name => $value) {
+ $this->_vars->offsetSet($name, $value);
+ }
+
+ // Clean up what is there now in the session.
+ $this->session->unsetAll();
+
+ // Signal the loader
+ $this->userLoader->unsetCurrentUser();
+ }
+
+ return $this;
+ }
}
Modified: branches/newUser2/classes/Gems/User/UserLoader.php
===================================================================
--- branches/newUser2/classes/Gems/User/UserLoader.php 2011-11-08 19:02:26 UTC (rev 196)
+++ branches/newUser2/classes/Gems/User/UserLoader.php 2011-11-09 12:18:27 UTC (rev 197)
@@ -80,18 +80,12 @@
protected $session;
/**
+ * There can be only one, current user that is.
*
- * @param mixed $container A container acting as source for MUtil_Registry_Source
- * @param array $dirs The directories where to look for requested classes
+ * @var Gems_User_User
*/
- public final function __construct($container, array $dirs)
- {
- parent::__construct($container, $dirs);
+ protected static $currentUser;
- // Make sure Gems_User_User gets userLoader variable.
- $this->addRegistryContainer(array('userLoader' => $this));
- }
-
/**
* Checks the password for the specified $login_name and $organization and
* handles the login security.
@@ -249,19 +243,39 @@
}
/**
+ * Should be called after answering the request to allow the Target
+ * to check if all required registry values have been set correctly.
+ *
+ * @return boolean False if required values are missing.
+ */
+ public function checkRegistryRequestsAnswers()
+ {
+ // Make sure Gems_User_User gets userLoader variable.
+ $extras['userLoader'] = $this;
+
+ // Make sure that this code keeps working when _initSession
+ // is removed from GemsEscort
+ if (! $this->session instanceof Zend_Session_Namespace) {
+ $this->session = new Zend_Session_Namespace('gems.' . GEMS_PROJECT_NAME . '.session');
+
+ $extras['session'] = $this->session;
+ }
+
+ $this->addRegistryContainer($extras);
+ }
+
+ /**
* Get the currently loggin in user
*
* @return Gems_User_User
*/
public final function getCurrentUser()
{
- static $currentUser;
-
- if (! $currentUser) {
- $currentUser = $this->_loadClass('User', true, array($this->session));
+ if (! self::$currentUser) {
+ self::$currentUser = $this->_loadClass('User', true, array($this->session));
}
- return $currentUser;
+ return self::$currentUser;
}
/**
@@ -489,4 +503,40 @@
{
return $this->project->getSuperAdminName() == $login_name;
}
+
+ /**
+ * Sets a new user as the current user.
+ *
+ * @param Gems_User_User $user
+ * @return Gems_User_UserLoader (continuation pattern)
+ */
+ public function setCurrentUser(Gems_User_User $user)
+ {
+ $this->unsetCurrentUser();
+ self::$currentUser = $user;
+
+ // Double check in case this function was used as original
+ // start for setting the user.
+ if (! $user->isCurrentUser()) {
+ $user->setAsCurrentUser();
+ }
+
+ return $this;
+ }
+
+ /**
+ * Sets a new user as the current user.
+ *
+ * @param Gems_User_User $user
+ * @return Gems_User_UserLoader (continuation pattern)
+ */
+ public function unsetCurrentUser()
+ {
+ // Remove if the currentUser still sees itself as the current user.
+ if ((self::$currentUser instanceof Gems_User_User) && self::$currentUser->isCurrentUser()) {
+ self::$currentUser->unsetAsCurrentUser();
+ }
+ self::$currentUser = $user;
+ return $this;
+ }
}
Modified: branches/newUser2/classes/GemsEscort.php
===================================================================
--- branches/newUser2/classes/GemsEscort.php 2011-11-08 19:02:26 UTC (rev 196)
+++ branches/newUser2/classes/GemsEscort.php 2011-11-09 12:18:27 UTC (rev 197)
@@ -444,22 +444,6 @@
*
* Use $this->util to access afterwards
*
- * @return Gems_User_User
- */
- protected function _initUser()
- {
- $this->bootstrap(array('loader', 'project', 'session'));
-
- return $this->getLoader()->getCurrentUser();
- }
-
- /**
- * Initialize the util component.
- *
- * You can overrule this function to specify your own project translation method / file.
- *
- * Use $this->util to access afterwards
- *
* @return Gems_Util
*/
protected function _initUtil()
@@ -975,7 +959,6 @@
public function afterLogout()
{
$this->session->unsetAll();
- $this->user = $this->getLoader()->getCurrentUser();
}
/**
Modified: branches/newUser2/configs/db/patches.sql
===================================================================
--- branches/newUser2/configs/db/patches.sql 2011-11-08 19:02:26 UTC (rev 196)
+++ branches/newUser2/configs/db/patches.sql 2011-11-09 12:18:27 UTC (rev 197)
@@ -282,7 +282,7 @@
INSERT INTO gems__user_logins (gul_login, gul_id_organization, gul_user_class,
gul_can_login,
gul_changed, gul_changed_by, gul_created, gul_created_by)
- SELECT gsf_login, gsf_id_organization, 'StaffUser',
+ SELECT gsf_login, gsf_id_organization, 'OldStaffUser',
gsf_active,
gsf_changed, gsf_changed_by, gsf_created, gsf_created_by
FROM gems__staff WHERE (gsf_login, gsf_id_organization) NOT IN (SELECT gul_login, gul_id_organization FROM gems__user_logins);
Modified: branches/newUser2/configs/db/tables/gems__staff.20.sql
===================================================================
--- branches/newUser2/configs/db/tables/gems__staff.20.sql 2011-11-08 19:02:26 UTC (rev 196)
+++ branches/newUser2/configs/db/tables/gems__staff.20.sql 2011-11-09 12:18:27 UTC (rev 197)
@@ -7,9 +7,10 @@
gsf_login varchar(20) CHARACTER SET 'utf8' COLLATE 'utf8_general_ci' not null,
gsf_id_organization bigint not null references gems__organizations (gor_id_organization),
+ gsf_active boolean null default 1,
+
-- depreciated
gsf_password varchar(32) CHARACTER SET 'utf8' COLLATE 'utf8_general_ci' null,
- gsf_active boolean null default 1,
gsf_failed_logins int(11) unsigned null default 0,
gsf_last_failed timestamp null,
-- end depreciated
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <gem...@li...> - 2011-11-08 19:02:35
|
Revision: 196
http://gemstracker.svn.sourceforge.net/gemstracker/?rev=196&view=rev
Author: matijsdejong
Date: 2011-11-08 19:02:26 +0000 (Tue, 08 Nov 2011)
Log Message:
-----------
Continue #31: Login works with new mechanism, still busy changing all the existing logins
MUtil_Date->diffSeconds now uses time() as default date/
Severe bug in DatabaseModelAbstract->_saveTableData on insert changed values are not returned when all keys are filled in the insert.
Bug in DbaModel -> chokes when directory does not exist.
Modified Paths:
--------------
branches/newUser2/changelog.txt
branches/newUser2/classes/Gems/Auth.php
branches/newUser2/classes/Gems/Cookies.php
branches/newUser2/classes/Gems/Default/CronAction.php
branches/newUser2/classes/Gems/Default/IndexAction.php
branches/newUser2/classes/Gems/Default/RespondentAction.php
branches/newUser2/classes/Gems/Default/StaffAction.php
branches/newUser2/classes/Gems/Default/TokenPlanAction.php
branches/newUser2/classes/Gems/Loader.php
branches/newUser2/classes/Gems/Model/DbaModel.php
branches/newUser2/classes/Gems/Model.php
branches/newUser2/classes/Gems/Project/ProjectSettings.php
branches/newUser2/classes/Gems/User/User.php
branches/newUser2/classes/Gems/User/UserLoader.php
branches/newUser2/classes/Gems/Util/DbLookup.php
branches/newUser2/classes/Gems/Validate/GemsPasswordUsername.php
branches/newUser2/classes/GemsEscort.php
branches/newUser2/classes/MUtil/Date.php
branches/newUser2/classes/MUtil/Model/DatabaseModelAbstract.php
branches/newUser2/classes/MUtil/Model/JoinModel.php
branches/newUser2/configs/db/patches.sql
branches/newUser2/configs/db/tables/gems__staff.20.sql
branches/newUser2/configs/db/tables/gems__user_ids.10.sql
branches/newUser2/configs/db/tables/gems__user_logins.10.sql
branches/newUser2/configs/db/tables/gems__user_passwords.50.sql
Added Paths:
-----------
branches/newUser2/classes/Gems/User/LoginPasswordValidator.php
branches/newUser2/classes/Gems/User/PasswordValidator.php
branches/newUser2/configs/db/tables/gems__user_login_attempts.10.sql
Removed Paths:
-------------
branches/newUser2/classes/Gems/Model/UserModel.php
branches/newUser2/classes/Gems/User/DatabaseUserAbstract.php
branches/newUser2/classes/Gems/User/NoLoginUser.php
branches/newUser2/classes/Gems/User/ProjectSuperUser.php
branches/newUser2/classes/Gems/User/RespondentUser.php
branches/newUser2/classes/Gems/User/StaffUser.php
branches/newUser2/classes/Gems/User/UserAbstract.php
branches/newUser2/classes/Gems/User/UserInterface.php
Modified: branches/newUser2/changelog.txt
===================================================================
--- branches/newUser2/changelog.txt 2011-11-08 15:10:39 UTC (rev 195)
+++ branches/newUser2/changelog.txt 2011-11-08 19:02:26 UTC (rev 196)
@@ -1,7 +1,8 @@
Important changes from 1.4.3 => 1.5
============================================================
Passwords should be set with a project.ini->salt. Salt is now a required project setting!
-The table gems__staff is split into gems__staff and gems__user with all login data in gems__users.
+The table gems__staff is split into gems__staff, gems__user_logins with generic login data and gems__users_passwords containing db stored password information.
+The table gems__user_ids provides unique and non-sequential user ids accross gems__staff and gems__respondents.
The gems__respondent.grs_bsn has been renamed to grs_ssn, to make the code more international.
MailController is now called MailTemplateController.
EmailController is now called CronController (with stub for compatibility).
Modified: branches/newUser2/classes/Gems/Auth.php
===================================================================
--- branches/newUser2/classes/Gems/Auth.php 2011-11-08 15:10:39 UTC (rev 195)
+++ branches/newUser2/classes/Gems/Auth.php 2011-11-08 19:02:26 UTC (rev 196)
@@ -98,8 +98,8 @@
* Lookup last failed login and number of failed logins
*/
try {
- $sql = "SELECT gus_failed_logins, UNIX_TIMESTAMP(gus_last_failed)
- AS gus_last_failed FROM gems__users WHERE gus_login = ?";
+ $sql = "SELECT gul_failed_logins, UNIX_TIMESTAMP(gul_last_failed) AS gul_last_failed
+ FROM gems__user_logins WHERE gul_login = ?";
$results = $this->db->fetchRow($sql, array($username));
} catch (Zend_Db_Exception $zde) {
//If we need to apply a db patch, just use a default value
@@ -107,10 +107,10 @@
MUtil_Echo::r(GemsEscort::getInstance()->translate->_('Please update the database'));
}
- $delay = pow($results['gus_failed_logins'], $this->_delayFactor);
- $remaining = ($results['gus_last_failed'] + $delay) - time();
+ $delay = pow($results['gul_failed_logins'], $this->_delayFactor);
+ $remaining = ($results['gul_last_failed'] + $delay) - time();
- if ($results['gus_failed_logins'] > 0 && $remaining > 0) {
+ if ($results['gul_failed_logins'] > 0 && $remaining > 0) {
//$this->_obscureValue = false;
$result = $this->_error(self::ERROR_PASSWORD_DELAY, ceil($remaining / 60));
}
Modified: branches/newUser2/classes/Gems/Cookies.php
===================================================================
--- branches/newUser2/classes/Gems/Cookies.php 2011-11-08 15:10:39 UTC (rev 195)
+++ branches/newUser2/classes/Gems/Cookies.php 2011-11-08 19:02:26 UTC (rev 196)
@@ -26,6 +26,7 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
+ *
* @package Gems
* @subpackage Cookies
* @author Matijs de Jong <mj...@ma...>
@@ -46,6 +47,7 @@
class Gems_Cookies
{
const LOCALE_COOKIE = 'gems_locale';
+ const ORGANIZATION_COOKIE = 'gems_organization';
/**
* Get a specific cookie from the request.
@@ -72,6 +74,17 @@
}
/**
+ * Get the current organization from the cookie.
+ *
+ * @param Zend_Controller_Request_Abstract $request
+ * @return int The current organization
+ */
+ public static function getOrganization(Zend_Controller_Request_Abstract $request)
+ {
+ return intval(self::get($request, self::ORGANIZATION_COOKIE));
+ }
+
+ /**
* Store this cookie in a generic save method that works for both sub-directory
* installations and own url installations.
*
@@ -104,4 +117,17 @@
// Set the cookie for 30 days
return self::set(self::LOCALE_COOKIE, $locale, 30, $basepath);
}
+
+ /**
+ * Store the organization in a cookie.
+ *
+ * @param int $organization Organization to store
+ * @param string $basepath The folder of the domain, if any.
+ * @return boolean True if the cookie was stored.
+ */
+ public static function setOrganization($organization, $basepath = '/')
+ {
+ // Set the cookie for 30 days
+ return self::set(self::ORGANIZATION_COOKIE, $organization, 30, $basepath);
+ }
}
Modified: branches/newUser2/classes/Gems/Default/CronAction.php
===================================================================
--- branches/newUser2/classes/Gems/Default/CronAction.php 2011-11-08 15:10:39 UTC (rev 195)
+++ branches/newUser2/classes/Gems/Default/CronAction.php 2011-11-08 19:02:26 UTC (rev 196)
@@ -26,17 +26,23 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
- * @author Michiel Rook <mi...@to...>
- * @package Gems
+ *
+ * @author Michiel Rook <mi...@to...>
+ * @package Gems
* @subpackage Default
+ * @copyright Copyright (c) 2011 Erasmus MC
+ * @license New BSD License
+ * @version $Id$
*/
/**
* Performs bulk-mail action, can be called from a cronjob
*
- * @author Michiel Rook <mi...@to...>
- * @package Gems
+ * @package Gems
* @subpackage Default
+ * @copyright Copyright (c) 2011 Erasmus MC
+ * @license New BSD License
+ * @since Class available since version 1.4
*/
class Gems_Default_CronAction extends MUtil_Controller_Action
{
@@ -69,6 +75,12 @@
/**
*
+ * @var Gems_Loader
+ */
+ public $loader;
+
+ /**
+ *
* @var Gems_Menu
*/
public $menu;
@@ -90,6 +102,12 @@
/**
*
+ * @var Gems_User_User
+ */
+ public $user;
+
+ /**
+ *
* @var Gems_Util
*/
public $util;
@@ -125,7 +143,7 @@
*/
protected function getUserLogin($userId)
{
- return $this->db->fetchOne("SELECT gus_login FROM gems__users WHERE gus_id_user = ?", $userId);
+ return $this->db->fetchOne("SELECT gsf_login FROM gems__staff WHERE gsf_id_user = ?", $userId);
}
public function indexAction()
@@ -141,57 +159,59 @@
public function mailJob()
{
- // Test: update `gems__tokens` set `gto_mail_sent_date` = null where `gto_mail_sent_date` > '2011-10-23'
+ $userLoader = $this->loader->getUserLoader();
+ $oldUserLogin = $this->user->getLoginName();
+ $oldUserOrg = $this->user->getOrganizationId();
- $currentUser = isset($this->session->user_login) ? $this->session->user_login : null;
-
$model = $this->loader->getTracker()->getTokenModel();
$mailer = new Gems_Email_TemplateMailer($this->escort);
+
// $mailer->setDefaultTransport(new MUtil_Mail_Transport_EchoLog());
$jobs = $this->db->fetchAll("SELECT * FROM gems__mail_jobs WHERE gmj_active = 1");
if ($jobs) {
foreach ($jobs as $job) {
- $this->escort->loadLoginInfo($this->getUserLogin($job['gmj_id_user_as']));
+ $user = $userLoader->getUserByStaffId($job['gmj_id_user_as']);
- // Set up filter
- $filter = $this->defaultFilter;
- if ($job['gmj_filter_mode'] == 'R') {
- $filter[] = 'gto_mail_sent_date <= DATE_SUB(CURRENT_DATE, INTERVAL ' . $job['gmj_filter_days_between'] . ' DAY)';
- } else {
- $filter['gto_mail_sent_date'] = NULL;
- }
- if ($job['gmj_id_organization']) {
- $filter['gto_id_organization'] = $job['gmj_id_organization'];
- }
- if ($job['gmj_id_track']) {
- $filter['gto_id_track'] = $job['gmj_id_track'];
- }
- if ($job['gmj_id_survey']) {
- $filter['gto_id_survey'] = $job['gmj_id_survey'];
- }
+ if ($user->isActive()) {
+ $user->setAsCurrentUser();
- $tokensData = $model->load($filter);
-
- if (count($tokensData)) {
- $mailer->setMethod($job['gmj_process_method']);
- if ($job['gmj_from_method'] == 'F') {
- $mailer->setFrom($job['gmj_from_fixed']);
+ // Set up filter
+ $filter = $this->defaultFilter;
+ if ($job['gmj_filter_mode'] == 'R') {
+ $filter[] = 'gto_mail_sent_date <= DATE_SUB(CURRENT_DATE, INTERVAL ' . $job['gmj_filter_days_between'] . ' DAY)';
} else {
- $mailer->setFrom($job['gmj_from_method']);
+ $filter['gto_mail_sent_date'] = NULL;
}
+ if ($job['gmj_id_organization']) {
+ $filter['gto_id_organization'] = $job['gmj_id_organization'];
+ }
+ if ($job['gmj_id_track']) {
+ $filter['gto_id_track'] = $job['gmj_id_track'];
+ }
+ if ($job['gmj_id_survey']) {
+ $filter['gto_id_survey'] = $job['gmj_id_survey'];
+ }
- $templateData = $this->getTemplate($job['gmj_id_message']);
- $mailer->setSubject($templateData['gmt_subject']);
- $mailer->setBody($templateData['gmt_body']);
+ $tokensData = $model->load($filter);
- $mailer->setTokens(MUtil_Ra::column('gto_id_token', $tokensData));
- $mailer->process($tokensData);
- }
+ if (count($tokensData)) {
+ $mailer->setMethod($job['gmj_process_method']);
+ if ($job['gmj_from_method'] == 'F') {
+ $mailer->setFrom($job['gmj_from_fixed']);
+ } else {
+ $mailer->setFrom($job['gmj_from_method']);
+ }
- Gems_Auth::getInstance()->clearIdentity();
- $this->escort->session->unsetAll();
+ $templateData = $this->getTemplate($job['gmj_id_message']);
+ $mailer->setSubject($templateData['gmt_subject']);
+ $mailer->setBody($templateData['gmt_body']);
+
+ $mailer->setTokens(MUtil_Ra::column('gto_id_token', $tokensData));
+ $mailer->process($tokensData);
+ }
+ }
}
}
@@ -202,51 +222,7 @@
$this->html->append($msg);
- if ($currentUser) {
- $this->escort->loadLoginInfo($currentUser);
- } else {
- $this->escort->afterLogout();
- }
-
- /*
- if (isset($this->project->email['automatic'])) {
- $batches = $this->project->email['automatic'];
- $numBatches = count($batches['mode']);
-
- for ($i = 0; $i < $numBatches; $i++) {
- $this->_organizationId = $batches['organization'][$i];
-
- if (isset($batches['days'][$i])) {
- $this->_intervalDays = $batches['days'][$i];
- }
-
- $this->escort->loadLoginInfo($batches['user'][$i]);
-
- $model->setFilter($this->getFilter($batches['mode'][$i]));
-
- $tokensData = $model->load();
-
- if (count($tokensData)) {
- $tokens = array();
-
- foreach ($tokensData as $tokenData) {
- $tokens[] = $tokenData['gto_id_token'];
- }
-
- $templateData = $this->getTemplate($batches['template'][$i]);
- $mailer->setSubject($templateData['gmt_subject']);
- $mailer->setBody($templateData['gmt_body']);
- $mailer->setMethod($batches['method'][$i]);
- $mailer->setFrom($batches['from'][$i]);
- $mailer->setTokens($tokens);
-
- $mailer->process($tokensData);
- }
-
- Gems_Auth::getInstance()->clearIdentity();
- $this->escort->session->unsetAll();
- }
- }
- // */
+ $user = $userLoader->getUser($oldUserLogin, $oldUserOrg);
+ $user->setAsCurrentUser();
}
}
\ No newline at end of file
Modified: branches/newUser2/classes/Gems/Default/IndexAction.php
===================================================================
--- branches/newUser2/classes/Gems/Default/IndexAction.php 2011-11-08 15:10:39 UTC (rev 195)
+++ branches/newUser2/classes/Gems/Default/IndexAction.php 2011-11-08 19:02:26 UTC (rev 196)
@@ -74,7 +74,7 @@
* @return Zend_Auth_Adapter_Interface
*/
protected function _getAuthAdapter($formValues) {
- $adapter = new Zend_Auth_Adapter_DbTable($this->db, 'gems__users', 'gus_login', 'gus_password');
+ $adapter = new Zend_Auth_Adapter_DbTable($this->db, 'gems__staff', 'gsf_login', 'gsf_password');
$adapter->setIdentity($formValues['userlogin']);
$adapter->setCredential($this->escort->passwordHash(null, $formValues['password'], false));
return $adapter;
@@ -126,7 +126,7 @@
$element->setAttrib('size', 10);
$element->setAttrib('maxlength', 20);
$element->setRequired(true);
- //$element->addValidator(new Gems_Validate_GemsPasswordUsername('userlogin', 'password', $this->db, $delayFactor));
+ $element->addValidator(new Gems_User_LoginPasswordValidator($this->loader->getUserLoader(), 'userlogin', 'organization', $this->translate));
$form->addElement($element);
// Submit knop
@@ -173,79 +173,55 @@
if ($this->_request->isPost()) {
if ($form->isValid($_POST, false)) {
- /*
+
if ($user = $this->loader->getUser($_POST['userlogin'], $_POST['organization'])) {
- } // */
+ $user->setAsCurrentUser();
- if (isset($this->project->admin) && $this->project->admin['user'] == $_POST['userlogin'] && $this->project->admin['pwd'] == $_POST['password']) {
- $this->session->user_id = 2000;
- $this->session->user_name = $_POST['userlogin'];
- $this->session->user_group = 800;
- $this->session->user_role = 'master';
- $this->session->user_organization_id = 70;
- $this->session->user_organization_name = 'SUPER ADMIN';
- $this->session->user_style = 'gems';
- //Als er nog geen tabellen zijn, moet dit ingesteld worden
- //@@TODO Nog kijken hoe beter op te lossen (met try op tabel ofzo)
- $this->session->allowedOrgs = array($this->session->user_organization_id=>$this->session->user_organization_name);
+ /**
+ * Fix current locale
+ */
+ Gems_Cookies::setLocale($this->session->user_locale, $this->basepath->getBasePath());
/**
* Ready
*/
$this->addMessage(sprintf($this->_('Login successful, welcome %s.'), $this->session->user_name));
- $this->_reroute(array('controller' => 'database', 'action' => 'index'), true);
- return;
- }
- //Now check authentication
- $adapter = $this->_getAuthAdapter($form->getValues());
- $auth = Gems_Auth::getInstance();
- $result = $auth->authenticate($adapter, $_POST['userlogin']);
- // Allow login using old password.
- if ((! $result->isValid()) && ($userid = $this->db->fetchOne("SELECT gus_id_user FROM gems__users WHERE gus_active = 1 AND gus_password IS NULL AND gus_login = ?", $_POST['userlogin']))) {
+ /**
+ * Log the login
+ */
+ Gems_AccessLog::getLog($this->db)->log("index.login", $this->getRequest(), null, $this->session->user_id, true);
- $adapter = new Zend_Auth_Adapter_DbTable($this->db, 'gems__staff', 'gsf_id_user', 'gsf_password');
- $adapter->setIdentity($userid);
- $adapter->setCredential(md5($_POST['password'], false));
- $result = $auth->authenticate($adapter, $_POST['userlogin']);
- // MUtil_Echo::track('old autho');
- } else {
- // MUtil_Echo::track('new autho');
+ if ($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);
+ }
}
- if (!$result->isValid()) {
- // Invalid credentials
- $errors = $result->getMessages();
- $this->addMessage($errors);
- $code = $result->getCode();
- if ($code != Gems_Auth::ERROR_PASSWORD_DELAY) {
- $this->escort->afterFailedLogin();
- }
-
- $this->view->form = $form;
- } else {
- // Load login data
+ /*/ Load login data
$this->escort->loadLoginInfo($_POST['userlogin']);
/**
* Perform any project specific post login activities
- */
+ * /
$this->escort->afterLogin($_POST['userlogin']);
/**
* Fix current locale
- */
+ * /
Gems_Cookies::setLocale($this->session->user_locale, $this->basepath->getBasePath());
/**
* Ready
- */
+ * /
$this->addMessage(sprintf($this->_('Login successful, welcome %s.'), $this->session->user_name));
/**
* Log the login
- */
+ * /
Gems_AccessLog::getLog($this->db)->log("index.login", $this->getRequest(), null, $this->session->user_id, true);
if ($previousRequestParameters = $this->session->previousRequestParameters) {
@@ -254,7 +230,7 @@
// This reroutes to the first available menu page after login
$this->_reroute(array('controller' => null, 'action' => null), true);
}
- }
+ } // */
} else {
$errors = $form->getErrors();
@@ -308,6 +284,8 @@
$mail->addBcc($this->escort->project->email['bcc']);
}
+ /*
+
if ($this->_request->isPost() && $form->isValid($_POST)) {
$sql = $this->db->quoteInto("SELECT gus_id_user, gsf_email, gus_reset_key, DATEDIFF(NOW(), gus_reset_requested) AS gsf_days FROM gems__users INNER JOIN gems__staff ON gus_id_user = gsf_id_user WHERE gus_login = ?", $_POST['userlogin']);
$result = $this->db->fetchRow($sql);
@@ -321,7 +299,7 @@
$key = md5(time() . $email);
$url = $this->util->getCurrentURI('index/resetpassword/key/' . $key);
- $this->db->update('gems__users', array('gus_reset_key' => $key, 'gus_reset_requested' => new Zend_Db_Expr('NOW()')), 'gus_id_user = ' . $result['gus_id_user']);
+ $this->db->update('gems__user_logins', array('gus_reset_key' => $key, 'gus_reset_requested' => new Zend_Db_Expr('NOW()')), 'gus_id_user = ' . $result['gus_id_user']);
$mail->setSubject('Password reset requested');
$mail->setBodyText('To reset your password, please click this link: ' . $url);
@@ -362,7 +340,7 @@
} else {
$this->addMessage($this->_('Unknown request'));
}
- }
+ } // */
$this->view->form = $form;
}
Modified: branches/newUser2/classes/Gems/Default/RespondentAction.php
===================================================================
--- branches/newUser2/classes/Gems/Default/RespondentAction.php 2011-11-08 15:10:39 UTC (rev 195)
+++ branches/newUser2/classes/Gems/Default/RespondentAction.php 2011-11-08 19:02:26 UTC (rev 196)
@@ -316,26 +316,6 @@
$this->html[] = $form;
}
- public function getPhysicians()
- {
- $session = new Zend_Session_Namespace('Pulse_' . __FILE__);
-
- if (! isset($session->physicians)) {
- $organizationId = $this->escort->getCurrentOrganization();
-
- $values = $this->db->fetchPairs("
- SELECT gsf_id_user,
- CONCAT(gsf_last_name, ', ', COALESCE(CONCAT(gsf_first_name, ' '), ''), COALESCE(gsf_surname_prefix, '')) AS name
- FROM (gems__users INNER JOIN gems__staff ON gus_id_user = gsf_id_user) INNER JOIN gems__groups ON gsf_id_primary_group = ggp_id_group
- WHERE gus_active=1 AND gus_id_organization = ? AND ggp_role = 'physician'
- ORDER BY 2", $organizationId);
-
- $session->physicians = $values;
- }
-
- return $this->util->getTranslated()->getEmptyDropdownArray() + $session->physicians;
- }
-
public function getMenuParameter($name, $default)
{
switch ($name) {
Modified: branches/newUser2/classes/Gems/Default/StaffAction.php
===================================================================
--- branches/newUser2/classes/Gems/Default/StaffAction.php 2011-11-08 15:10:39 UTC (rev 195)
+++ branches/newUser2/classes/Gems/Default/StaffAction.php 2011-11-08 19:02:26 UTC (rev 196)
@@ -44,7 +44,7 @@
*/
class Gems_Default_StaffAction extends Gems_Controller_BrowseEditAction
{
- public $filterStandard = array('gus_active' => 1);
+ public $filterStandard = array('gsf_active' => 1);
public $sortKey = array('name' => SORT_ASC);
protected $_instanceId;
@@ -149,7 +149,7 @@
$groups = $this->db->fetchPairs($sql);
if (! ($this->escort->hasPrivilege('pr.staff.edit.all') ||
- $data['gus_id_organization'] == $this->escort->getCurrentOrganization())) {
+ $data['gsf_id_organization'] == $this->escort->getCurrentOrganization())) {
throw new Zend_Exception($this->_('You are not allowed to edit this staff member.'));
}
}
@@ -176,15 +176,15 @@
//$model->resetOrder(); */
$model = $this->loader->getModels()->getStaffModel();
- $model->set('gus_login', 'label', $this->_('Login'));
+ $model->set('gsf_login', 'label', $this->_('Login'));
$model->set('name', 'label', $this->_('Name'),
'column_expression', "CONCAT(COALESCE(CONCAT(gsf_last_name, ', '), '-, '), COALESCE(CONCAT(gsf_first_name, ' '), ''), COALESCE(gsf_surname_prefix, ''))");
$model->set('gsf_email', 'label', $this->_('E-Mail'), 'itemDisplay', 'MUtil_Html_AElement::ifmail');
if ($detailed || $this->escort->hasPrivilege('pr.staff.see.all')) {
- $this->menu->getParameterSource()->offsetSet('gus_id_organization', $this->escort->getCurrentOrganization());
+ $this->menu->getParameterSource()->offsetSet('gsf_id_organization', $this->escort->getCurrentOrganization());
- $model->set('gus_id_organization', 'label', $this->_('Organization'),
+ $model->set('gsf_id_organization', 'label', $this->_('Organization'),
'multiOptions', $this->util->getDbLookup()->getOrganizations(),
'default', $this->escort->getCurrentOrganization());
}
@@ -193,12 +193,12 @@
$model->set('gsf_gender', 'label', $this->_('Gender'), 'multiOptions', $this->util->getTranslated()->getGenders());
if ($detailed) {
- $model->set('gus_user_class', 'default', Gems_User_UserLoader::USER_STAFF);
+ $model->set('gul_user_class', 'default', Gems_User_UserLoader::USER_STAFF);
$model->set('gsf_iso_lang', 'label', $this->_('Language'), 'multiOptions', $this->util->getLocalized()->getLanguages());
$model->set('gsf_logout_on_survey', 'label', $this->_('Logout on survey'), 'multiOptions', $this->util->getTranslated()->getYesNo());
}
- $model->setDeleteValues('gus_active', 0);
+ $model->setDeleteValues('gsf_active', 0);
return $model;
}
@@ -209,8 +209,8 @@
if ($this->escort->hasPrivilege('pr.staff.see.all')) {
// Select organization
- $options = array('' => $this->_('(all organizations)')) + $this->getModel()->get('gus_id_organization', 'multiOptions');
- $select = new Zend_Form_Element_Select('gus_id_organization', array('multiOptions' => $options));
+ $options = array('' => $this->_('(all organizations)')) + $this->getModel()->get('gsf_id_organization', 'multiOptions');
+ $select = new Zend_Form_Element_Select('gsf_id_organization', array('multiOptions' => $options));
// Position as second element
$search = array_shift($elements);
Modified: branches/newUser2/classes/Gems/Default/TokenPlanAction.php
===================================================================
--- branches/newUser2/classes/Gems/Default/TokenPlanAction.php 2011-11-08 15:10:39 UTC (rev 195)
+++ branches/newUser2/classes/Gems/Default/TokenPlanAction.php 2011-11-08 19:02:26 UTC (rev 196)
@@ -351,9 +351,8 @@
COALESCE(gems__staff.gsf_first_name, ''),
COALESCE(CONCAT(' ', gems__staff.gsf_surname_prefix), '')
) AS gsf_name
- FROM (gems__users INNER JOIN gems__staff ON gus_id_user = gsf_id_user) INNER JOIN gems__respondent2track ON gus_id_user = gr2t_created_by
+ FROM gems__staff INNER JOIN gems__respondent2track ON gus_id_user = gr2t_created_by
WHERE gr2t_id_organization = $orgId AND
- gsu_active = 1 AND
gr2t_active = 1";
$elements[] = $this->_createSelectElement('gr2t_created_by', $sql, $this->_('(all staff)'));
Modified: branches/newUser2/classes/Gems/Loader.php
===================================================================
--- branches/newUser2/classes/Gems/Loader.php 2011-11-08 15:10:39 UTC (rev 195)
+++ branches/newUser2/classes/Gems/Loader.php 2011-11-08 19:02:26 UTC (rev 196)
@@ -125,7 +125,7 @@
*
* @return Gems_User_User
*/
- public function getCurrentUser($login_name, $organization)
+ public function getCurrentUser()
{
$loader = $this->getUserLoader();
@@ -208,7 +208,7 @@
/**
*
* @param string $login_name
- * @param int $organization
+ * @param int $organization
* @return Gems_User_User
*/
public function getUser($login_name, $organization)
@@ -222,7 +222,7 @@
*
* @return Gems_User_UserLoader
*/
- protected function getUserLoader()
+ public function getUserLoader()
{
return $this->_getClass('userLoader', 'User_UserLoader');
}
Modified: branches/newUser2/classes/Gems/Model/DbaModel.php
===================================================================
--- branches/newUser2/classes/Gems/Model/DbaModel.php 2011-11-08 15:10:39 UTC (rev 195)
+++ branches/newUser2/classes/Gems/Model/DbaModel.php 2011-11-08 19:02:26 UTC (rev 196)
@@ -132,50 +132,52 @@
foreach (array_reverse($this->directories) as $i => $mainDirectory) {
$location = $this->locations[$i];
- foreach (new DirectoryIterator($mainDirectory) as $directory) {
- $type = $this->_getType($directory->getFilename());
+ if (is_dir($mainDirectory)) {
+ foreach (new DirectoryIterator($mainDirectory) as $directory) {
+ $type = $this->_getType($directory->getFilename());
- if ($directory->isDir() && (! $directory->isDot())) {
- $path = $directory->getPathname();
+ if ($directory->isDir() && (! $directory->isDot())) {
+ $path = $directory->getPathname();
- foreach (new DirectoryIterator($path) as $file) {
+ foreach (new DirectoryIterator($path) as $file) {
- $fileName = strtolower($file->getFilename());
+ $fileName = strtolower($file->getFilename());
- if (substr($fileName, -4) == '.sql') {
- $fileName = substr($fileName, 0, -4);
- $forder = $this->_getOrder($fileName); // Changes $fileName
+ if (substr($fileName, -4) == '.sql') {
+ $fileName = substr($fileName, 0, -4);
+ $forder = $this->_getOrder($fileName); // Changes $fileName
- if ($fexists = array_key_exists($fileName, $tables)) {
- unset($tables[$fileName]);
- } elseif (array_key_exists($fileName, $data)) {
- // $fexists is also true when the table was already defined
- // in a previous directory
- $fexists = $data[$fileName]['exists'];
- }
+ if ($fexists = array_key_exists($fileName, $tables)) {
+ unset($tables[$fileName]);
+ } elseif (array_key_exists($fileName, $data)) {
+ // $fexists is also true when the table was already defined
+ // in a previous directory
+ $fexists = $data[$fileName]['exists'];
+ }
- $fileContent = file_get_contents($file->getPathname());
- if ($this->file_encoding) {
- $fileContent = mb_convert_encoding($fileContent, mb_internal_encoding(), $this->file_encoding);
+ $fileContent = file_get_contents($file->getPathname());
+ if ($this->file_encoding) {
+ $fileContent = mb_convert_encoding($fileContent, mb_internal_encoding(), $this->file_encoding);
+ }
+
+ $data[$fileName] = array(
+ 'name' => $fileName,
+ 'group' => $this->_getGroupName($fileName),
+ 'type' => $type,
+ 'order' => $forder,
+ 'defined' => true,
+ 'exists' => $fexists,
+ 'state' => $fexists ? self::STATE_CREATED : self::STATE_DEFINED,
+ 'path' => $path,
+ 'fullPath' => $file->getPathname(),
+ 'fileName' => $file->getFilename(),
+ // MUtil_Lazy does not serialize
+ // 'script' => MUtil_Lazy::call('file_get_contents', $file->getPathname()),
+ 'script' => $fileContent,
+ 'lastChanged' => $file->getMTime(),
+ 'location' => $location,
+ );
}
-
- $data[$fileName] = array(
- 'name' => $fileName,
- 'group' => $this->_getGroupName($fileName),
- 'type' => $type,
- 'order' => $forder,
- 'defined' => true,
- 'exists' => $fexists,
- 'state' => $fexists ? self::STATE_CREATED : self::STATE_DEFINED,
- 'path' => $path,
- 'fullPath' => $file->getPathname(),
- 'fileName' => $file->getFilename(),
- // MUtil_Lazy does not serialize
- // 'script' => MUtil_Lazy::call('file_get_contents', $file->getPathname()),
- 'script' => $fileContent,
- 'lastChanged' => $file->getMTime(),
- 'location' => $location,
- );
}
}
}
Deleted: branches/newUser2/classes/Gems/Model/UserModel.php
===================================================================
--- branches/newUser2/classes/Gems/Model/UserModel.php 2011-11-08 15:10:39 UTC (rev 195)
+++ branches/newUser2/classes/Gems/Model/UserModel.php 2011-11-08 19:02:26 UTC (rev 196)
@@ -1,119 +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 Model
- * @author Matijs de Jong <mj...@ma...>
- * @copyright Copyright (c) 2011 Erasmus MC
- * @license New BSD License
- * @version $Id: Sample.php 203 2011-07-07 12:51:32Z matijs $
- */
-
-/**
- *
- *
- * @package Gems
- * @subpackage Model
- * @copyright Copyright (c) 2011 Erasmus MC
- * @license New BSD License
- * @since Class available since version 1.4.4
- */
-class Gems_Model_UserModel extends Gems_Model_JoinModel
-{
- /**
- * The length of a user id.
- *
- * @var int
- */
- protected $userIdLen = 8;
-
- /**
- * Create a model that joins two or more tables
- *
- * @param string $name The name of the model
- * @param string $secondTable The optional second base table for the model
- * @param array $joinFields Array of source->dest primary keys for this join
- * @param string $fieldPrefix Prefix to use for change fields (date/userid)
- * @param bool $saveable Will changes to this table be saved
- */
- public function __construct($name, $secondTable = null, array $joinFields = null, $fieldPrefix = null, $saveable = null)
- {
- parent::__construct($name, 'gems__users', (null === $saveable ? $fieldPrefix : $saveable));
-
- if ($fieldPrefix) {
- Gems_Model::setChangeFieldsByPrefix($this, 'gus');
- }
-
- if ($secondTable) {
- $this->addTable($secondTable, $joinFields, $fieldPrefix, $saveable);
- }
- }
-
- /**
- * Finds a random unique user id.
- *
- * @return int
- */
- protected function _createUserId()
- {
- $db = $this->getAdapter();
-
- $max = $this->userIdLen;
-
- do {
- $out = mt_rand(1, 9);
- for ($i = 1; $i < $this->userIdLen; $i++) {
- $out .= mt_rand(0, 9);
- }
- // Make it a number
- $out = intval($out);
-
- } while ($db->fetchOne('SELECT gus_id_user FROM gems__users WHERE gus_id_user = ?', $out));
-
- return $out;
- }
-
- /**
- * Save a single model item.
- *
- * @param array $newValues The values to store for a single model item.
- * @param array $filter If the filter contains old key values these are used
- * to decide on update versus insert.
- * @return array The values as they are after saving (they may change).
- */
- public function save(array $newValues, array $filter = null, array $saveTables = null)
- {
- if (! (isset($newValues['gus_id_user']) && $newValues['gus_id_user'])) {
- // Load a new user id if needed
- $newValues['gus_id_user'] = $this->_createUserId();
- }
-
- return parent::save($newValues, $filter, $saveTables);
- }
-}
Modified: branches/newUser2/classes/Gems/Model.php
===================================================================
--- branches/newUser2/classes/Gems/Model.php 2011-11-08 15:10:39 UTC (rev 195)
+++ branches/newUser2/classes/Gems/Model.php 2011-11-08 19:02:26 UTC (rev 196)
@@ -129,7 +129,7 @@
$out = intval($out);
try {
- if (0 === $this->db->insert('gems__user_logins', array('gui_id_user' => $out, 'gui_created' => $creationTime))) {
+ if (0 === $this->db->insert('gems__user_ids', array('gui_id_user' => $out, 'gui_created' => $creationTime))) {
$out = null;
}
} catch (Zend_Db_Exception $e) {
@@ -139,6 +139,8 @@
return $out;
}
+
+ return $value;
}
/**
@@ -150,7 +152,7 @@
{
$model = $this->_loadClass('RespondentModel', true);
- $this->addAsUserLogin($model, $this->respondentLoginIdField, 'gr2o_id_organization');
+ // $this->addAsUserLogin($model, $this->respondentLoginIdField, 'gr2o_id_organization');
$this->setAsGemsUserId($model, 'grs_id_user');
return $model;
@@ -172,6 +174,7 @@
}
$model = $this->createRespondentModel();
+
$translated = $this->util->getTranslated();
$model->setIfExists('gr2o_patient_nr', 'label', $this->translate->_('Respondent nr'));
Modified: branches/newUser2/classes/Gems/Project/ProjectSettings.php
===================================================================
--- branches/newUser2/classes/Gems/Project/ProjectSettings.php 2011-11-08 15:10:39 UTC (rev 195)
+++ branches/newUser2/classes/Gems/Project/ProjectSettings.php 2011-11-08 19:02:26 UTC (rev 196)
@@ -147,6 +147,31 @@
}
/**
+ * Checks the super admin password, if it exists
+ *
+ * @param string $password
+ * @return boolean True if the password is correct.
+ */
+ public function checkSuperAdminPassword($password)
+ {
+ return $password && ($password == $this->getSuperAdminPassword($password));
+ }
+
+ /**
+ * Returns the factor used to delay account reloading.
+ *
+ * @return int
+ */
+ public function getAccountDelayFactor()
+ {
+ if (isset($this->account['delayFactor'])) {
+ return intval($this->account['delayFactor']);
+ } else {
+ return 4;
+ }
+ }
+
+ /**
* Returns the super admin name, if any
*
* @return string
@@ -159,11 +184,11 @@
}
/**
- * Returns the super admin password, if any
+ * Returns the super admin password, if it exists
*
* @return string
*/
- public function getSuperAdminPassword()
+ protected function getSuperAdminPassword()
{
if (isset($this->admin['pwd'])) {
return $this->admin['pwd'];
Deleted: branches/newUser2/classes/Gems/User/DatabaseUserAbstract.php
===================================================================
--- branches/newUser2/classes/Gems/User/DatabaseUserAbstract.php 2011-11-08 15:10:39 UTC (rev 195)
+++ branches/newUser2/classes/Gems/User/DatabaseUserAbstract.php 2011-11-08 19:02:26 UTC (rev 196)
@@ -1,83 +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.4.4
- */
-class Gems_User_DatabaseUserAbstract extends Gems_User_UserAbstract
-{
- /**
- *
- * @var Zend_Db_Adapter_Abstract
- */
- protected $db;
-
- /**
- * Simple used name => database field
- * @var array
- */
- protected $fieldMappings = array();
-
- /**
- * Creates the initial feed SQL select statement
- *
- * @return Zend_Db_Select
- */
- abstract public function getSqlSelect();
-
- /**
- * Intialize the values for this user.
- *
- * Skipped when the user is the active user and is stored in the session.
- *
- * @param string $login_name
- * @param int $organization Only used when more than one organization uses this $login_name
- * @return boolean False when the object could not load.
- */
- protected function initVariables($login_name, $organization)
- {
- $select = $this->getSqlSelect();
-
- $userIds = $select->query()->fetchAll();
- }
-}
Added: branches/newUser2/classes/Gems/User/LoginPasswordValidator.php
===================================================================
--- branches/newUser2/classes/Gems/User/LoginPasswordValidator.php (rev 0)
+++ branches/newUser2/classes/Gems/User/LoginPasswordValidator.php 2011-11-08 19:02:26 UTC (rev 196)
@@ -0,0 +1,140 @@
+<?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.'));
+ }
+
+
+ }
+}
Deleted: branches/newUser2/classes/Gems/User/NoLoginUser.php
===================================================================
--- branches/newUser2/classes/Gems/User/NoLoginUser.php 2011-11-08 15:10:39 UTC (rev 195)
+++ branches/newUser2/classes/Gems/User/NoLoginUser.php 2011-11-08 19:02:26 UTC (rev 196)
@@ -1,81 +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.4.4
- */
-class Gems_User_NoLoginUser extends Gems_User_UserAbstract
-{
- /**
- *
- * @var Gems_Util_Translated
- */
- protected $translated;
-
- /**
- * Check that the password is correct for this user.
- *
- * @param string $password Unencrypted password
- * @return boolean
- */
- public function checkPassword($password)
- {
- return false;
- }
-
- /**
- * Intialize the values for this user.
- *
- * Skipped when the user is the active user and is stored in the session.
- *
- * @param string $login_name
- * @param int $organization Only used when more than one organization uses this $login_name
- * @return boolean False when the object could not load.
- */
- protected function initVariables($login_name, $organization)
- {
- $this->setRole('nologin');
- return true;
- }
-
-}
Added: branches/newUser2/classes/Gems/User/PasswordValidator.php
===================================================================
--- branches/newUser2/classes/Gems/User/PasswordValidator.php (rev 0)
+++ branches/newUser2/classes/Gems/User/PasswordValidator.php 2011-11-08 19:02:26 UTC (rev 196)
@@ -0,0 +1,101 @@
+<?php
+
+/**
+ * Copyright (c) 2011, Erasmus MC
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of Erasmus MC nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *
+ * @package Gems
+ * @subpackage User
+ * @author Matijs de Jong <mj...@ma...>
+ * @copyright Copyright (c) 2011 Erasmus MC
+ * @license New BSD License
+ * @version $Id: Sample.php 203 2011-07-07 12:51:32Z matijs $
+ */
+
+/**
+ *
+ *
+ * @package Gems
+ * @subpackage User
+ * @copyright Copyright (c) 2011 Erasmus MC
+ * @license New BSD License
+ * @since Class available since version 1.5
+ */
+class Gems_User_LoginPasswordValidator implements Zend_Validate_Interface
+{
+ /**
+ *
+ * @var string
+ */
+ private $loginField = 'userlogin';
+
+ private $organizationField = 'organization';
+
+ /**
+ *
+ * @var Gems_User_UserLoader
+ */
+ private $userLoader;
+
+ public function __construct(Gems_User_UserLoader $loader, Gems_User_User $user = null)
+ {
+ $this->userLoader = $loader;
+ $this->user = $user;
+ }
+
+ /**
+ * Returns true if and only if $value meets the validation requirements
+ *
+ * If $value fails validation, then this method returns false, and
+ * getMessages() will return an array of messages that explain why the
+ * validation failed.
+ *
+ * @param mixed $value
+ * @param mixed $content
+ * @return boolean
+ * @throws Zend_Validate_Exception If validation of $value is impossible
+ */
+ public function isValid($value, $context = array())
+ {
+ if (! $this->user) {
+ if (isset($context[]))
+ }
+ }
+
+ /**
+ * Returns an array of messages that explain why the most recent isValid()
+ * call returned false. The array keys are validation failure message identifiers,
+ * and the array values are the corresponding human-readable message strings.
+ *
+ * If isValid() was never called or if the most recent isValid() call
+ * returned true, then this method returns an empty array.
+ *
+ * @return array
+ */
+ public function getMessages()
+ {
+ }
+}
Deleted: branches/newUser2/classes/Gems/User/ProjectSuperUser.php
===================================================================
--- branches/newUser2/classes/Gems/User/ProjectSuperUser.php 2011-11-08 15:10:39 UTC (rev 195)
+++ branches/newUser2/classes/Gems/User/ProjectSuperUser.php 2011-11-08 19:02:26 UTC (rev 196)
@@ -1,113 +0,0 @@
-<?php
-
-/**
- * Copyright (c) 2011, Erasmus MC
- * All rights reserved.
- *
- * Redistr...
[truncated message content] |
|
From: <gem...@li...> - 2011-11-08 15:10:48
|
Revision: 195
http://gemstracker.svn.sourceforge.net/gemstracker/?rev=195&view=rev
Author: mennodekker
Date: 2011-11-08 15:10:39 +0000 (Tue, 08 Nov 2011)
Log Message:
-----------
Updated buttons in DatabaseAction -> patchAction, updated buttons for UpgradeAction
Modified Paths:
--------------
trunk/library/classes/Gems/Default/DatabaseAction.php
trunk/library/classes/Gems/Default/UpgradeAction.php
Modified: trunk/library/classes/Gems/Default/DatabaseAction.php
===================================================================
--- trunk/library/classes/Gems/Default/DatabaseAction.php 2011-11-08 13:31:35 UTC (rev 194)
+++ trunk/library/classes/Gems/Default/DatabaseAction.php 2011-11-08 15:10:39 UTC (rev 195)
@@ -382,7 +382,7 @@
$table->setAsFormLayout($form, true, true);
$table['tbody'][0][0]->class = 'label'; // Is only one row with formLayout, so all in output fields get class.
- if ($links = $this->createMenuLinks(10)) {
+ if ($links = $this->createMenuLinks(1)) {
$table->tf(); // Add empty cell, no label
$linksCell = $table->tf($links);
}
Modified: trunk/library/classes/Gems/Default/UpgradeAction.php
===================================================================
--- trunk/library/classes/Gems/Default/UpgradeAction.php 2011-11-08 13:31:35 UTC (rev 194)
+++ trunk/library/classes/Gems/Default/UpgradeAction.php 2011-11-08 15:10:39 UTC (rev 195)
@@ -92,7 +92,7 @@
if ($menuItem = $this->menu->find(array('controller' => $this->_getParam('controller'), 'action' => 'show', 'allowed' => true))) {
$this->html->br();
- $this->html[] = $menuItem->toActionLinkLower($this->getRequest(), array('id'=>$context));
+ $this->html[] = $menuItem->toActionLinkLower($this->getRequest(), array('id'=>$context), $this->_('Back'));
}
}
@@ -181,6 +181,10 @@
} else {
$this->html[] = sprintf($this->_('Context %s not found!'), $context);
}
+
+ if ($parentItem = $this->menu->getCurrent()->getParent()) {
+ $this->html[] = $parentItem->toActionLink($this->getRequest(), $this->_('Cancel'));
+ }
}
public function getTopicTitle() {
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-08 12:46:26
|
Revision: 193
http://gemstracker.svn.sourceforge.net/gemstracker/?rev=193&view=rev
Author: mennodekker
Date: 2011-11-08 12:46:17 +0000 (Tue, 08 Nov 2011)
Log Message:
-----------
Quickfix for storing organization ID from successful login in a cookie (to be discussed, escort getCurrentOrganization commented code do we really need that?)
Modified Paths:
--------------
trunk/library/classes/Gems/Cookies.php
trunk/library/classes/Gems/Default/IndexAction.php
trunk/library/classes/GemsEscort.php
Modified: trunk/library/classes/Gems/Cookies.php
===================================================================
--- trunk/library/classes/Gems/Cookies.php 2011-11-08 10:42:02 UTC (rev 192)
+++ trunk/library/classes/Gems/Cookies.php 2011-11-08 12:46:17 UTC (rev 193)
@@ -45,7 +45,8 @@
*/
class Gems_Cookies
{
- const LOCALE_COOKIE = 'gems_locale';
+ const LOCALE_COOKIE = 'gems_locale';
+ const ORGANIZATION_COOKIE = 'gems_organization';
/**
* Get a specific cookie from the request.
@@ -72,6 +73,17 @@
}
/**
+ * Get the organization from the cookie.
+ *
+ * @param Zend_Controller_Request_Abstract $request
+ * @return int The organization
+ */
+ public static function getOrganization(Zend_Controller_Request_Abstract $request)
+ {
+ return self::get($request, self::ORGANIZATION_COOKIE);
+ }
+
+ /**
* Store this cookie in a generic save method that works for both sub-directory
* installations and own url installations.
*
@@ -104,4 +116,17 @@
// Set the cookie for 30 days
return self::set(self::LOCALE_COOKIE, $locale, 30, $basepath);
}
+
+ /**
+ * Store the organization in a cookie.
+ *
+ * @param int $locale Organization to store
+ * @param string $basepath The folder of the domain, if any.
+ * @return boolean True if the cookie was stored.
+ */
+ public static function setOrganization($locale, $basepath = '/')
+ {
+ // Set the cookie for 30 days
+ return self::set(self::ORGANIZATION_COOKIE, $locale, 30, $basepath);
+ }
}
Modified: trunk/library/classes/Gems/Default/IndexAction.php
===================================================================
--- trunk/library/classes/Gems/Default/IndexAction.php 2011-11-08 10:42:02 UTC (rev 192)
+++ trunk/library/classes/Gems/Default/IndexAction.php 2011-11-08 12:46:17 UTC (rev 193)
@@ -234,9 +234,10 @@
$this->escort->afterLogin($_POST['userlogin']);
/**
- * Fix current locale
+ * Fix current locale & organization
*/
Gems_Cookies::setLocale($this->session->user_locale, $this->basepath->getBasePath());
+ Gems_Cookies::setOrganization($this->session->user_organization_id, $this->basepath->getBasePath());
/**
* Ready
Modified: trunk/library/classes/GemsEscort.php
===================================================================
--- trunk/library/classes/GemsEscort.php 2011-11-08 10:42:02 UTC (rev 192)
+++ trunk/library/classes/GemsEscort.php 2011-11-08 12:46:17 UTC (rev 193)
@@ -1115,6 +1115,7 @@
*/
public function getCurrentOrganization()
{
+ /*
if ($this instanceof Gems_Project_Organization_MultiOrganizationInterface) {
return $this->getUserOrganization();
}
@@ -1122,11 +1123,12 @@
if ($this instanceof Gems_Project_Organization_SingleOrganizationInterface) {
return $this->getRespondentOrganization();
}
+ */
if (isset($this->session->user_organization_id)) {
return $this->session->user_organization_id;
} else {
- return 0;
+ return Gems_Cookies::getOrganization(Zend_Controller_Front::getInstance()->getRequest());
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <gem...@li...> - 2011-11-08 10:42:08
|
Revision: 192
http://gemstracker.svn.sourceforge.net/gemstracker/?rev=192&view=rev
Author: mennodekker
Date: 2011-11-08 10:42:02 +0000 (Tue, 08 Nov 2011)
Log Message:
-----------
A little more documentation
Modified Paths:
--------------
trunk/library/classes/Gems/UpgradesAbstract.php
Modified: trunk/library/classes/Gems/UpgradesAbstract.php
===================================================================
--- trunk/library/classes/Gems/UpgradesAbstract.php 2011-11-08 10:32:48 UTC (rev 191)
+++ trunk/library/classes/Gems/UpgradesAbstract.php 2011-11-08 10:42:02 UTC (rev 192)
@@ -25,8 +25,6 @@
* (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
@@ -35,10 +33,10 @@
*/
/**
- * Short description for Upgrades
+ * This class can take care of handling upgrades that can not be achieved by a
+ * simple db patch. For example adding an extra attribute to all token tables
+ * in LimeSurvey needs a simple loop.
*
- * Long description for class Upgrades (if any)...
- *
* @package Gems
* @subpackage Upgrades
* @copyright Copyright (c) 2011 Erasmus MC
@@ -142,6 +140,18 @@
$this->_messages = array();
}
+ /**
+ * Execute upgrades for the given $context
+ *
+ * When no $to or $from are given, the given $context will be upgraded from the current level
+ * to the max level. Otherwise the $from and/or $to will be used to determine what upgrades
+ * to execute.
+ *
+ * @param string $context The context to execute the upgrades for
+ * @param int|null $to The level to upgrade to
+ * @param int|null $from The level to start the upgrade on
+ * @return false|int The achieved upgrade level or false on failure
+ */
public function execute($context, $to = null, $from = null)
{
if(is_null($to)) {
@@ -182,21 +192,32 @@
return $success;
}
+ /**
+ * Retrieve the current context
+ *
+ * @return string
+ */
public function getContext() {
return $this->_context;
}
+ /**
+ * Get the current upgrade level for the given $context
+ *
+ * @param string $context
+ * @return int
+ */
public function getLevel($context)
{
if(isset($this->_info->$context)) {
- return $this->_info->$context;
+ return intval($this->_info->$context);
} else {
return 0;
}
}
/**
- * Get the highest level for the given context
+ * Get the highest level for the given $context
*
* @param string|null $context
* @return int
@@ -251,6 +272,11 @@
return ++$level;
}
+ /**
+ * Get all messages that were recorded during the upgrade process
+ *
+ * @return array
+ */
public function getMessages()
{
return $this->_messages;
@@ -273,6 +299,12 @@
return array();
}
+ /**
+ * Retrieve info about the $requestedContext or all contexts when omitted
+ *
+ * @param string $requestedContext
+ * @return array
+ */
public function getUpgradesInfo($requestedContext = null)
{
$result = array();
@@ -293,6 +325,19 @@
}
}
+ /**
+ * Register an upgrade in the stack, it can be executed by using $this->execute
+ *
+ * Index and context are optional and will be generated when omitted. For the
+ * user interface to be clear $info should provide a good description of what
+ * the upgrade does.
+ *
+ * @param array|string $callback A valid callback, either string for a method of the current class or array otherwise
+ * @param string $info A descriptive message about what this upgrade does
+ * @param int $index The number of the upgrade
+ * @param string $context The context to which this upgrade applies
+ * @return boolean
+ */
public function register($callback, $info = null, $index = null, $context = null)
{
if (is_string($callback)) {
@@ -325,10 +370,27 @@
return false;
}
+ /**
+ * Change the active context
+ *
+ * Usefull when adding upgrades in the construct to save typing
+ *
+ * @param string $context
+ */
public function setContext($context) {
$this->_context = $context;
}
+ /**
+ * Set the upgrade level for the given $context to a certain level
+ *
+ * Will only update when the $level is higher than the achieved level, unless
+ * when $force = true when it will always update.
+ *
+ * @param string $context
+ * @param int $level
+ * @param boolean $force
+ */
protected function setLevel($context, $level = null, $force = false)
{
if (!is_null($level) &&
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <gem...@li...> - 2011-11-08 10:32:56
|
Revision: 191
http://gemstracker.svn.sourceforge.net/gemstracker/?rev=191&view=rev
Author: matijsdejong
Date: 2011-11-08 10:32:48 +0000 (Tue, 08 Nov 2011)
Log Message:
-----------
Merged 177-190
Modified Paths:
--------------
branches/newUser2/classes/Gems/Default/AskAction.php
branches/newUser2/classes/Gems/Default/DatabaseAction.php
branches/newUser2/classes/Gems/Default/RespondentAction.php
branches/newUser2/classes/Gems/Default/StaffAction.php
branches/newUser2/classes/Gems/Default/TrackActionAbstract.php
branches/newUser2/classes/Gems/Loader.php
branches/newUser2/classes/Gems/Menu/SubMenuItem.php
branches/newUser2/classes/Gems/Menu.php
branches/newUser2/classes/Gems/Util/DatabasePatcher.php
branches/newUser2/classes/GemsEscort.php
branches/newUser2/classes/MUtil/Model/FormBridge.php
branches/newUser2/configs/db/tables/gems__user_logins.10.sql
branches/newUser2/pre_bootstrap.php
Added Paths:
-----------
branches/newUser2/classes/Gems/Default/UpgradeAction.php
branches/newUser2/classes/Gems/Upgrades.php
branches/newUser2/classes/Gems/UpgradesAbstract.php
branches/newUser2/controllers/UpgradeController.php
Property Changed:
----------------
branches/newUser2/
Property changes on: branches/newUser2
___________________________________________________________________
Modified: svn:mergeinfo
- /branches/newUser:113-150
+ /branches/newUser:113-150
/trunk/library:177-190
Modified: branches/newUser2/classes/Gems/Default/AskAction.php
===================================================================
--- branches/newUser2/classes/Gems/Default/AskAction.php 2011-11-08 10:12:18 UTC (rev 190)
+++ branches/newUser2/classes/Gems/Default/AskAction.php 2011-11-08 10:32:48 UTC (rev 191)
@@ -186,6 +186,9 @@
public function indexAction()
{
+ // Make sure to return to ask screen
+ $this->session->return_controller = $this->getRequest()->getControllerName();
+
$tracker = $this->loader->getTracker();
$max_length = $tracker->getTokenLibrary()->getLength();
@@ -242,11 +245,40 @@
public function returnAction()
{
- if (isset($this->session->user_id)) {
+ if (isset($this->session->user_id) && $this->session->user_id) {
$tracker = $this->loader->getTracker();
$token = $tracker->getToken($tracker->filterToken($this->_getParam(MUtil_Model::REQUEST_ID)));
- $this->_reroute(array('controller' => 'respondent', 'action' => 'show', MUtil_Model::REQUEST_ID => $token->getPatientNumber()), true);
+ // Check for completed tokens
+ $this->loader->getTracker()->processCompletedTokens($token->getRespondentId(), $this->session->user_id);
+
+ if (isset($this->session->return_controller) && $this->session->return_controller) {
+ $return = $this->session->return_controller;
+ } else {
+ $return = 'respondent';
+ }
+
+ $parameters['controller'] = $return;
+ $parameters['action'] = 'show';
+ $parameters[MUtil_Model::REQUEST_ID] = $token->getPatientNumber();
+ switch ($return) {
+ case 'track':
+ $parameters['action'] = 'show-track';
+ $parameters[Gems_Model::RESPONDENT_TRACK] = $token->getRespondentTrackId();
+ break;
+
+ case 'survey':
+ $parameters[MUtil_Model::REQUEST_ID] = $token->getTokenId();
+ break;
+
+ case 'ask':
+ $this->_forward('forward');
+ return;
+
+ default:
+ $parameters['controller'] = 'respondent';
+ }
+ $this->_reroute($parameters, true);
} else {
$this->_forward('forward');
}
Modified: branches/newUser2/classes/Gems/Default/DatabaseAction.php
===================================================================
--- branches/newUser2/classes/Gems/Default/DatabaseAction.php 2011-11-08 10:12:18 UTC (rev 190)
+++ branches/newUser2/classes/Gems/Default/DatabaseAction.php 2011-11-08 10:32:48 UTC (rev 191)
@@ -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: branches/newUser2/classes/Gems/Default/RespondentAction.php
===================================================================
--- branches/newUser2/classes/Gems/Default/RespondentAction.php 2011-11-08 10:12:18 UTC (rev 190)
+++ branches/newUser2/classes/Gems/Default/RespondentAction.php 2011-11-08 10:32:48 UTC (rev 191)
@@ -360,6 +360,20 @@
return $this->_('Respondents');
}
+ /**
+ * Initialize translate and html objects
+ *
+ * Called from {@link __construct()} as final step of object instantiation.
+ *
+ * @return void
+ */
+ public function init()
+ {
+ parent::init();
+
+ $this->session->return_controller = $this->getRequest()->getControllerName();
+ }
+
protected function openedRespondent($patientId, $orgId = null, $userId = null)
{
if ($patientId) {
Modified: branches/newUser2/classes/Gems/Default/StaffAction.php
===================================================================
--- branches/newUser2/classes/Gems/Default/StaffAction.php 2011-11-08 10:12:18 UTC (rev 190)
+++ branches/newUser2/classes/Gems/Default/StaffAction.php 2011-11-08 10:32:48 UTC (rev 191)
@@ -105,9 +105,9 @@
$bridge->addHidden( 'gus_id_user');
$bridge->addHidden( 'gsf_id_user'); // Needed for e-mail validation
- $bridge->addHidden( 'gus_user_class');
- $bridge->addText( 'gus_login', 'size', 15, 'minlength', 4,
- 'validator', $model->createUniqueValidator('gus_login'));
+ $bridge->addHidden( 'gsu_user_class');
+ $bridge->addText( 'gsu_login', 'size', 15, 'minlength', 4,
+ 'validator', $model->createUniqueValidator('gsu_login', array('gsu_id_user')));
// Can the organization be changed?
if ($this->escort->hasPrivilege('pr.staff.edit.all')) {
Modified: branches/newUser2/classes/Gems/Default/TrackActionAbstract.php
===================================================================
--- branches/newUser2/classes/Gems/Default/TrackActionAbstract.php 2011-11-08 10:12:18 UTC (rev 190)
+++ branches/newUser2/classes/Gems/Default/TrackActionAbstract.php 2011-11-08 10:32:48 UTC (rev 191)
@@ -352,6 +352,20 @@
parent::indexAction();
}
+ /**
+ * Initialize translate and html objects
+ *
+ * Called from {@link __construct()} as final step of object instantiation.
+ *
+ * @return void
+ */
+ public function init()
+ {
+ parent::init();
+
+ $this->session->return_controller = $this->getRequest()->getControllerName();
+ }
+
public function initFilter()
{
// FROM REQUEST
Copied: branches/newUser2/classes/Gems/Default/UpgradeAction.php (from rev 190, trunk/library/classes/Gems/Default/UpgradeAction.php)
===================================================================
--- branches/newUser2/classes/Gems/Default/UpgradeAction.php (rev 0)
+++ branches/newUser2/classes/Gems/Default/UpgradeAction.php 2011-11-08 10:32:48 UTC (rev 191)
@@ -0,0 +1,193 @@
+<?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 Default
+ * @copyright Copyright (c) 2011 Erasmus MC
+ * @license New BSD License
+ * @version $Id: Sample.php 215 2011-07-12 08:52:54Z michiel $
+ */
+
+/**
+ * This controller handles applying upgrades to the project
+ *
+ * @package Gems
+ * @subpackage Default
+ * @copyright Copyright (c) 2011 Erasmus MC
+ * @license New BSD License
+ * @since Class available since version 1.5
+ */
+class Gems_Default_UpgradeAction extends Gems_Controller_Action
+{
+ public $useHtmlView = true;
+
+ /**
+ * @var Gems_Menu
+ */
+ public $menu;
+
+ /**
+ * @var Gems_Upgrades
+ */
+ protected $_upgrades;
+
+ public function init()
+ {
+ parent::init();
+
+ $this->_upgrades = $this->loader->getUpgrades();
+
+ }
+
+ /**
+ *
+ * @var Gems_Loader
+ */
+ public $loader;
+
+ /**
+ * Executes the upgrades for a certain context
+ *
+ * optional: give from and to levels
+ *
+ * usage: execute/context/<context>{/from/int/to/int}
+ */
+ protected function executeAction()
+ {
+ $context = $this->getRequest()->getParam('id', 'gems');
+ $from = $this->getRequest()->getParam('from');
+ $to = $this->getRequest()->getParam('to');
+
+ $this->html->h3(sprintf($this->_('Upgrading %s'), $context));
+
+ $this->_upgrades->execute($context, $to, $from);
+ $messages = $this->_upgrades->getMessages();
+ foreach($messages as $message) {
+ $this->html->p($message);
+ }
+
+ if ($menuItem = $this->menu->find(array('controller' => $this->_getParam('controller'), 'action' => 'show', 'allowed' => true))) {
+ $this->html->br();
+ $this->html[] = $menuItem->toActionLinkLower($this->getRequest(), array('id'=>$context));
+ }
+ }
+
+ /**
+ * Proxy for the menu
+ */
+ public function executeAllAction() {
+ $this->executeAction();
+ }
+
+ public function executeFromAction() {
+ $this->executeAction();
+ }
+
+ public function executeOneAction() {
+ $this->executeAction();
+ }
+
+ public function executeToAction() {
+ $this->executeAction();
+ }
+
+ /**
+ * Overview of available contexts, max upgrade level and achieved upgrade level
+ */
+ public function indexAction()
+ {
+ $this->html->h3($this->getTopicTitle());
+
+ $displayColumns = array('link' => '',
+ 'context' => $this->_('Context'),
+ 'maxLevel' => $this->_('Max level'),
+ 'level' => $this->_('Level'));
+
+ foreach($this->_upgrades->getUpgradesInfo() as $row) {
+ if ($menuItem = $this->menu->find(array('controller' => $this->_getParam('controller'), 'action' => 'show', 'allowed' => true))) {
+ $row['link'] = $menuItem->toActionLinkLower($this->getRequest(), $row);
+ }
+ $data[] = $row;
+
+ }
+ $this->addSnippet('SelectiveTableSnippet', 'data', $data, 'class', 'browser', 'columns', $displayColumns);
+ }
+
+ /**
+ * Show the upgrades and level for a certain context
+ *
+ * Usage: show/context/<context>
+ */
+ public function showAction()
+ {
+ $this->html->h3($this->getTopicTitle());
+
+ $context = $this->_getParam('id', 'gems');
+ $this->_upgrades->setContext($context);
+ if ($info = $this->_upgrades->getUpgradesInfo($context)) {
+ $this->html->table(array('class'=>'browser'))->tr()
+ ->th($this->_('Context'))->td($info['context'])
+ ->tr()
+ ->th($this->_('Level'))->td($info['level']);
+ $data = $this->_upgrades->getUpgrades();
+ foreach($data as $level => $row) {
+ foreach($this->menu->getCurrent()->getChildren() as $menuItem) {
+ if ($menuItem->is('allowed', true)) {
+ $show = true;
+ if ($level <= $info['level'] && $menuItem->is('action','execute-to')) {
+ //When this level is < current level don't allow to execute from current level to this one
+ $show = false;
+ }
+ if ($level <= $info['level'] && $menuItem->is('action','execute-from')) {
+ //When this level is < current level don't allow to execute from current level to this one
+ $show = false;
+ }
+ if ($show) {
+ $row['action'][] = $menuItem->toActionLinkLower($this->getRequest(), $row, array('from'=>$level, 'to'=>$level));
+ }
+ }
+ }
+ $row['level'] = $level;
+ $data[$level] = $row;
+ }
+ $displayColumns = array('level' => $this->_('Level'),
+ 'info' => $this->_('Description'),
+ 'action' => $this->_('Action'));
+ $this->addSnippet('SelectiveTableSnippet', 'data', $data, 'class', 'browser', 'columns', $displayColumns);
+ } else {
+ $this->html[] = sprintf($this->_('Context %s not found!'), $context);
+ }
+ }
+
+ public function getTopicTitle() {
+ return $this->_('Upgrades');
+ }
+
+ public function getTopic($n = 1) {
+ return $this->_('Upgrades');
+ }
+}
\ No newline at end of file
Modified: branches/newUser2/classes/Gems/Loader.php
===================================================================
--- branches/newUser2/classes/Gems/Loader.php 2011-11-08 10:12:18 UTC (rev 190)
+++ branches/newUser2/classes/Gems/Loader.php 2011-11-08 10:32:48 UTC (rev 191)
@@ -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;
@@ -194,6 +198,15 @@
/**
*
+ * @return Gems_Upgrades
+ */
+ public function getUpgrades()
+ {
+ return $this->_getClass('upgrades');
+ }
+
+ /**
+ *
* @param string $login_name
* @param int $organization
* @return Gems_User_User
Modified: branches/newUser2/classes/Gems/Menu/SubMenuItem.php
===================================================================
--- branches/newUser2/classes/Gems/Menu/SubMenuItem.php 2011-11-08 10:12:18 UTC (rev 190)
+++ branches/newUser2/classes/Gems/Menu/SubMenuItem.php 2011-11-08 10:32:48 UTC (rev 191)
@@ -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: branches/newUser2/classes/Gems/Menu.php
===================================================================
--- branches/newUser2/classes/Gems/Menu.php 2011-11-08 10:12:18 UTC (rev 190)
+++ branches/newUser2/classes/Gems/Menu.php 2011-11-08 10:32:48 UTC (rev 191)
@@ -213,6 +213,14 @@
$logMaint = $page->addPage($this->_('Maintenance'), 'pr.log.maintenance', 'log-maintenance');
$logMaint->addAutofilterAction();
$logMaint->addEditAction('pr.log.maintenance');
+
+ //UPGRADES CONTROLLER
+ $page = $setup->addPage($this->_('Upgrade'), 'pr.upgrade', 'upgrade', 'index');
+ $show = $page->addAction($this->_('Show'), null, 'show')->setNamedParameters('id','context');
+ $page->addAction($this->_('Execute all'), 'pr.upgrade.all', 'execute-all')->setModelParameters(1);
+ $show->addActionButton($this->_('Execute this'), 'pr.upgrade.one', 'execute-one')->setModelParameters(1)->addNamedParameters('from','from','to','to');
+ $show->addActionButton($this->_('Execute from here'), 'pr.upgrade.from', 'execute-from')->setModelParameters(1)->addNamedParameters('from','from');
+ $show->addActionButton($this->_('Execute to here'), 'pr.upgrade.to', 'execute-to')->setModelParameters(1)->addNamedParameters('to','to');
return $setup;
}
Copied: branches/newUser2/classes/Gems/Upgrades.php (from rev 190, trunk/library/classes/Gems/Upgrades.php)
===================================================================
--- branches/newUser2/classes/Gems/Upgrades.php (rev 0)
+++ branches/newUser2/classes/Gems/Upgrades.php 2011-11-08 10:32:48 UTC (rev 191)
@@ -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', 'Upgrade from 1.43 to 1.5');
+ }
+
+
+ /**
+ * 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
Copied: branches/newUser2/classes/Gems/UpgradesAbstract.php (from rev 190, trunk/library/classes/Gems/UpgradesAbstract.php)
===================================================================
--- branches/newUser2/classes/Gems/UpgradesAbstract.php (rev 0)
+++ branches/newUser2/classes/Gems/UpgradesAbstract.php 2011-11-08 10:32:48 UTC (rev 191)
@@ -0,0 +1,342 @@
+<?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 = $this->getMaxLevel($context);
+ }
+ if(is_null($from)) {
+ $from = $this->getNextLevel($context);
+
+ if ($from > $to) {
+ $this->addMessage($this->_('Already at max. level.'));
+ return $to;
+ }
+ }
+ $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;
+ $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 {
+ $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;
+
+ }
+ }
+
+ /**
+ * 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
+ $current++;
+ if (isset($levels[$current])) return $levels[$current];
+
+ //Else return current level +1 (doesn't exist anyway)
+ return ++$level;
+ }
+
+ public function getMessages()
+ {
+ return $this->_messages;
+ }
+
+ /**
+ * Retrieve the upgrades for a certain context, will return an empty array when nothing present.
+ *
+ * @param string $context
+ * @return array
+ */
+ public function getUpgrades($context = null) {
+ if (! $context) {
+ $context = $this->getContext();
+ }
+
+ if (isset($this->_upgradeStack[$context])) {
+ return $this->_upgradeStack[$context];
+ }
+ return array();
+ }
+
+ public function getUpgradesInfo($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, $info = null, $index = null, $context = null)
+ {
+ if (is_string($callback)) {
+ $callback = array(get_class($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]['upgrade'] = $callback;
+ $this->_upgradeStack[$context][$index]['info'] = $info;
+
+ 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
Modified: branches/newUser2/classes/Gems/Util/DatabasePatcher.php
===================================================================
--- branches/newUser2/classes/Gems/Util/DatabasePatcher.php 2011-11-08 10:12:18 UTC (rev 190)
+++ branches/newUser2/classes/Gems/Util/DatabasePatcher.php 2011-11-08 10:32:48 UTC (rev 191)
@@ -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;
}
Modified: branches/newUser2/classes/GemsEscort.php
===================================================================
--- branches/newUser2/classes/GemsEscort.php 2011-11-08 10:12:18 UTC (rev 190)
+++ branches/newUser2/classes/GemsEscort.php 2011-11-08 10:32:48 UTC (rev 191)
@@ -146,25 +146,37 @@
{
$cache = null;
$exists = false;
- $cacheDir = GEMS_ROOT_DIR . "/var/cache/";
- if (!file_exists($cacheDir)) {
- if (@mkdir($cacheDir, 0777, true)) {
+
+ // Check if APC extension is loaded
+ if( extension_loaded('apc') ) {
+ $cacheBackend = 'Apc';
+ $cacheBackendOptions = array();
+ $exists = true;
+ } else {
+ $cacheBackend = 'File';
+ $cacheDir = GEMS_ROOT_DIR . "/var/cache/";
+ $cacheBackendOptions = array('cache_dir' => $cacheDir);
+ if (!file_exists($cacheDir)) {
+ if (@mkdir($cacheDir, 0777, true)) {
+ $exists = true;
+ }
+ } else {
$exists = true;
}
- } else {
- $exists = true;
}
if ($exists) {
- $cacheFrontendOptions = array('automatic_serialization' => true);
- $cacheBackendOptions = array('cache_dir' => $cacheDir);
+ $cacheFrontendOptions = array('automatic_serialization' => true,
+ 'cache_id_prefix' => GEMS_PROJECT_NAME . '_');
- $cache = Zend_Cache::factory('Core', 'File', $cacheFrontendOptions, $cacheBackendOptions);
-
- Zend_Db_Table_Abstract::setDefaultMetadataCache($cache);
- Zend_Translate::setCache($cache);
+ $cache = Zend_Cache::factory('Core', $cacheBackend, $cacheFrontendOptions, $cacheBackendOptions);
+ } else {
+ $cache = Zend_Cache::factory('Core', 'Static', array('caching' => false), array('disable_caching' => true));
}
+ Zend_Db_Table_Abstract::setDefaultMetadataCache($cache);
+ Zend_Translate::setCache($cache);
+
return $cache;
}
Modified: branches/newUser2/classes/MUtil/Model/FormBridge.php
===================================================================
--- branches/newUser2/classes/MUtil/Model/FormBridge.php 2011-11-08 10:12:18 UTC (rev 190)
+++ branches/newUser2/classes/MUtil/Model/FormBridge.php 2011-11-08 10:32:48 UTC (rev 191)
@@ -112,31 +112,6 @@
return $element;
}
- public static function applyFixedOptions($type, array &$options)
- {
- static $typeOptions;
-
- if (! $typeOptions) {
- $typeOptions = Zend_Registry::get('MUtil_Model_FormBridge');
- }
-
- if (substr($type, 0, 3) == 'add') {
- $type = strtolower(substr($type, 3));
- }
- // MUtil_Echo::rs($type, $options);
-
- if (isset($typeOptions[$type])) {
- foreach ($typeOptions[$type] as $key => $value) {
- if (is_array($value) && isset($options[$key])) {
- $options[$key] = $value + $options[$key];
- } else {
- $options[$key] = $value;
- }
- }
- }
- // MUtil_Echo::rs('After', $options, $typeOptions);
- }
-
protected function _applyValidators($name, Zend_Form_Element $element)
{
$validators = $this->model->get($name, 'validators');
@@ -656,6 +631,8 @@
self::DISPLAY_OPTIONS, self::TEXT_OPTIONS, self::TEXTAREA_OPTIONS);
$stringlength = $this->_getStringLength($options);
+ // Remove as size and maxlength are not used for textarea's
+ unset($options['size'], $options['maxlength']);
$element = new Zend_Form_Element_Textarea($name, $options);
@@ -682,6 +659,31 @@
return $this;
}
+ public static function applyFixedOptions($type, array &$options)
+ {
+ static $typeOptions;
+
+ if (! $typeOptions) {
+ $typeOptions = Zend_Registry::get('MUtil_Model_FormBridge');
+ }
+
+ if (substr($type, 0, 3) == 'add') {
+ $type = strtolower(substr($type, 3));
+ }
+ // MUtil_Echo::rs($type, $options);
+
+ if (isset($typeOptions[$type])) {
+ foreach ($typeOptions[$type] as $key => $value) {
+ if (is_array($value) && isset($options[$key])) {
+ $options[$key] = $value + $options[$key];
+ } else {
+ $options[$key] = $value;
+ }
+ }
+ }
+ // MUtil_Echo::rs('After', $options, $typeOptions);
+ }
+
/**
*
* @return Zend_Form
Modified: branches/newUser2/configs/db/tables/gems__user_logins.10.sql
===================================================================
--- branches/newUser2/configs/db/tables/gems__user_logins.10.sql 2011-11-08 10:12:18 UTC (rev 190)
+++ branches/newUser2/configs/db/tables/gems__user_logins.10.sql 2011-11-08 10:32:48 UTC (rev 191)
@@ -14,8 +14,8 @@
gul_created timestamp not null,
gul_created_by bigint unsigned not null,
- PRIMARY KEY (gsl_id_user),
- UNIQUE (gsl_login, gsl_id_organization)
+ PRIMARY KEY (gul_id_user),
+ UNIQUE (gul_login, gul_id_organization)
)
ENGINE=InnoDB
AUTO_INCREMENT = 10001
Copied: branches/newUser2/controllers/UpgradeController.php (from rev 190, trunk/library/controllers/UpgradeController.php)
===================================================================
--- branches/newUser2/controllers/UpgradeController.php (rev 0)
+++ branches/newUser2/controllers/UpgradeController.php 2011-11-08 10:32:48 UTC (rev 191)
@@ -0,0 +1,30 @@
+<?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.
+ */
+class UpgradeController extends Gems_Default_UpgradeAction
+{
+}
\ No newline at end of file
Modified: branches/newUser2/pre_bootstrap.php
===================================================================
--- branches/newUser2/pre_bootstrap.php 2011-11-08 10:12:18 UTC (rev 190)
+++ branches/newUser2/pre_bootstrap.php 2011-11-08 10:32:48 UTC (rev 191)
@@ -1,34 +1,34 @@
<?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.
- */
-
+
/**
+ * 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.
+ */
+
+/**
* This files contains general project code that loads the
* Zend_Application - and does whatever else has to be done.
*
@@ -66,10 +66,11 @@
* then to Gems application directory
*/
set_include_path(
- GEMS_ROOT_DIR . '/library' . PATH_SEPARATOR .
GEMS_LIBRARY_DIR . '/classes' . PATH_SEPARATOR .
APPLICATION_PATH . '/classes' . PATH_SEPARATOR .
- get_include_path());
+ get_include_path()
+ //. PATH_SEPARATOR . GEMS_ROOT_DIR . '/library' //Shouldn't be needed, uncomment when neccessary
+ );
$GEMS_DIRS = array(
GEMS_PROJECT_NAME_UC => APPLICATION_PATH . '/classes',
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <gem...@li...> - 2011-11-08 10:12:25
|
Revision: 190
http://gemstracker.svn.sourceforge.net/gemstracker/?rev=190&view=rev
Author: matijsdejong
Date: 2011-11-08 10:12:18 +0000 (Tue, 08 Nov 2011)
Log Message:
-----------
Restoring token check in show.
Modified Paths:
--------------
trunk/library/classes/Gems/Default/RespondentAction.php
Modified: trunk/library/classes/Gems/Default/RespondentAction.php
===================================================================
--- trunk/library/classes/Gems/Default/RespondentAction.php 2011-11-08 09:42:10 UTC (rev 189)
+++ trunk/library/classes/Gems/Default/RespondentAction.php 2011-11-08 10:12:18 UTC (rev 190)
@@ -401,6 +401,12 @@
// Log
$this->openedRespondent($data['gr2o_patient_nr'], $data['gr2o_id_organization'], $data['grs_id_user']);
+ // Check for completed tokens
+ if ($this->loader->getTracker()->processCompletedTokens($data['grs_id_user'], $this->session->user_id)) {
+ //As data might have changed due to token events... reload
+ $data = $model->applyRequest($this->getRequest(), true)->loadFirst();
+ }
+
if ($data['gr2o_consent'] == $model->get('gr2o_consent', 'default')) {
$url = $this->view->url(array('controller' => 'respondent', 'action' => 'edit', 'id' => $data['gr2o_patient_nr'])) . '#tabContainer-frag-3';
$this->addMessage(MUtil_Html::create()->a($url, $this->_('Please settle the informed consent form for this respondent.')));
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <gem...@li...> - 2011-11-08 09:42:21
|
Revision: 189
http://gemstracker.svn.sourceforge.net/gemstracker/?rev=189&view=rev
Author: mennodekker
Date: 2011-11-08 09:42:10 +0000 (Tue, 08 Nov 2011)
Log Message:
-----------
Added controller for #34, privileges not set by default at this time
Modified Paths:
--------------
trunk/library/classes/Gems/Menu.php
trunk/library/classes/Gems/UpgradesAbstract.php
Added Paths:
-----------
trunk/library/classes/Gems/Default/UpgradeAction.php
trunk/library/controllers/UpgradeController.php
Added: trunk/library/classes/Gems/Default/UpgradeAction.php
===================================================================
--- trunk/library/classes/Gems/Default/UpgradeAction.php (rev 0)
+++ trunk/library/classes/Gems/Default/UpgradeAction.php 2011-11-08 09:42:10 UTC (rev 189)
@@ -0,0 +1,193 @@
+<?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 Default
+ * @copyright Copyright (c) 2011 Erasmus MC
+ * @license New BSD License
+ * @version $Id: Sample.php 215 2011-07-12 08:52:54Z michiel $
+ */
+
+/**
+ * This controller handles applying upgrades to the project
+ *
+ * @package Gems
+ * @subpackage Default
+ * @copyright Copyright (c) 2011 Erasmus MC
+ * @license New BSD License
+ * @since Class available since version 1.5
+ */
+class Gems_Default_UpgradeAction extends Gems_Controller_Action
+{
+ public $useHtmlView = true;
+
+ /**
+ * @var Gems_Menu
+ */
+ public $menu;
+
+ /**
+ * @var Gems_Upgrades
+ */
+ protected $_upgrades;
+
+ public function init()
+ {
+ parent::init();
+
+ $this->_upgrades = $this->loader->getUpgrades();
+
+ }
+
+ /**
+ *
+ * @var Gems_Loader
+ */
+ public $loader;
+
+ /**
+ * Executes the upgrades for a certain context
+ *
+ * optional: give from and to levels
+ *
+ * usage: execute/context/<context>{/from/int/to/int}
+ */
+ protected function executeAction()
+ {
+ $context = $this->getRequest()->getParam('id', 'gems');
+ $from = $this->getRequest()->getParam('from');
+ $to = $this->getRequest()->getParam('to');
+
+ $this->html->h3(sprintf($this->_('Upgrading %s'), $context));
+
+ $this->_upgrades->execute($context, $to, $from);
+ $messages = $this->_upgrades->getMessages();
+ foreach($messages as $message) {
+ $this->html->p($message);
+ }
+
+ if ($menuItem = $this->menu->find(array('controller' => $this->_getParam('controller'), 'action' => 'show', 'allowed' => true))) {
+ $this->html->br();
+ $this->html[] = $menuItem->toActionLinkLower($this->getRequest(), array('id'=>$context));
+ }
+ }
+
+ /**
+ * Proxy for the menu
+ */
+ public function executeAllAction() {
+ $this->executeAction();
+ }
+
+ public function executeFromAction() {
+ $this->executeAction();
+ }
+
+ public function executeOneAction() {
+ $this->executeAction();
+ }
+
+ public function executeToAction() {
+ $this->executeAction();
+ }
+
+ /**
+ * Overview of available contexts, max upgrade level and achieved upgrade level
+ */
+ public function indexAction()
+ {
+ $this->html->h3($this->getTopicTitle());
+
+ $displayColumns = array('link' => '',
+ 'context' => $this->_('Context'),
+ 'maxLevel' => $this->_('Max level'),
+ 'level' => $this->_('Level'));
+
+ foreach($this->_upgrades->getUpgradesInfo() as $row) {
+ if ($menuItem = $this->menu->find(array('controller' => $this->_getParam('controller'), 'action' => 'show', 'allowed' => true))) {
+ $row['link'] = $menuItem->toActionLinkLower($this->getRequest(), $row);
+ }
+ $data[] = $row;
+
+ }
+ $this->addSnippet('SelectiveTableSnippet', 'data', $data, 'class', 'browser', 'columns', $displayColumns);
+ }
+
+ /**
+ * Show the upgrades and level for a certain context
+ *
+ * Usage: show/context/<context>
+ */
+ public function showAction()
+ {
+ $this->html->h3($this->getTopicTitle());
+
+ $context = $this->_getParam('id', 'gems');
+ $this->_upgrades->setContext($context);
+ if ($info = $this->_upgrades->getUpgradesInfo($context)) {
+ $this->html->table(array('class'=>'browser'))->tr()
+ ->th($this->_('Context'))->td($info['context'])
+ ->tr()
+ ->th($this->_('Level'))->td($info['level']);
+ $data = $this->_upgrades->getUpgrades();
+ foreach($data as $level => $row) {
+ foreach($this->menu->getCurrent()->getChildren() as $menuItem) {
+ if ($menuItem->is('allowed', true)) {
+ $show = true;
+ if ($level <= $info['level'] && $menuItem->is('action','execute-to')) {
+ //When this level is < current level don't allow to execute from current level to this one
+ $show = false;
+ }
+ if ($level <= $info['level'] && $menuItem->is('action','execute-from')) {
+ //When this level is < current level don't allow to execute from current level to this one
+ $show = false;
+ }
+ if ($show) {
+ $row['action'][] = $menuItem->toActionLinkLower($this->getRequest(), $row, array('from'=>$level, 'to'=>$level));
+ }
+ }
+ }
+ $row['level'] = $level;
+ $data[$level] = $row;
+ }
+ $displayColumns = array('level' => $this->_('Level'),
+ 'info' => $this->_('Description'),
+ 'action' => $this->_('Action'));
+ $this->addSnippet('SelectiveTableSnippet', 'data', $data, 'class', 'browser', 'columns', $displayColumns);
+ } else {
+ $this->html[] = sprintf($this->_('Context %s not found!'), $context);
+ }
+ }
+
+ public function getTopicTitle() {
+ return $this->_('Upgrades');
+ }
+
+ public function getTopic($n = 1) {
+ return $this->_('Upgrades');
+ }
+}
\ No newline at end of file
Modified: trunk/library/classes/Gems/Menu.php
===================================================================
--- trunk/library/classes/Gems/Menu.php 2011-11-07 15:30:23 UTC (rev 188)
+++ trunk/library/classes/Gems/Menu.php 2011-11-08 09:42:10 UTC (rev 189)
@@ -213,6 +213,14 @@
$logMaint = $page->addPage($this->_('Maintenance'), 'pr.log.maintenance', 'log-maintenance');
$logMaint->addAutofilterAction();
$logMaint->addEditAction('pr.log.maintenance');
+
+ //UPGRADES CONTROLLER
+ $page = $setup->addPage($this->_('Upgrade'), 'pr.upgrade', 'upgrade', 'index');
+ $show = $page->addAction($this->_('Show'), null, 'show')->setNamedParameters('id','context');
+ $page->addAction($this->_('Execute all'), 'pr.upgrade.all', 'execute-all')->setModelParameters(1);
+ $show->addActionButton($this->_('Execute this'), 'pr.upgrade.one', 'execute-one')->setModelParameters(1)->addNamedParameters('from','from','to','to');
+ $show->addActionButton($this->_('Execute from here'), 'pr.upgrade.from', 'execute-from')->setModelParameters(1)->addNamedParameters('from','from');
+ $show->addActionButton($this->_('Execute to here'), 'pr.upgrade.to', 'execute-to')->setModelParameters(1)->addNamedParameters('to','to');
return $setup;
}
Modified: trunk/library/classes/Gems/UpgradesAbstract.php
===================================================================
--- trunk/library/classes/Gems/UpgradesAbstract.php 2011-11-07 15:30:23 UTC (rev 188)
+++ trunk/library/classes/Gems/UpgradesAbstract.php 2011-11-08 09:42:10 UTC (rev 189)
@@ -148,7 +148,7 @@
$to = $this->getMaxLevel($context);
}
if(is_null($from)) {
- $from = $this->getNextLevel();
+ $from = $this->getNextLevel($context);
if ($from > $to) {
$this->addMessage($this->_('Already at max. level.'));
@@ -165,7 +165,7 @@
ksort($upgrades);
$this->_upgradeStack[$context] = $upgrades;
foreach($this->_upgradeStack[$context] as $level => $upgrade) {
- if (($level > $from && $level <= $to)) {
+ 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;
@@ -244,10 +244,11 @@
$current = array_search($level, $levels);
//And if it is present, return the next level
- if (isset($levels[$current++])) return $levels[$current++];
+ $current++;
+ if (isset($levels[$current])) return $levels[$current];
//Else return current level +1 (doesn't exist anyway)
- return $level++;
+ return ++$level;
}
public function getMessages()
Added: trunk/library/controllers/UpgradeController.php
===================================================================
--- trunk/library/controllers/UpgradeController.php (rev 0)
+++ trunk/library/controllers/UpgradeController.php 2011-11-08 09:42:10 UTC (rev 189)
@@ -0,0 +1,30 @@
+<?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.
+ */
+class UpgradeController extends Gems_Default_UpgradeAction
+{
+}
\ 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-07 13:48:41
|
Revision: 187
http://gemstracker.svn.sourceforge.net/gemstracker/?rev=187&view=rev
Author: michieltcs
Date: 2011-11-07 13:48:32 +0000 (Mon, 07 Nov 2011)
Log Message:
-----------
Allow creation of (dummy) cache when cache directory is not writeable
Modified Paths:
--------------
trunk/library/classes/GemsEscort.php
Modified: trunk/library/classes/GemsEscort.php
===================================================================
--- trunk/library/classes/GemsEscort.php 2011-11-07 09:26:56 UTC (rev 186)
+++ trunk/library/classes/GemsEscort.php 2011-11-07 13:48:32 UTC (rev 187)
@@ -170,11 +170,13 @@
'cache_id_prefix' => GEMS_PROJECT_NAME . '_');
$cache = Zend_Cache::factory('Core', $cacheBackend, $cacheFrontendOptions, $cacheBackendOptions);
-
- Zend_Db_Table_Abstract::setDefaultMetadataCache($cache);
- Zend_Translate::setCache($cache);
+ } else {
+ $cache = Zend_Cache::factory('Core', 'Static', array('caching' => false), array('disable_caching' => true));
}
+ Zend_Db_Table_Abstract::setDefaultMetadataCache($cache);
+ Zend_Translate::setCache($cache);
+
return $cache;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <gem...@li...> - 2011-11-07 09:27:02
|
Revision: 186
http://gemstracker.svn.sourceforge.net/gemstracker/?rev=186&view=rev
Author: mennodekker
Date: 2011-11-07 09:26:56 +0000 (Mon, 07 Nov 2011)
Log Message:
-----------
Improved cache by using prefix so 'apc' won't get name clashes on a shared environment
Modified Paths:
--------------
trunk/library/classes/GemsEscort.php
Modified: trunk/library/classes/GemsEscort.php
===================================================================
--- trunk/library/classes/GemsEscort.php 2011-11-04 14:01:18 UTC (rev 185)
+++ trunk/library/classes/GemsEscort.php 2011-11-07 09:26:56 UTC (rev 186)
@@ -166,7 +166,8 @@
}
if ($exists) {
- $cacheFrontendOptions = array('automatic_serialization' => true);
+ $cacheFrontendOptions = array('automatic_serialization' => true,
+ 'cache_id_prefix' => GEMS_PROJECT_NAME . '_');
$cache = Zend_Cache::factory('Core', $cacheBackend, $cacheFrontendOptions, $cacheBackendOptions);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <gem...@li...> - 2011-11-04 14:01:24
|
Revision: 185
http://gemstracker.svn.sourceforge.net/gemstracker/?rev=185&view=rev
Author: mennodekker
Date: 2011-11-04 14:01:18 +0000 (Fri, 04 Nov 2011)
Log Message:
-----------
Minor fixes for #34
Modified Paths:
--------------
trunk/library/classes/Gems/UpgradesAbstract.php
Modified: trunk/library/classes/Gems/UpgradesAbstract.php
===================================================================
--- trunk/library/classes/Gems/UpgradesAbstract.php 2011-11-04 12:49:12 UTC (rev 184)
+++ trunk/library/classes/Gems/UpgradesAbstract.php 2011-11-04 14:01:18 UTC (rev 185)
@@ -145,7 +145,7 @@
public function execute($context, $to = null, $from = null)
{
if(is_null($to)) {
- $to = count($this->_upgradeStack[$context]);
+ $to = $this->getMaxLevel($context);
}
if(is_null($from)) {
$from = $this->getLevel($context);
@@ -214,7 +214,24 @@
return $this->_messages;
}
- public function getUpgrades($requestedContext = null)
+ /**
+ * Retrieve the upgrades for a certain context, will return an empty array when nothing present.
+ *
+ * @param string $context
+ * @return array
+ */
+ public function getUpgrades($context = null) {
+ if (! $context) {
+ $context = $this->getContext();
+ }
+
+ if (isset($this->_upgradeStack[$context])) {
+ return $this->_upgradeStack[$context];
+ }
+ return array();
+ }
+
+ public function getUpgradesInfo($requestedContext = null)
{
$result = array();
foreach($this->_upgradeStack as $context => $content) {
@@ -237,7 +254,7 @@
public function register($callback, $index = null, $context = null)
{
if (is_string($callback)) {
- $callback = array($this, $callback);
+ $callback = array(get_class($this), $callback);
}
if (is_callable($callback)) {
if (! $context) {
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-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 11:39:49
|
Revision: 182
http://gemstracker.svn.sourceforge.net/gemstracker/?rev=182&view=rev
Author: mennodekker
Date: 2011-11-04 11:39:43 +0000 (Fri, 04 Nov 2011)
Log Message:
-----------
use Apc memory cache when available (add more when needed)
Modified Paths:
--------------
trunk/library/classes/GemsEscort.php
Modified: trunk/library/classes/GemsEscort.php
===================================================================
--- trunk/library/classes/GemsEscort.php 2011-11-04 11:18:25 UTC (rev 181)
+++ trunk/library/classes/GemsEscort.php 2011-11-04 11:39:43 UTC (rev 182)
@@ -146,20 +146,29 @@
{
$cache = null;
$exists = false;
- $cacheDir = GEMS_ROOT_DIR . "/var/cache/";
- if (!file_exists($cacheDir)) {
- if (@mkdir($cacheDir, 0777, true)) {
+
+ // Check if APC extension is loaded
+ if( extension_loaded('apc') ) {
+ $cacheBackend = 'Apc';
+ $cacheBackendOptions = array();
+ $exists = true;
+ } else {
+ $cacheBackend = 'File';
+ $cacheDir = GEMS_ROOT_DIR . "/var/cache/";
+ $cacheBackendOptions = array('cache_dir' => $cacheDir);
+ if (!file_exists($cacheDir)) {
+ if (@mkdir($cacheDir, 0777, true)) {
+ $exists = true;
+ }
+ } else {
$exists = true;
}
- } else {
- $exists = true;
}
if ($exists) {
$cacheFrontendOptions = array('automatic_serialization' => true);
- $cacheBackendOptions = array('cache_dir' => $cacheDir);
- $cache = Zend_Cache::factory('Core', 'File', $cacheFrontendOptions, $cacheBackendOptions);
+ $cache = Zend_Cache::factory('Core', $cacheBackend, $cacheFrontendOptions, $cacheBackendOptions);
Zend_Db_Table_Abstract::setDefaultMetadataCache($cache);
Zend_Translate::setCache($cache);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <gem...@li...> - 2011-11-04 11:18:31
|
Revision: 181
http://gemstracker.svn.sourceforge.net/gemstracker/?rev=181&view=rev
Author: matijsdejong
Date: 2011-11-04 11:18:25 +0000 (Fri, 04 Nov 2011)
Log Message:
-----------
Small fix in attributes used with a text area
Modified Paths:
--------------
trunk/library/classes/MUtil/Model/FormBridge.php
Modified: trunk/library/classes/MUtil/Model/FormBridge.php
===================================================================
--- trunk/library/classes/MUtil/Model/FormBridge.php 2011-11-04 09:59:31 UTC (rev 180)
+++ trunk/library/classes/MUtil/Model/FormBridge.php 2011-11-04 11:18:25 UTC (rev 181)
@@ -112,31 +112,6 @@
return $element;
}
- public static function applyFixedOptions($type, array &$options)
- {
- static $typeOptions;
-
- if (! $typeOptions) {
- $typeOptions = Zend_Registry::get('MUtil_Model_FormBridge');
- }
-
- if (substr($type, 0, 3) == 'add') {
- $type = strtolower(substr($type, 3));
- }
- // MUtil_Echo::rs($type, $options);
-
- if (isset($typeOptions[$type])) {
- foreach ($typeOptions[$type] as $key => $value) {
- if (is_array($value) && isset($options[$key])) {
- $options[$key] = $value + $options[$key];
- } else {
- $options[$key] = $value;
- }
- }
- }
- // MUtil_Echo::rs('After', $options, $typeOptions);
- }
-
protected function _applyValidators($name, Zend_Form_Element $element)
{
$validators = $this->model->get($name, 'validators');
@@ -656,6 +631,8 @@
self::DISPLAY_OPTIONS, self::TEXT_OPTIONS, self::TEXTAREA_OPTIONS);
$stringlength = $this->_getStringLength($options);
+ // Remove as size and maxlength are not used for textarea's
+ unset($options['size'], $options['maxlength']);
$element = new Zend_Form_Element_Textarea($name, $options);
@@ -682,6 +659,31 @@
return $this;
}
+ public static function applyFixedOptions($type, array &$options)
+ {
+ static $typeOptions;
+
+ if (! $typeOptions) {
+ $typeOptions = Zend_Registry::get('MUtil_Model_FormBridge');
+ }
+
+ if (substr($type, 0, 3) == 'add') {
+ $type = strtolower(substr($type, 3));
+ }
+ // MUtil_Echo::rs($type, $options);
+
+ if (isset($typeOptions[$type])) {
+ foreach ($typeOptions[$type] as $key => $value) {
+ if (is_array($value) && isset($options[$key])) {
+ $options[$key] = $value + $options[$key];
+ } else {
+ $options[$key] = $value;
+ }
+ }
+ }
+ // MUtil_Echo::rs('After', $options, $typeOptions);
+ }
+
/**
*
* @return Zend_Form
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|