|
From: <gem...@li...> - 2011-11-24 11:11:20
|
Revision: 279
http://gemstracker.svn.sourceforge.net/gemstracker/?rev=279&view=rev
Author: matijsdejong
Date: 2011-11-24 11:11:14 +0000 (Thu, 24 Nov 2011)
Log Message:
-----------
Moved functionality from OrganizationAction.php to User->setCurrentOrganization()
Moved determination of password rule codes from PasswordChecker.php to User.php (seemed more logical and better extensible)
Modified Paths:
--------------
trunk/library/changelog.txt
trunk/library/classes/Gems/Default/OrganizationAction.php
trunk/library/classes/Gems/Project/ProjectSettings.php
trunk/library/classes/Gems/User/Organization.php
trunk/library/classes/Gems/User/PasswordChecker.php
trunk/library/classes/Gems/User/User.php
trunk/library/classes/Gems/User/UserLoader.php
Modified: trunk/library/changelog.txt
===================================================================
--- trunk/library/changelog.txt 2011-11-23 18:52:36 UTC (rev 278)
+++ trunk/library/changelog.txt 2011-11-24 11:11:14 UTC (rev 279)
@@ -4,6 +4,7 @@
Setting rules for user passwords has changed and has become more powerfull, unless you do not set them.
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.
GemsEscort->afterLogin(), ->afterLogout() and ->loadLoginInfo(0 are now all handled by Gems_User_UserDefinitionInterface objects.
+GemsEscort->session kept for compatibility reasons, but use should be stopped.
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.
Modified: trunk/library/classes/Gems/Default/OrganizationAction.php
===================================================================
--- trunk/library/classes/Gems/Default/OrganizationAction.php 2011-11-23 18:52:36 UTC (rev 278)
+++ trunk/library/classes/Gems/Default/OrganizationAction.php 2011-11-24 11:11:14 UTC (rev 279)
@@ -79,49 +79,14 @@
$allowedOrganizations = $user->getAllowedOrganizations();
if (isset($allowedOrganizations[$orgId])) {
- $this->session->user_organization_id = $orgId;
- $this->session->user_organization_name = $allowedOrganizations[$orgId];
+ $user->setCurrentOrganization($orgId);
- if ($this->escort instanceof Gems_Project_Layout_MultiLayoutInterface) {
- $this->session->user_style = $this->db->fetchOne(
- "SELECT gor_style
- FROM gems__organizations
- WHERE gor_id_organization = ?", $orgId
- );
+ if ($url) {
+ $this->getResponse()->setRedirect($url);
+ } else {
+ $user->gotoStartPage($this->menu, $request);
}
-
- // Now update the requestcache to change the oldOrgId to the new orgId
- // Don't do it when the oldOrgId doesn't match
- $requestCache = $this->session->requestCache;
-
- //Create the list of request cache keys that match an organization ID (to be extended)
- $possibleOrgIds = array(
- 'gr2o_id_organization',
- 'gto_id_organization');
-
- foreach ($requestCache as $key => $value) {
- if (is_array($value)) {
- foreach ($value as $paramKey => $paramValue) {
- if (in_array($paramKey, $possibleOrgIds)) {
- if ($paramValue == $oldOrgId) {
- $requestCache[$key][$paramKey] = $orgId;
- }
- }
- }
- }
- }
- $this->session->requestCache = $requestCache;
-
- if (Gems_Cookies::setOrganization($orgId, $this->basepath->getBasePath())) {
- if ($url) {
- $this->getResponse()->setRedirect($url);
- } else {
- $user->gotoStartPage($this->menu, $request);
- }
- return;
- }
-
- throw new Exception($this->_('Cookies must be enabled.'));
+ return;
}
throw new Exception($this->_('Invalid organization.'));
@@ -137,27 +102,6 @@
parent::createAction();
}
-
- public function chooseAction()
- {
- $this->addSnippet('Organization_ChooseOrganizationSnippet');
- $this->html->h3($this->_('Choose an organization'));
-
- $user = $this->loader->getCurrentUser();
- $request = $this->getRequest();
-
- foreach ($user->getAllowedOrganizations() as $orgId => $name) {
- $org = $this->loader->getOrganization($orgId);
-
- if ($org->canHaveRespondents()) {
- $url = array($request->getActionKey() => 'change-ui');
- $url['org'] = $orgId;
-
- $this->html->pInfo()->actionLink($url, $name, array('style' => 'font-size: 120%;'));
- }
- }
- }
-
/**
* Creates a model for getModel(). Called only for each new $action.
*
Modified: trunk/library/classes/Gems/Project/ProjectSettings.php
===================================================================
--- trunk/library/classes/Gems/Project/ProjectSettings.php 2011-11-23 18:52:36 UTC (rev 278)
+++ trunk/library/classes/Gems/Project/ProjectSettings.php 2011-11-24 11:11:14 UTC (rev 279)
@@ -100,13 +100,21 @@
$this->checkRequiredValues();
}
- protected function _getPasswordRules(array $current, array $keys, array &$rules)
+ /**
+ * Add recursively the rules active for this specific set of codes.
+ *
+ * @param array $current The current (part)sub) array of $this->passwords to check
+ * @param array $codes An array of code names that identify rules that should be used only for those codes.
+ * @param array $rules The array that stores the activated rules.
+ * @return void
+ */
+ protected function _getPasswordRules(array $current, array $codes, array &$rules)
{
foreach ($current as $key => $value) {
if (is_array($value)) {
// Only act when this is in the set of key values
- if (isset($keys[strtolower($key)])) {
- $this->_getPasswordRules($value, $keys, $rules);
+ if (isset($codes[strtolower($key)])) {
+ $this->_getPasswordRules($value, $codes, $rules);
}
} else {
$rules[$key] = $value;
@@ -195,6 +203,30 @@
}
/**
+ * Returns an array with throttling settings for the ask
+ * controller
+ *
+ * @return array
+ */
+ public function getAskThrottleSettings()
+ {
+ // Check for the 'askThrottle' config section
+ if (!empty($this->askThrottle)) {
+ return $this->askThrottle;
+ } else {
+ // Set some sensible defaults
+ // Detection window: 15 minutes
+ // Threshold: 20 requests per minute
+ // Delay: 10 seconds
+ $throttleSettings = array(
+ 'period' => 15 * 60,
+ 'threshold' => 15 * 20,
+ 'delay' => 10
+ );
+ }
+ }
+
+ /**
* Returns the public name of this project.
* @return string
*/
@@ -204,20 +236,20 @@
}
/**
+ * Get the rules active for this specific set of codes.
*
- * @param string $userDefinition
- * @param string $role
+ * @param array $codes An array of code names that identify rules that should be used only for those codes.
* @return array
*/
- public function getPasswordRules($userDefinition, $role)
+ public function getPasswordRules(array $codes)
{
- $args = MUtil_Ra::flatten(func_get_args());
- $args = array_change_key_case(array_flip(array_filter($args)));
- // MUtil_Echo::track($args);
+ // Process the codes array to a format better used for filtering
+ $codes = array_change_key_case(array_flip(array_filter($codes)));
+ // MUtil_Echo::track($codes);
$rules = array();
if (isset($this->passwords) && is_array($this->passwords)) {
- $this->_getPasswordRules($this->passwords, $args, $rules);
+ $this->_getPasswordRules($this->passwords, $codes, $rules);
}
return $rules;
@@ -238,30 +270,6 @@
}
/**
- * Returns an array with throttling settings for the ask
- * controller
- *
- * @return array
- */
- public function getAskThrottleSettings()
- {
- // Check for the 'askThrottle' config section
- if (!empty($this->askThrottle)) {
- return $this->askThrottle;
- } else {
- // Set some sensible defaults
- // Detection window: 15 minutes
- // Threshold: 20 requests per minute
- // Delay: 10 seconds
- $throttleSettings = array(
- 'period' => 15 * 60,
- 'threshold' => 15 * 20,
- 'delay' => 10
- );
- }
- }
-
- /**
* Returns the super admin name, if any
*
* @return string
@@ -296,7 +304,7 @@
return $this->admin['ipRanges'];
}
}
-
+
/**
* Returns a salted hash on the
*
Modified: trunk/library/classes/Gems/User/Organization.php
===================================================================
--- trunk/library/classes/Gems/User/Organization.php 2011-11-23 18:52:36 UTC (rev 278)
+++ trunk/library/classes/Gems/User/Organization.php 2011-11-24 11:11:14 UTC (rev 279)
@@ -186,7 +186,7 @@
}
/**
- * Get the style attribute.
+ * Get the code attribute.
*
* @return string
*/
@@ -196,6 +196,26 @@
}
/**
+ * Get the organization id.
+ *
+ * @return int
+ */
+ public function getId()
+ {
+ return $this->_organizationData['gor_id_organization'];
+ }
+
+ /**
+ * Get the name of the organization.
+ *
+ * @return string
+ */
+ public function getName()
+ {
+ return $this->_organizationData['gor_name'];
+ }
+
+ /**
* Get the style attribute.
*
* @return string
Modified: trunk/library/classes/Gems/User/PasswordChecker.php
===================================================================
--- trunk/library/classes/Gems/User/PasswordChecker.php 2011-11-23 18:52:36 UTC (rev 278)
+++ trunk/library/classes/Gems/User/PasswordChecker.php 2011-11-24 11:11:14 UTC (rev 279)
@@ -206,16 +206,16 @@
/**
* Check for password weakness.
*
- * @param Gems_User_User $user The user for e.g. name checks
* @param string $password
+ * @param array $codes An array of code names that identify rules that should be used only for those codes.
* @return mixed String or array of strings containing warning messages
*/
- public function reportPasswordWeakness(Gems_User_User $user, $password)
+ public function reportPasswordWeakness(Gems_User_User $user, $password, array $codes)
{
+ $this->user = $user;
$this->_errors = array();
- $this->user = $user;
- $rules = $this->project->getPasswordRules($user->getOrganizationCode(), $user->getRoles(), $user->getDefinitionName());
+ $rules = $this->project->getPasswordRules($codes);
// MUtil_Echo::track($rules);
foreach ($rules as $rule => $parameter) {
Modified: trunk/library/classes/Gems/User/User.php
===================================================================
--- trunk/library/classes/Gems/User/User.php 2011-11-23 18:52:36 UTC (rev 278)
+++ trunk/library/classes/Gems/User/User.php 2011-11-24 11:11:14 UTC (rev 279)
@@ -59,30 +59,42 @@
private $_vars;
/**
+ * Required
*
* @var MUtil_Acl
*/
protected $acl;
/**
+ * Required
*
+ * @var Gems_Util_BasePath
+ */
+ protected $basepath;
+
+ /**
+ * Required
+ *
* @var Zend_Db_Adapter_Abstract
*/
protected $db;
/**
+ * Required, set in constructor
*
* @var Gems_User_UserDefinitionInterface
*/
protected $definition;
/**
+ * Required
*
* @var Zend_Session_Namespace
*/
protected $session;
/**
+ * Required
*
* @var Gems_User_UserLoader
*/
@@ -260,7 +272,7 @@
*/
public function checkRegistryRequestsAnswers()
{
- if (! $this->session instanceof Zend_Session_Namespace) {
+ if (! (($this->db instanceof Zend_Db_Adapter_Abstract) && ($this->session instanceof Zend_Session_Namespace))) {
return false;
}
@@ -292,7 +304,7 @@
$this->refreshAllowedOrganizations();
}
- return true;
+ return (boolean) $this->acl && $this->basepath && $this->userLoader;
}
/**
@@ -319,11 +331,11 @@
* Returns the name of the user definition.
*
* @return string
- */
+ * NOT NEEDED FOR THE MOMENT /
public function getDefinitionName()
{
return $this->_getVar('__user_definition');
- }
+ } // */
/**
* Return true if this user has a password.
@@ -390,6 +402,15 @@
/**
*
+ * @return Gems_User_Organization
+ */
+ public function getOrganization()
+ {
+ return $this->userLoader->getOrganization($this->getOrganizationId());
+ }
+
+ /**
+ *
* @return int
*/
public function getOrganizationId()
@@ -407,13 +428,13 @@
* Gets the (optional) organization code.
*
* @return string
- */
+ * NOT NEEDED FOR THE MOMENT /
public function getOrganizationCode()
{
$organizationId = $this->getOrganizationId();
return $this->userLoader->getOrganization($organizationId)->getCode();
- }
+ } // */
/**
* Return a password reset key
@@ -632,7 +653,11 @@
if ($this->canSetPassword()) {
$checker = $this->userLoader->getPasswordChecker();
- return $checker->reportPasswordWeakness($this, $password);
+ $codes[] = $this->getOrganization()->getCode();
+ $codes[] = $this->getRoles();
+ $codes[] = $this->_getVar('__user_definition');
+
+ return $checker->reportPasswordWeakness($this, $password, MUtil_Ra::flatten($codes));
}
}
@@ -667,7 +692,64 @@
return $this;
}
+ /**
+ * Set the currently selected organization for this user
+ *
+ * @param mixed $organization Gems_User_Organization or an organization id.
+ * @return Gems_User_User (continuation pattern)
+ */
+ public function setCurrentOrganization($organization)
+ {
+ if ($organization instanceof Gems_User_Organization) {
+ $organizationId = $organization->getId();
+ } else {
+ $organizationId = $organization;
+ $organization = $this->userLoader->getOrganization($organizationId);
+ }
+ $oldOrganizationId = $this->getOrganizationId();
+
+ if ($organizationId != $oldOrganizationId) {
+ $this->_setVar('user_organization_id', $organizationId);
+
+ // Depreciation warning: the settings will be removed in
+ // version 1.6 at the latest.
+ $this->_setVar('user_organization_name', $organization->getName());
+ $this->_setVar('user_style', $organization->getStyle());
+ // End depreciation warning
+
+ if ($this->isCurrentUser()) {
+ // Now update the requestcache to change the oldOrgId to the new orgId
+ // Don't do it when the oldOrgId doesn't match
+ $requestCache = $this->session->requestCache;
+
+ //Create the list of request cache keys that match an organization ID (to be extended)
+ $possibleOrgIds = array(
+ 'gr2o_id_organization',
+ 'gto_id_organization');
+
+ foreach ($requestCache as $key => $value) {
+ if (is_array($value)) {
+ foreach ($value as $paramKey => $paramValue) {
+ if (in_array($paramKey, $possibleOrgIds)) {
+ if ($paramValue == $oldOrganizationId) {
+ $requestCache[$key][$paramKey] = $organizationId;
+ }
+ }
+ }
+ }
+ }
+ $this->session->requestCache = $requestCache;
+ }
+ }
+
+ if (! Gems_Cookies::setOrganization($organizationId, $this->basepath->getBasePath())) {
+ throw new Exception($this->_('Cookies must be enabled for this site.'));
+ }
+
+ return $this;
+ }
+
/**
* Set the password, if allowed for this user type.
*
Modified: trunk/library/classes/Gems/User/UserLoader.php
===================================================================
--- trunk/library/classes/Gems/User/UserLoader.php 2011-11-23 18:52:36 UTC (rev 278)
+++ trunk/library/classes/Gems/User/UserLoader.php 2011-11-24 11:11:14 UTC (rev 279)
@@ -299,7 +299,7 @@
{
$checker = $this->_getClass('passwordChecker');
- return $checker->reportPasswordWeakness($user, $password);
+ return $user->reportPasswordWeakness($password);
}
/**
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|