|
From: <gem...@li...> - 2012-04-08 13:41:26
|
Revision: 607
http://gemstracker.svn.sourceforge.net/gemstracker/?rev=607&view=rev
Author: matijsdejong
Date: 2012-04-08 13:41:19 +0000 (Sun, 08 Apr 2012)
Log Message:
-----------
Adapted User object so the user can never login to an organization url of an organization where he/she has no access
ChangePasswordForm.php now uses the same default sizes for password input as the other user forms
Simplified displayResetForm parameters
Modified Paths:
--------------
trunk/library/classes/Gems/Default/IndexAction.php
trunk/library/classes/Gems/Default/OptionAction.php
trunk/library/classes/Gems/User/Form/ChangePasswordForm.php
trunk/library/classes/Gems/User/User.php
Modified: trunk/library/classes/Gems/Default/IndexAction.php
===================================================================
--- trunk/library/classes/Gems/Default/IndexAction.php 2012-04-06 18:15:38 UTC (rev 606)
+++ trunk/library/classes/Gems/Default/IndexAction.php 2012-04-08 13:41:19 UTC (rev 607)
@@ -146,11 +146,13 @@
* @param Gems_Form_AutoLoadFormAbstract $form Rset password or reset request form
* @param mixed $errors
*/
- protected function displayResetForm(Gems_Form_AutoLoadFormAbstract $form, $errors, Gems_User_User $user = null)
+ protected function displayResetForm(Gems_Form_AutoLoadFormAbstract $form, $errors)
{
- if ($form instanceof Gems_User_Form_ResetRequestForm) {
+ if ($form instanceof Gems_User_Validate_GetUserInterface) {
$user = $form->getUser();
+ }
+ if ($form instanceof Gems_User_Form_ResetRequestForm) {
$this->html->h3($this->_('Request password reset'));
$p = $this->html->pInfo();
@@ -162,7 +164,8 @@
$this->html->p($this->_('We will then send you an e-mail with a link. The link will bring you to a page where you can set a new password of your choice.'));
} elseif ($form instanceof Gems_User_Form_ChangePasswordForm) {
- $form->getUser()->getCurrentOrganization()->setAsCurrentOrganization();
+
+ $this->setCurrentOrganizationTo($user);
if ($user->hasPassword()) {
$this->html->h3($this->_('Execute password reset'));
$p = $this->html->pInfo($this->_('We received your password reset request.'));
@@ -179,7 +182,7 @@
$this->addMessage($errors);
}
- if ($user) {
+ if (isset($user)) {
$this->setCurrentOrganizationTo($user);
}
@@ -276,13 +279,12 @@
$errors = array();
$form = $this->createResetRequestForm();
$request = $this->getRequest();
- $user = null;
if ($key = $this->_getParam('key')) {
$user = $this->loader->getUserLoader()->getUserByResetKey($key);
if ($user->hasValidResetKey()) {
- $form = $user->getChangePasswordForm(array('askOld' => false, 'askCheck' => true));
+ $form = $user->getChangePasswordForm(array('askOld' => false, 'askCheck' => true, 'labelWidthFactor' => $this->labelWidthFactor));
} else {
if (! $request->isPost()) {
if ($user->hasPassword() || (! $user->isActive())) {
@@ -317,6 +319,7 @@
} elseif ($form instanceof Gems_User_Form_ChangePasswordForm) {
$this->addMessage($this->_('New password is active.'));
+ // User set before this form was initiated
$user->setAsCurrentUser();
$user->gotoStartPage($this->menu, $this->getRequest());
}
@@ -324,7 +327,7 @@
}
$form->populate($request->getParams());
- $this->displayResetForm($form, $errors, $user);
+ $this->displayResetForm($form, $errors);
}
/**
Modified: trunk/library/classes/Gems/Default/OptionAction.php
===================================================================
--- trunk/library/classes/Gems/Default/OptionAction.php 2012-04-06 18:15:38 UTC (rev 606)
+++ trunk/library/classes/Gems/Default/OptionAction.php 2012-04-08 13:41:19 UTC (rev 607)
@@ -85,7 +85,7 @@
/*************
* Make form *
*************/
- $form = $user->getChangePasswordForm(array('showReport' => false));
+ $form = $user->getChangePasswordForm(array('showReport' => false, 'useTableLayout' => true));
/****************
* Process form *
Modified: trunk/library/classes/Gems/User/Form/ChangePasswordForm.php
===================================================================
--- trunk/library/classes/Gems/User/Form/ChangePasswordForm.php 2012-04-06 18:15:38 UTC (rev 606)
+++ trunk/library/classes/Gems/User/Form/ChangePasswordForm.php 2012-04-08 13:41:19 UTC (rev 607)
@@ -44,7 +44,7 @@
* @license New BSD License
* @since Class available since version 1.5
*/
-class Gems_User_Form_ChangePasswordForm extends Gems_Form_AutoLoadFormAbstract
+class Gems_User_Form_ChangePasswordForm extends Gems_Form_AutoLoadFormAbstract implements Gems_User_Validate_GetUserInterface
{
/**
* The field name for the new password element.
@@ -132,7 +132,7 @@
*
* @var boolean
*/
- protected $useTableLayout = true;
+ protected $useTableLayout = false;
public function addButtons($links)
{
@@ -176,6 +176,21 @@
}
/**
+ * 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()
+ {
+ if ($this->translate && $this->user) {
+ return parent::checkRegistryRequestsAnswers();
+ } else {
+ return false;
+ }
+ }
+
+ /**
* Should a user specific check question be asked?
*
* @return boolean
@@ -218,8 +233,7 @@
// Field new password
$element = new Zend_Form_Element_Password($this->_newPasswordFieldName);
$element->setLabel($this->translate->_('New password'));
- $element->setAttrib('size', 10);
- $element->setAttrib('maxlength', 20);
+ $element->setAttrib('size', 40);
$element->setRequired(true);
$element->setRenderPassword(true);
$element->addValidator(new Gems_User_Validate_NewPasswordValidator($this->user));
@@ -247,8 +261,7 @@
// Field current password
$element = new Zend_Form_Element_Password($this->_oldPasswordFieldName);
$element->setLabel($this->translate->_('Current password'));
- $element->setAttrib('size', 10);
- $element->setAttrib('maxlength', 20);
+ $element->setAttrib('size', 40);
$element->setRenderPassword(true);
$element->setRequired(true);
$element->addValidator(new Gems_User_Validate_UserPasswordValidator($this->user, $this->translate->_('Wrong password.')));
@@ -272,8 +285,7 @@
// Field repeat password
$element = new Zend_Form_Element_Password($this->_repeatPasswordFieldName);
$element->setLabel($this->translate->_('Repeat password'));
- $element->setAttrib('size', 10);
- $element->setAttrib('maxlength', 20);
+ $element->setAttrib('size', 40);
$element->setRequired(true);
$element->setRenderPassword(true);
@@ -330,6 +342,16 @@
}
/**
+ * Returns a user
+ *
+ * @return Gems_User_User
+ */
+ public function getUser()
+ {
+ return $this->user;
+ }
+
+ /**
* Validate the form
*
* As it is better for translation utilities to set the labels etc. translated,
Modified: trunk/library/classes/Gems/User/User.php
===================================================================
--- trunk/library/classes/Gems/User/User.php 2012-04-06 18:15:38 UTC (rev 606)
+++ trunk/library/classes/Gems/User/User.php 2012-04-08 13:41:19 UTC (rev 607)
@@ -445,6 +445,27 @@
}
/**
+ * True when the current url is one where this user is allowed to login.
+ *
+ * If the url is a fixed organization url and the user is not allowed to
+ * access this organization, then this function returns false.
+ *
+ * @return boolean
+ */
+ public function canLoginHere()
+ {
+ if (! $this->_hasVar('can_login_here')) {
+ $this->_setVar('can_login_here', true);
+ if ($orgId = $this->userLoader->getOrganizationIdByUrl()) {
+ if (! $this->isAllowedOrganization($orgId)) {
+ $this->_setVar('can_login_here', false);;
+ }
+ }
+ }
+ return $this->_getVar('can_login_here');
+ }
+
+ /**
* Return true if a password reset key can be created.
*
* @return boolean
@@ -461,7 +482,7 @@
*/
public function canSetPassword()
{
- return $this->definition->canSetPassword();
+ return $this->isActive() && $this->definition->canSetPassword();
}
/**
@@ -472,7 +493,7 @@
*/
public function checkPasswordResetKey($key)
{
- return $this->definition->checkPasswordResetKey($this, $key);
+ return $this->isActive() && $this->definition->checkPasswordResetKey($this, $key);
}
/**
@@ -955,13 +976,13 @@
}
/**
- * True when the reset key is within it's timeframe
+ * True when the reset key is within it's timeframe and OK for the current organization
*
* @return boolean
*/
public function hasValidResetKey()
{
- return (boolean) $this->_getVar('user_resetkey_valid');
+ return (boolean) $this->isActive() && $this->_getVar('user_resetkey_valid');
}
/**
@@ -970,7 +991,7 @@
*/
public function isActive()
{
- return (boolean) $this->_getVar('user_active');
+ return (boolean) $this->canLoginHere() && $this->_getVar('user_active');
}
/**
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|