|
From: <gem...@li...> - 2011-11-15 10:29:50
|
Revision: 217
http://gemstracker.svn.sourceforge.net/gemstracker/?rev=217&view=rev
Author: mennodekker
Date: 2011-11-15 10:29:43 +0000 (Tue, 15 Nov 2011)
Log Message:
-----------
And finally remove the checkpassword, and obsolete validators
Modified Paths:
--------------
trunk/library/classes/Gems/Default/IndexAction.php
trunk/library/classes/Gems/Default/OptionAction.php
trunk/library/classes/Gems/User/NoLoginDefinition.php
trunk/library/classes/Gems/User/OldStaffUserDefinition.php
trunk/library/classes/Gems/User/ProjectUserDefinition.php
trunk/library/classes/Gems/User/StaffUserDefinition.php
trunk/library/classes/Gems/User/User.php
trunk/library/classes/Gems/User/UserDefinitionInterface.php
trunk/library/classes/Gems/User/UserLoader.php
Removed Paths:
-------------
trunk/library/classes/Gems/User/LoginPasswordValidator.php
trunk/library/classes/Gems/User/UserPasswordValidator.php
Modified: trunk/library/classes/Gems/Default/IndexAction.php
===================================================================
--- trunk/library/classes/Gems/Default/IndexAction.php 2011-11-15 09:44:12 UTC (rev 216)
+++ trunk/library/classes/Gems/Default/IndexAction.php 2011-11-15 10:29:43 UTC (rev 217)
@@ -184,7 +184,6 @@
$element->setAttrib('size', 10);
$element->setAttrib('maxlength', 20);
$element->setRequired(true);
- //$element->addValidator(new Gems_User_LoginPasswordValidator($this->loader->getUserLoader(), 'userlogin', 'organization', $this->translate));
return $element;
}
Modified: trunk/library/classes/Gems/Default/OptionAction.php
===================================================================
--- trunk/library/classes/Gems/Default/OptionAction.php 2011-11-15 09:44:12 UTC (rev 216)
+++ trunk/library/classes/Gems/Default/OptionAction.php 2011-11-15 10:29:43 UTC (rev 217)
@@ -98,7 +98,6 @@
$element->setAttrib('maxlength', 20);
$element->setRenderPassword(true);
$element->setRequired(true);
- $element->addValidator(new Gems_User_UserPasswordValidator($user, $this->translate));
$form->addElement($element);
}
@@ -131,16 +130,26 @@
/****************
* Process form *
****************/
- if ($this->_request->isPost() && $form->isValid($_POST)) {
- $user->setPassword($_POST['new_password']);
+ if ($this->_request->isPost()) {
+ if ($form->isValid($_POST)) {
+ $authResult = $user->authenticate(array('userlogin' => $user->getLoginName(),
+ 'password' => $_POST['old_password'],
+ 'organization' =>$user->getOrganizationId()));
+ if ($authResult->isValid()) {
+ $user->setPassword($_POST['new_password']);
- $this->addMessage($this->_('New password is active.'));
- $this->_reroute(array($this->getRequest()->getActionKey() => 'edit'));
+ $this->addMessage($this->_('New password is active.'));
+ $this->_reroute(array($this->getRequest()->getActionKey() => 'edit'));
+ } else {
+ if (isset($_POST['old_password'])) {
+ if ($_POST['old_password'] === strtoupper($_POST['old_password'])) {
+ $this->addMessage($this->_('Caps Lock seems to be on!'));
+ } else {
+ $errors = $authResult->getMessages();
+ $this->addMessage($errors);
- } else {
- if (isset($_POST['old_password'])) {
- if ($_POST['old_password'] === strtoupper($_POST['old_password'])) {
- $this->addMessage($this->_('Caps Lock seems to be on!'));
+ }
+ }
}
}
$form->populate($_POST);
Deleted: trunk/library/classes/Gems/User/LoginPasswordValidator.php
===================================================================
--- trunk/library/classes/Gems/User/LoginPasswordValidator.php 2011-11-15 09:44:12 UTC (rev 216)
+++ trunk/library/classes/Gems/User/LoginPasswordValidator.php 2011-11-15 10:29:43 UTC (rev 217)
@@ -1,140 +0,0 @@
-<?php
-
-/**
- * Copyright (c) 2011, Erasmus MC
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * * Neither the name of Erasmus MC nor the
- * names of its contributors may be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY
- * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- *
- * @package Gems
- * @subpackage User
- * @author Matijs de Jong <mj...@ma...>
- * @copyright Copyright (c) 2011 Erasmus MC
- * @license New BSD License
- * @version $Id: Sample.php 203 2011-07-07 12:51:32Z matijs $
- */
-
-/**
- *
- *
- * @package Gems
- * @subpackage User
- * @copyright Copyright (c) 2011 Erasmus MC
- * @license New BSD License
- * @since Class available since version 1.5
- */
-class Gems_User_LoginPasswordValidator implements Zend_Validate_Interface
-{
- /**
- * Field containing user login
- *
- * @var string
- */
- private $_loginField = 'userlogin';
-
- /**
- * Field containing organization id.
- *
- * @var string
- */
- private $_organizationField = 'organization';
-
- /**
- *
- * @var Gems_User_UserLoader
- */
- private $_userLoader;
-
- /**
- *
- * @var Zend_Translate
- */
- private $_translate;
-
- /**
- *
- * @var boolean
- */
- private $_valid = false;
-
- /**
- *
- * @param Gems_User_UserLoader $loader
- * @param type $loginField Field in form containing login name
- * @param string $organizationField Field in form containing organization
- * @param Zend_Translate $translate Optional translator
- */
- public function __construct(Gems_User_UserLoader $loader, $loginField, $organizationField, Zend_Translate $translate = null)
- {
- $this->_userLoader = $loader;
- $this->_loginField = $loginField;
- $this->_organizationField = $organizationField;
- $this->_translate = $translate ? $translate : new MUtil_Translate_Adapter_Potemkin();
- }
-
- /**
- * Returns true if and only if $value meets the validation requirements
- *
- * If $value fails validation, then this method returns false, and
- * getMessages() will return an array of messages that explain why the
- * validation failed.
- *
- * @param mixed $value
- * @param mixed $content
- * @return boolean
- * @throws Zend_Validate_Exception If validation of $value is impossible
- */
- public function isValid($value, $context = array())
- {
- if (isset($context[$this->_loginField], $context[$this->_organizationField])) {
- $this->_valid = $this->_userLoader->checkPassword($context[$this->_loginField], $context[$this->_organizationField], $value);
- } else {
- $this->_valid = false;
- }
-
- return $this->_valid;
- }
-
- /**
- * Returns an array of messages that explain why the most recent isValid()
- * call returned false. The array keys are validation failure message identifiers,
- * and the array values are the corresponding human-readable message strings.
- *
- * If isValid() was never called or if the most recent isValid() call
- * returned true, then this method returns an empty array.
- *
- * @return array
- */
- public function getMessages()
- {
- if ($this->_valid) {
- return array();
-
- } else {
- return array($this->_translate->_('Combination of username password not found.'));
- }
-
-
- }
-}
Modified: trunk/library/classes/Gems/User/NoLoginDefinition.php
===================================================================
--- trunk/library/classes/Gems/User/NoLoginDefinition.php 2011-11-15 09:44:12 UTC (rev 216)
+++ trunk/library/classes/Gems/User/NoLoginDefinition.php 2011-11-15 10:29:43 UTC (rev 217)
@@ -46,18 +46,16 @@
*/
class Gems_User_NoLoginDefinition extends Gems_User_UserDefinitionAbstract
{
- /**
- * Checks the password for the specified $login_name and $organization.
- *
- * @param string $login_name
- * @param int $organization
- * @param string $password
- * @return boolean True if the password is correct.
- */
- public function checkPassword($login_name, $organization, $password)
- {
+ private function alwaysFalse($params) {
+ $result = new Zend_Auth_Result(Zend_Auth_Result::FAILURE, $params['userlogin']);
return false;
}
+
+ public function getAuthAdapter($formValues)
+ {
+ $adapter = new Gems_Auth_Adapter_Callback(array(get_class(),'alwaysFalse'), $formValues['userlogin'], $formValues);
+ return $adapter;
+ }
/**
* Returns a user object, that may be empty if the user is unknown.
@@ -74,15 +72,4 @@
//'user_organization_id' => 0, //REMOVED AS IT BREAKS STORING LAST ORGANIZATION
);
}
-
- public function getAuthAdapter($formValues)
- {
- $adapter = new Gems_Auth_Adapter_Callback(array(get_class(),'alwaysFalse'), $formValues['userlogin'], $formValues);
- return $adapter;
- }
-
- private function alwaysFalse($params) {
- $result = new Zend_Auth_Result(Zend_Auth_Result::FAILURE, $params['userlogin']);
- return false;
- }
}
Modified: trunk/library/classes/Gems/User/OldStaffUserDefinition.php
===================================================================
--- trunk/library/classes/Gems/User/OldStaffUserDefinition.php 2011-11-15 09:44:12 UTC (rev 216)
+++ trunk/library/classes/Gems/User/OldStaffUserDefinition.php 2011-11-15 10:29:43 UTC (rev 217)
@@ -58,23 +58,22 @@
* @var Gems_Project_ProjectSettings
*/
protected $project;
-
+
/**
- * Checks the password for the specified $login_name and $organization.
+ * Perform UserDefinition specific post-login logic
*
- * @param string $login_name
- * @param int $organization
- * @param string $password
- * @return boolean True if the password is correct.
+ * @param Zend_Auth_Result $authResult
+ * @return void
*/
- public function checkPassword($login_name, $organization, $password)
+ public function afterLogin($authResult, $formValues)
{
- $pwd_hash = $this->hashPassword($password);
+ if ($authResult->isValid()) {
+ $login_name = $formValues['userlogin'];
+ $organization = $formValues['organization'];
+ $password = $formValues['password'];
+ $userData = $this->getUserData($formValues['userlogin'], $formValues['organization']);
+ $staff_id = $userData['user_id'];
- $sql = "SELECT gsf_id_user FROM gems__staff WHERE gsf_active = 1 AND gsf_login = ? AND gsf_id_organization = ? AND gsf_password = ?";
-
- if ($staff_id = $this->db->fetchOne($sql, array($login_name, $organization, $pwd_hash))) {
-
$sql = 'SELECT gul_id_user FROM gems__user_logins WHERE gul_can_login = 1 AND gul_login = ? AND gul_id_organization = ?';
try {
@@ -115,10 +114,23 @@
// MUtil_Echo::r($e);
}
-
- return true;
}
+ }
+ public function getAuthAdapter($formValues)
+ {
+ $adapter = new Zend_Auth_Adapter_DbTable(null, 'gems__staff', 'gsf_login', 'gsf_password');
+
+ $pwd_hash = $this->hashPassword($formValues['password']);
+
+ $select = $adapter->getDbSelect();
+ $select->where('gsf_active = 1')
+ ->where('gsf_id_organization = ?', $formValues['organization']);
+
+ $adapter->setIdentity($formValues['userlogin'])
+ ->setCredential($pwd_hash);
+
+ return $adapter;
}
/**
@@ -178,78 +190,4 @@
{
return md5($password);
}
-
- public function getAuthAdapter($formValues)
- {
- $adapter = new Zend_Auth_Adapter_DbTable(null, 'gems__staff', 'gsf_login', 'gsf_password');
-
- $pwd_hash = $this->hashPassword($formValues['password']);
-
- $select = $adapter->getDbSelect();
- $select->where('gsf_active = 1')
- ->where('gsf_id_organization = ?', $formValues['organization']);
-
- $adapter->setIdentity($formValues['userlogin'])
- ->setCredential($pwd_hash);
-
- return $adapter;
- }
-
- /**
- * Perform UserDefinition specific post-login logic
- *
- * @param Zend_Auth_Result $authResult
- * @return void
- */
- public function afterLogin($authResult, $formValues)
- {
- if ($authResult->isValid()) {
- $login_name = $formValues['userlogin'];
- $organization = $formValues['organization'];
- $password = $formValues['password'];
- $userData = $this->getUserData($formValues['userlogin'], $formValues['organization']);
- $staff_id = $userData['user_id'];
-
- $sql = 'SELECT gul_id_user FROM gems__user_logins WHERE gul_can_login = 1 AND gul_login = ? AND gul_id_organization = ?';
-
- try {
- $user_id = $this->db->fetchOne($sql, array($login_name, $organization));
-
- $currentTimestamp = new Zend_Db_Expr('CURRENT_TIMESTAMP');
-
- // Move to USER_STAFF
- $values['gup_id_user'] = $user_id;
- $values['gup_password'] = $this->project->getValueHash($password);
- $values['gup_reset_key'] = null;
- $values['gup_reset_requested'] = null;
- $values['gup_reset_required'] = 0;
- $values['gup_changed'] = $currentTimestamp ;
- $values['gup_changed_by'] = $staff_id;
- $values['gup_created'] = $currentTimestamp ;
- $values['gup_created_by'] = $staff_id;
-
- $this->db->insert('gems__user_passwords', $values);
-
- // Update user class
- $values = array();
- $values['gul_user_class'] = Gems_User_UserLoader::USER_STAFF;
- $values['gul_changed'] = $currentTimestamp ;
- $values['gul_changed_by'] = $staff_id;
- $this->db->update('gems__user_logins', $values, $this->db->quoteInto('gul_id_user = ?', $user_id));
-
- // Remove old password
- $values = array();
- $values['gsf_password'] = null;
- $values['gsf_changed'] = $currentTimestamp ;
- $values['gsf_changed_by'] = $user_id;
-
- $this->db->update('gems__staff', $values, $this->db->quoteInto('gsf_id_user = ?', $staff_id));
-
- } catch (Zend_Db_Exception $e) {
- // Fall through as this does not work if the database upgrade did not run
- // MUtil_Echo::r($e);
-
- }
- }
- }
-}
+}
\ No newline at end of file
Modified: trunk/library/classes/Gems/User/ProjectUserDefinition.php
===================================================================
--- trunk/library/classes/Gems/User/ProjectUserDefinition.php 2011-11-15 09:44:12 UTC (rev 216)
+++ trunk/library/classes/Gems/User/ProjectUserDefinition.php 2011-11-15 10:29:43 UTC (rev 217)
@@ -52,17 +52,10 @@
*/
protected $project;
- /**
- * Checks the password for the specified $login_name and $organization.
- *
- * @param string $login_name
- * @param int $organization
- * @param string $password
- * @return boolean True if the password is correct.
- */
- public function checkPassword($login_name, $organization, $password)
+ public function getAuthAdapter($formValues)
{
- return $this->project->checkSuperAdminPassword($password);
+ $adapter = new Gems_Auth_Adapter_Callback(array($this->project,'checkSuperAdminPassword'), $formValues['userlogin'], $formValues['password']);
+ return $adapter;
}
/**
@@ -86,10 +79,4 @@
'allowedOrgs' => array($organization => 'SUPER ADMIN')
);
}
-
- public function getAuthAdapter($formValues)
- {
- $adapter = new Gems_Auth_Adapter_Callback(array($this->project,'checkSuperAdminPassword'), $formValues['userlogin'], $formValues['password']);
- return $adapter;
- }
-}
+}
\ No newline at end of file
Modified: trunk/library/classes/Gems/User/StaffUserDefinition.php
===================================================================
--- trunk/library/classes/Gems/User/StaffUserDefinition.php 2011-11-15 09:44:12 UTC (rev 216)
+++ trunk/library/classes/Gems/User/StaffUserDefinition.php 2011-11-15 10:29:43 UTC (rev 217)
@@ -92,29 +92,6 @@
}
/**
- * Checks the password for the specified $login_name and $organization.
- *
- * @param string $login_name
- * @param int $organization
- * @param string $password
- * @return boolean True if the password is correct.
- */
- public function checkPassword($login_name, $organization, $password)
- {
- $pwd_hash = $this->hashPassword($password);
-
- $sql = "SELECT gup_password
- FROM gems__user_passwords INNER JOIN gems__user_logins ON gup_id_user = gul_id_user
- WHERE gul_can_login = 1 AND gul_login = ? AND gul_id_organization = ?";
-
- $db_pwd = $this->db->fetchOne($sql, array($login_name, $organization));
-
- // MUtil_Echo::track($password, $pwd_hash, $db_pwd);
-
- return ($pwd_hash == $db_pwd);
- }
-
- /**
* Check whether a reset key is really linked to a user.
*
* @param Gems_User_User $user The user the key was created for (hopefully).
@@ -136,6 +113,23 @@
return false;
}
+ public function getAuthAdapter($formValues)
+ {
+ $adapter = new Zend_Auth_Adapter_DbTable($this->db, 'gems__user_passwords', 'gul_login', 'gup_password');
+
+ $pwd_hash = $this->hashPassword($formValues['password']);
+
+ $select = $adapter->getDbSelect();
+ $select->join('gems__user_logins', 'gup_id_user = gul_id_user', array())
+ ->where('gul_can_login = 1')
+ ->where('gul_id_organization = ?', $formValues['organization']);
+
+ $adapter->setIdentity($formValues['userlogin'])
+ ->setCredential($pwd_hash);
+
+ return $adapter;
+ }
+
/**
* Return a password reset key
*
@@ -252,21 +246,4 @@
return $this;
}
-
- public function getAuthAdapter($formValues)
- {
- $adapter = new Zend_Auth_Adapter_DbTable($this->db, 'gems__user_passwords', 'gul_login', 'gup_password');
-
- $pwd_hash = $this->hashPassword($formValues['password']);
-
- $select = $adapter->getDbSelect();
- $select->join('gems__user_logins', 'gup_id_user = gul_id_user', array())
- ->where('gul_can_login = 1')
- ->where('gul_id_organization = ?', $formValues['organization']);
-
- $adapter->setIdentity($formValues['userlogin'])
- ->setCredential($pwd_hash);
-
- return $adapter;
- }
-}
+}
\ No newline at end of file
Modified: trunk/library/classes/Gems/User/User.php
===================================================================
--- trunk/library/classes/Gems/User/User.php 2011-11-15 09:44:12 UTC (rev 216)
+++ trunk/library/classes/Gems/User/User.php 2011-11-15 10:29:43 UTC (rev 217)
@@ -227,17 +227,6 @@
}
/**
- * Checks the password for this user and handle the login security.
- *
- * @param string $password
- * @return boolean True if the password is correct.
- */
- public function checkPassword($password)
- {
- return $this->userLoader->checkPassword($this->getLoginName(), $this->getOrganizationId(), $password);
- }
-
- /**
* Check whether a reset key is really linked to this user.
*
* @param string The key
Modified: trunk/library/classes/Gems/User/UserDefinitionInterface.php
===================================================================
--- trunk/library/classes/Gems/User/UserDefinitionInterface.php 2011-11-15 09:44:12 UTC (rev 216)
+++ trunk/library/classes/Gems/User/UserDefinitionInterface.php 2011-11-15 10:29:43 UTC (rev 217)
@@ -69,16 +69,6 @@
public function canSetPassword(Gems_User_User $user = null);
/**
- * Checks the password for the specified $login_name and $organization.
- *
- * @param string $login_name
- * @param int $organization
- * @param string $password
- * @return boolean True if the password is correct.
- */
- public function checkPassword($login_name, $organization, $password);
-
- /**
* Check whether a reset key is really linked to a user.
*
* @param Gems_User_User $user The user the key was created for (hopefully).
Modified: trunk/library/classes/Gems/User/UserLoader.php
===================================================================
--- trunk/library/classes/Gems/User/UserLoader.php 2011-11-15 09:44:12 UTC (rev 216)
+++ trunk/library/classes/Gems/User/UserLoader.php 2011-11-15 10:29:43 UTC (rev 217)
@@ -114,76 +114,6 @@
protected static $organizationStore;
/**
- * Checks the password for the specified $login_name and $organization and
- * handles the login security.
- *
- * @param string $login_name
- * @param int $organization
- * @param string $password
- * @return boolean True if the password is correct.
- */
- public function checkPassword($login_name, $organization, $password)
- {
- // MUtil_Echo::track($login_name, $organization, $password);
- $defName = $this->getUserClassName($login_name, $organization);
- $definition = $this->_getClass($defName);
-
- $success = $definition->checkPassword($login_name, $organization, $password);
-
- try {
- $sql = "SELECT gula_failed_logins, gula_last_failed FROM gems__user_login_attemps WHERE gula_login = ? AND gula_id_organization = ?";
- $values = $this->db->fetchRow($sql, array($login_name, $organization));
-
- if (! $values) {
- $values = array();
- $values['gula_login'] = $login_name;
- $values['gula_id_organization'] = $organization;
- $values['gula_failed_logins'] = 0;
- $values['gula_last_failed'] = null;
- }
- if ($success) {
- $values['gula_failed_logins'] = 0;
- $values['gula_last_failed'] = null;
- } else {
- if ($values['gula_failed_logins']) {
- // Get the datetime
- $last = new MUtil_Date($values['gula_last_failed'], Zend_Date::ISO_8601);
-
- // How long to wait until we can ignore the previous failed attempt
- $delay = pow($values['gula_failed_logins'], $this->project->getAccountDelayFactor());
-
- if (abs($last->diffSeconds()) <= $delay) {
- // Response gets slowly slower
- sleep(min($values['gula_failed_logins'], 10));
-
- $values['gula_failed_logins'] += 1;
-
- } else {
- $values['gula_failed_logins'] = 1;
- }
- } else {
- $values['gula_failed_logins'] = 1;
- }
- $values['gula_failed_logins'] = max($values['gula_failed_logins'], 1);
- $values['gula_last_failed'] = new Zend_Db_Expr('CURRENT_TIMESTAMP');
- }
-
- if (isset($values['gula_login'])) {
- $this->db->insert('gems__user_login_attemps', $values);
- } else {
- $where = $this->db->quoteInto('gula_login = ? AND ', $login_name);
- $where .= $this->db->quoteInto('gula_id_organization = ?', $organization);
- $this->db->update('gems__user_login_attemps', $values, $where);
- }
-
- } catch (Zend_Db_Exception $e) {
- // Fall through as this does not work if the database upgrade did not run
- // MUtil_Echo::r($e);
- }
- return $success;
- }
-
- /**
* Should be called after answering the request to allow the Target
* to check if all required registry values have been set correctly.
*
Deleted: trunk/library/classes/Gems/User/UserPasswordValidator.php
===================================================================
--- trunk/library/classes/Gems/User/UserPasswordValidator.php 2011-11-15 09:44:12 UTC (rev 216)
+++ trunk/library/classes/Gems/User/UserPasswordValidator.php 2011-11-15 10:29:43 UTC (rev 217)
@@ -1,118 +0,0 @@
-<?php
-
-/**
- * Copyright (c) 2011, Erasmus MC
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * * Neither the name of Erasmus MC nor the
- * names of its contributors may be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY
- * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- *
- * @package Gems
- * @subpackage User
- * @author Matijs de Jong <mj...@ma...>
- * @copyright Copyright (c) 2011 Erasmus MC
- * @license New BSD License
- * @version $Id: Sample.php 203 2011-07-07 12:51:32Z matijs $
- */
-
-/**
- *
- *
- * @package Gems
- * @subpackage User
- * @copyright Copyright (c) 2011 Erasmus MC
- * @license New BSD License
- * @since Class available since version 1.5
- */
-class Gems_User_UserPasswordValidator implements Zend_Validate_Interface
-{
- /**
- *
- * @var Gems_User_User
- */
- private $_user;
-
- /**
- *
- * @var Zend_Translate
- */
- private $_translate;
-
- /**
- *
- * @var boolean
- */
- private $_valid = false;
-
- /**
- *
- * @param Gems_User_User $user The user to check
- * @param Zend_Translate $translate Optional translator
- */
- public function __construct(Gems_User_User $user, Zend_Translate $translate = null)
- {
- $this->_user = $user;
- $this->_translate = $translate ? $translate : new MUtil_Translate_Adapter_Potemkin();
- }
-
- /**
- * Returns true if and only if $value meets the validation requirements
- *
- * If $value fails validation, then this method returns false, and
- * getMessages() will return an array of messages that explain why the
- * validation failed.
- *
- * @param mixed $value
- * @param mixed $content
- * @return boolean
- * @throws Zend_Validate_Exception If validation of $value is impossible
- */
- public function isValid($value, $context = array())
- {
- $this->_valid = $this->_user->checkPassword($value);
-
- return $this->_valid;
- }
-
- /**
- * Returns an array of messages that explain why the most recent isValid()
- * call returned false. The array keys are validation failure message identifiers,
- * and the array values are the corresponding human-readable message strings.
- *
- * If isValid() was never called or if the most recent isValid() call
- * returned true, then this method returns an empty array.
- *
- * @return array
- */
- public function getMessages()
- {
- if ($this->_valid) {
- return array();
-
- } else {
- return array($this->_translate->_('Wrong password.'));
- }
-
-
- }
-}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|