Open Monograph Press  1.1
 All Classes Namespaces Functions Variables Groups Pages
LoginChangePasswordForm.inc.php
1 <?php
2 
16 import('lib.pkp.classes.form.Form');
17 
19 
23  function LoginChangePasswordForm($site) {
24  parent::Form('user/loginChangePassword.tpl');
25 
26  // Validation checks for this form
27  $this->addCheck(new FormValidatorCustom($this, 'oldPassword', 'required', 'user.profile.form.oldPasswordInvalid', create_function('$password,$form', 'return Validation::checkCredentials($form->getData(\'username\'),$password);'), array($this)));
28  $this->addCheck(new FormValidatorLength($this, 'password', 'required', 'user.register.form.passwordLengthTooShort', '>=', $site->getMinPasswordLength()));
29  $this->addCheck(new FormValidator($this, 'password', 'required', 'user.profile.form.newPasswordRequired'));
30  $this->addCheck(new FormValidatorCustom($this, 'password', 'required', 'user.register.form.passwordsDoNotMatch', create_function('$password,$form', 'return $password == $form->getData(\'password2\');'), array($this)));
31  $this->addCheck(new FormValidatorPost($this));
32  }
33 
37  function display($request) {
38  $templateMgr = TemplateManager::getManager($request);
39  $site = $request->getSite();
40  $templateMgr->assign('minPasswordLength', $site->getMinPasswordLength());
41  parent::display();
42  }
43 
47  function readInputData() {
48  $this->readUserVars(array('username', 'oldPassword', 'password', 'password2'));
49  }
50 
55  function execute() {
56  $userDao = DAORegistry::getDAO('UserDAO');
57  $user = $userDao->getByUsername($this->getData('username'), false);
58  if ($user != null) {
59  if ($user->getAuthId()) {
60  $authDao = DAORegistry::getDAO('AuthSourceDAO');
61  $auth = $authDao->getPlugin($user->getAuthId());
62  }
63 
64  if (isset($auth)) {
65  $auth->doSetUserPassword($user->getUsername(), $this->getData('password'));
66  $user->setPassword(Validation::encryptCredentials($user->getId(), Validation::generatePassword())); // Used for PW reset hash only
67  } else {
68  $user->setPassword(Validation::encryptCredentials($user->getUsername(), $this->getData('password')));
69  }
70 
71  $user->setMustChangePassword(0);
72  $userDao->updateObject($user);
73  return true;
74 
75  } else {
76  return false;
77  }
78  }
79 }
80 
81 ?>
static & getDAO($name, $dbconn=null)
addCheck($formValidator)
Definition: Form.inc.php:396
Form validation check with a custom user function performing the validation check.
Form validation check to make sure the form is POSTed.
readUserVars($vars)
Definition: Form.inc.php:364
Class defining basic operations for handling HTML forms.
Definition: Form.inc.php:47
Form validation check that checks if a field&#39;s length meets certain requirements. ...
getData($key)
Definition: Form.inc.php:210
static generatePassword($length=8)
Form to change a user&#39;s password in order to login.
static encryptCredentials($username, $password, $encryption=false)
Class to represent a form validation check.