00001 <?php
00002
00015
00016
00017
00018 import('form.Form');
00019
00020 class LoginChangePasswordForm extends Form {
00021
00025 function LoginChangePasswordForm() {
00026 parent::Form('user/loginChangePassword.tpl');
00027 $site = &Request::getSite();
00028
00029
00030 $this->addCheck(new FormValidatorCustom($this, 'oldPassword', 'required', 'user.profile.form.oldPasswordInvalid', create_function('$password,$form', 'return Validation::checkCredentials($form->getData(\'username\'),$password);'), array(&$this)));
00031 $this->addCheck(new FormValidatorLength($this, 'password', 'required', 'user.register.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.register.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 $templateMgr = &TemplateManager::getManager();
00042 $site = &Request::getSite();
00043 $templateMgr->assign('minPasswordLength', $site->getMinPasswordLength());
00044 parent::display();
00045 }
00046
00050 function readInputData() {
00051 $this->readUserVars(array('username', 'oldPassword', 'password', 'password2'));
00052 }
00053
00058 function execute() {
00059 $userDao = &DAORegistry::getDAO('UserDAO');
00060 $user = &$userDao->getUserByUsername($this->getData('username'), false);
00061 if ($user != null) {
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->getUserId(), Validation::generatePassword()));
00070 } else {
00071 $user->setPassword(Validation::encryptCredentials($user->getUsername(), $this->getData('password')));
00072 }
00073
00074 $user->setMustChangePassword(0);
00075 $userDao->updateUser($user);
00076 return true;
00077
00078 } else {
00079 return false;
00080 }
00081 }
00082
00083 }
00084
00085 ?>