00001 <?php
00002
00016 import('lib.pkp.classes.form.Form');
00017
00018 class ChangePasswordForm extends Form {
00019
00021 var $_user;
00022
00024 var $_site;
00025
00029 function ChangePasswordForm($user, $site) {
00030 parent::Form('user/changePassword.tpl');
00031
00032 $this->_user =& $user;
00033 $this->_site =& $site;
00034
00035
00036 $this->addCheck(new FormValidatorCustom($this, 'oldPassword', 'required', 'user.profile.form.oldPasswordInvalid', create_function('$password,$username', 'return Validation::checkCredentials($username,$password);'), array($user->getUsername())));
00037 $this->addCheck(new FormValidatorLength($this, 'password', 'required', 'user.register.form.passwordLengthTooShort', '>=', $site->getMinPasswordLength()));
00038 $this->addCheck(new FormValidator($this, 'password', 'required', 'user.profile.form.newPasswordRequired'));
00039 $this->addCheck(new FormValidatorCustom($this, 'password', 'required', 'user.register.form.passwordsDoNotMatch', create_function('$password,$form', 'return $password == $form->getData(\'password2\');'), array(&$this)));
00040 $this->addCheck(new FormValidatorCustom($this, 'password', 'required', 'user.profile.form.passwordSameAsOld', create_function('$password,$form', 'return $password != $form->getData(\'oldPassword\');'), array(&$this)));
00041
00042 $this->addCheck(new FormValidatorPost($this));
00043 }
00044
00048 function getUser() {
00049 return $this->_user;
00050 }
00051
00055 function getSite() {
00056 return $this->_site;
00057 }
00058
00062 function display() {
00063 $user =& $this->getUser();
00064 $templateMgr =& TemplateManager::getManager();
00065 $site =& $this->getSite();
00066 $templateMgr->assign('minPasswordLength', $site->getMinPasswordLength());
00067 $templateMgr->assign('username', $user->getUsername());
00068 parent::display();
00069 }
00070
00074 function readInputData() {
00075 $this->readUserVars(array('oldPassword', 'password', 'password2'));
00076 }
00077
00081 function execute() {
00082 $user =& $this->getUser();
00083
00084 if ($user->getAuthId()) {
00085 $authDao =& DAORegistry::getDAO('AuthSourceDAO');
00086 $auth =& $authDao->getPlugin($user->getAuthId());
00087 }
00088
00089 if (isset($auth)) {
00090 $auth->doSetUserPassword($user->getUsername(), $this->getData('password'));
00091 $user->setPassword(Validation::encryptCredentials($user->getId(), Validation::generatePassword()));
00092 } else {
00093 $user->setPassword(Validation::encryptCredentials($user->getUsername(), $this->getData('password')));
00094 }
00095
00096 $userDao =& DAORegistry::getDAO('UserDAO');
00097 $userDao->updateObject($user);
00098 }
00099 }
00100
00101 ?>