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