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