Open Monograph Press  1.1
 All Classes Namespaces Functions Variables Groups Pages
ChangePasswordForm.inc.php
1 <?php
2 
17 import('lib.pkp.classes.form.Form');
18 
19 class ChangePasswordForm extends Form {
20 
22  var $_user;
23 
25  var $_site;
26 
30  function ChangePasswordForm($user, $site) {
31  parent::Form('user/changePassword.tpl');
32 
33  $this->_user = $user;
34  $this->_site = $site;
35 
36  // Validation checks for this form
37  $this->addCheck(new FormValidatorCustom($this, 'oldPassword', 'required', 'user.profile.form.oldPasswordInvalid', create_function('$password,$username', 'return Validation::checkCredentials($username,$password);'), array($user->getUsername())));
38  $this->addCheck(new FormValidatorLength($this, 'password', 'required', 'user.register.form.passwordLengthTooShort', '>=', $site->getMinPasswordLength()));
39  $this->addCheck(new FormValidator($this, 'password', 'required', 'user.profile.form.newPasswordRequired'));
40  $this->addCheck(new FormValidatorCustom($this, 'password', 'required', 'user.register.form.passwordsDoNotMatch', create_function('$password,$form', 'return $password == $form->getData(\'password2\');'), array($this)));
41  $this->addCheck(new FormValidatorCustom($this, 'password', 'required', 'user.profile.form.passwordSameAsOld', create_function('$password,$form', 'return $password != $form->getData(\'oldPassword\');'), array($this)));
42 
43  $this->addCheck(new FormValidatorPost($this));
44  }
45 
49  function getUser() {
50  return $this->_user;
51  }
52 
56  function getSite() {
57  return $this->_site;
58  }
59 
63  function display() {
64  $user = $this->getUser();
65  $templateMgr = TemplateManager::getManager();
66  $site = $this->getSite();
67  $templateMgr->assign('minPasswordLength', $site->getMinPasswordLength());
68  $templateMgr->assign('username', $user->getUsername());
69  parent::display();
70  }
71 
75  function readInputData() {
76  $this->readUserVars(array('oldPassword', 'password', 'password2'));
77  }
78 
82  function execute() {
83  $user = $this->getUser();
84 
85  if ($user->getAuthId()) {
86  $authDao = DAORegistry::getDAO('AuthSourceDAO');
87  $auth = $authDao->getPlugin($user->getAuthId());
88  }
89 
90  if (isset($auth)) {
91  $auth->doSetUserPassword($user->getUsername(), $this->getData('password'));
92  $user->setPassword(Validation::encryptCredentials($user->getId(), Validation::generatePassword())); // Used for PW reset hash only
93  } else {
94  $user->setPassword(Validation::encryptCredentials($user->getUsername(), $this->getData('password')));
95  }
96 
97  $userDao = DAORegistry::getDAO('UserDAO');
98  $userDao->updateObject($user);
99  }
100 }
101 
102 ?>
static & getDAO($name, $dbconn=null)
addCheck($formValidator)
Definition: Form.inc.php:396
Form to change a user&#39;s password.
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)
ChangePasswordForm($user, $site)
static encryptCredentials($username, $password, $encryption=false)
Class to represent a form validation check.