Open Monograph Press  3.3.0
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 __construct($user, $site) {
31  parent::__construct('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', function($password) use ($user) {
38  return Validation::checkCredentials($user->getUsername(),$password);
39  }));
40  $this->addCheck(new FormValidatorLength($this, 'password', 'required', 'user.register.form.passwordLengthRestriction', '>=', $site->getMinPasswordLength()));
41  $this->addCheck(new FormValidator($this, 'password', 'required', 'user.profile.form.newPasswordRequired'));
42  $form = $this;
43  $this->addCheck(new FormValidatorCustom($this, 'password', 'required', 'user.register.form.passwordsDoNotMatch', function($password) use ($form) {
44  return $password == $form->getData('password2');
45  }));
46  $this->addCheck(new FormValidatorCustom($this, 'password', 'required', 'user.profile.form.passwordSameAsOld', function($password) use ($form) {
47  return $password != $form->getData('oldPassword');
48  }));
49 
50  $this->addCheck(new FormValidatorPost($this));
51  $this->addCheck(new FormValidatorCSRF($this));
52  }
53 
57  function getUser() {
58  return $this->_user;
59  }
60 
64  function getSite() {
65  return $this->_site;
66  }
67 
71  function fetch($request, $template = null, $display = false) {
72  $templateMgr = TemplateManager::getManager();
73  $templateMgr->assign(array(
74  'minPasswordLength' => $this->getSite()->getMinPasswordLength(),
75  'username' => $this->getUser()->getUsername(),
76  ));
77  return parent::fetch($request, $template, $display);
78  }
79 
83  function readInputData() {
84  $this->readUserVars(array('oldPassword', 'password', 'password2'));
85  }
86 
90  function execute(...$functionArgs) {
91  $user = $this->getUser();
92 
93  if ($user->getAuthId()) {
94  $authDao = DAORegistry::getDAO('AuthSourceDAO'); /* @var $authDao AuthSourceDAO */
95  $auth = $authDao->getPlugin($user->getAuthId());
96  }
97 
98  if (isset($auth)) {
99  $auth->doSetUserPassword($user->getUsername(), $this->getData('password'));
100  $user->setPassword(Validation::encryptCredentials($user->getId(), Validation::generatePassword())); // Used for PW reset hash only
101  } else {
102  $user->setPassword(Validation::encryptCredentials($user->getUsername(), $this->getData('password')));
103  }
104 
105  parent::execute(...$functionArgs);
106 
107  $userDao = DAORegistry::getDAO('UserDAO'); /* @var $userDao UserDAO */
108  $userDao->updateObject($user);
109  }
110 }
111 
112 
ChangePasswordForm\execute
execute(... $functionArgs)
Definition: ChangePasswordForm.inc.php:96
Validation\encryptCredentials
static encryptCredentials($username, $password, $encryption=false, $legacy=false)
Definition: Validation.inc.php:255
ChangePasswordForm\$_site
$_site
Definition: ChangePasswordForm.inc.php:31
FormValidatorLength
Form validation check that checks if a field's length meets certain requirements.
Definition: FormValidatorLength.inc.php:18
DAORegistry\getDAO
static & getDAO($name, $dbconn=null)
Definition: DAORegistry.inc.php:57
ChangePasswordForm\readInputData
readInputData()
Definition: ChangePasswordForm.inc.php:89
Form\readUserVars
readUserVars($vars)
Definition: Form.inc.php:378
FormValidatorPost
Form validation check to make sure the form is POSTed.
Definition: FormValidatorPost.inc.php:18
ChangePasswordForm
Form to change a user's password.
Definition: ChangePasswordForm.inc.php:19
ChangePasswordForm\fetch
fetch($request, $template=null, $display=false)
Definition: ChangePasswordForm.inc.php:77
Validation\generatePassword
static generatePassword($length=null)
Definition: Validation.inc.php:283
ChangePasswordForm\$_user
$_user
Definition: ChangePasswordForm.inc.php:25
Validation\checkCredentials
static checkCredentials($username, $password)
Definition: Validation.inc.php:188
ChangePasswordForm\getUser
getUser()
Definition: ChangePasswordForm.inc.php:63
ChangePasswordForm\__construct
__construct($user, $site)
Definition: ChangePasswordForm.inc.php:36
PKPTemplateManager\getManager
static & getManager($request=null)
Definition: PKPTemplateManager.inc.php:1239
FormValidator
Class to represent a form validation check.
Definition: FormValidator.inc.php:23
Form\addCheck
addCheck($formValidator)
Definition: Form.inc.php:395
FormValidatorCSRF
Form validation check to make sure the CSRF token is correct.
Definition: FormValidatorCSRF.inc.php:18
Form
Class defining basic operations for handling HTML forms.
Definition: Form.inc.php:47
FormValidatorCustom
Form validation check with a custom user function performing the validation check.
Definition: FormValidatorCustom.inc.php:18
ChangePasswordForm\getSite
getSite()
Definition: ChangePasswordForm.inc.php:70