00001 <?php
00002
00015
00016
00017 import('form.Form');
00018
00019 class ChangePasswordForm extends Form {
00020
00024 function ChangePasswordForm() {
00025 parent::Form('user/changePassword.tpl');
00026 $user =& Request::getUser();
00027 $site =& Request::getSite();
00028
00029
00030 $this->addCheck(new FormValidatorCustom($this, 'oldPassword', 'required', 'user.profile.form.oldPasswordInvalid', create_function('$password,$username', 'return Validation::checkCredentials($username,$password);'), array($user->getUsername())));
00031 $this->addCheck(new FormValidatorLength($this, 'password', 'required', 'user.account.form.passwordLengthTooShort', '>=', $site->getMinPasswordLength()));
00032 $this->addCheck(new FormValidator($this, 'password', 'required', 'user.profile.form.newPasswordRequired'));
00033 $this->addCheck(new FormValidatorCustom($this, 'password', 'required', 'user.account.form.passwordsDoNotMatch', create_function('$password,$form', 'return $password == $form->getData(\'password2\');'), array(&$this)));
00034 $this->addCheck(new FormValidatorPost($this));
00035 }
00036
00040 function display() {
00041 $user =& Request::getUser();
00042 $templateMgr =& TemplateManager::getManager();
00043 $site =& Request::getSite();
00044 $templateMgr->assign('minPasswordLength', $site->getMinPasswordLength());
00045 $templateMgr->assign('username', $user->getUsername());
00046 parent::display();
00047 }
00048
00052 function readInputData() {
00053 $this->readUserVars(array('oldPassword', 'password', 'password2'));
00054 }
00055
00059 function execute() {
00060 $user =& Request::getUser();
00061
00062 if ($user->getAuthId()) {
00063 $authDao =& DAORegistry::getDAO('AuthSourceDAO');
00064 $auth =& $authDao->getPlugin($user->getAuthId());
00065 }
00066
00067 if (isset($auth)) {
00068 $auth->doSetUserPassword($user->getUsername(), $this->getData('password'));
00069 $user->setPassword(Validation::encryptCredentials($user->getId(), Validation::generatePassword()));
00070 } else {
00071 $user->setPassword(Validation::encryptCredentials($user->getUsername(), $this->getData('password')));
00072 }
00073
00074 $userDao =& DAORegistry::getDAO('UserDAO');
00075 $userDao->updateObject($user);
00076 }
00077 }
00078
00079 ?>