Open Journal Systems  3.3.0
LoginChangePasswordForm.inc.php
1 <?php
2 
16 import('lib.pkp.classes.form.Form');
17 
19 
23  function __construct($site) {
24  parent::__construct('user/loginChangePassword.tpl');
25 
26  // Validation checks for this form
27  $form = $this;
28  $this->addCheck(new FormValidatorCustom($this, 'oldPassword', 'required', 'user.profile.form.oldPasswordInvalid', function($password) use ($form) {
29  return Validation::checkCredentials($form->getData('username'),$password);
30  }));
31  $this->addCheck(new FormValidatorLength($this, 'password', 'required', 'user.register.form.passwordLengthRestriction', '>=', $site->getMinPasswordLength()));
32  $this->addCheck(new FormValidator($this, 'password', 'required', 'user.profile.form.newPasswordRequired'));
33  $this->addCheck(new FormValidatorCustom($this, 'password', 'required', 'user.register.form.passwordsDoNotMatch', function($password) use ($form) {
34  return $password == $form->getData('password2');
35  }));
36  $this->addCheck(new FormValidatorPost($this));
37  $this->addCheck(new FormValidatorCSRF($this));
38  }
39 
43  function display($request = null, $template = null) {
44  $templateMgr = TemplateManager::getManager($request);
45  $site = $request->getSite();
46  $templateMgr->assign('minPasswordLength', $site->getMinPasswordLength());
47  parent::display($request, $template);
48  }
49 
53  function readInputData() {
54  $this->readUserVars(array('username', 'oldPassword', 'password', 'password2'));
55  }
56 
61  function execute(...$functionArgs) {
62  $userDao = DAORegistry::getDAO('UserDAO'); /* @var $userDao UserDAO */
63  $user = $userDao->getByUsername($this->getData('username'), false);
64  parent::execute(...$functionArgs);
65  if ($user != null) {
66  if ($user->getAuthId()) {
67  $authDao = DAORegistry::getDAO('AuthSourceDAO'); /* @var $authDao AuthSourceDAO */
68  $auth = $authDao->getPlugin($user->getAuthId());
69  }
70 
71  if (isset($auth)) {
72  $auth->doSetUserPassword($user->getUsername(), $this->getData('password'));
73  $user->setPassword(Validation::encryptCredentials($user->getId(), Validation::generatePassword())); // Used for PW reset hash only
74  } else {
75  $user->setPassword(Validation::encryptCredentials($user->getUsername(), $this->getData('password')));
76  }
77 
78  $user->setMustChangePassword(0);
79  $userDao->updateObject($user);
80  return true;
81 
82  } else {
83  return false;
84  }
85  }
86 }
87 
88 
Validation\encryptCredentials
static encryptCredentials($username, $password, $encryption=false, $legacy=false)
Definition: Validation.inc.php:255
FormValidatorLength
Form validation check that checks if a field's length meets certain requirements.
Definition: FormValidatorLength.inc.php:18
LoginChangePasswordForm\display
display($request=null, $template=null)
Definition: LoginChangePasswordForm.inc.php:43
DAORegistry\getDAO
static & getDAO($name, $dbconn=null)
Definition: DAORegistry.inc.php:57
Form\readUserVars
readUserVars($vars)
Definition: Form.inc.php:378
Form\getData
getData($key)
Definition: Form.inc.php:220
FormValidatorPost
Form validation check to make sure the form is POSTed.
Definition: FormValidatorPost.inc.php:18
Validation\generatePassword
static generatePassword($length=null)
Definition: Validation.inc.php:283
LoginChangePasswordForm\__construct
__construct($site)
Definition: LoginChangePasswordForm.inc.php:23
LoginChangePasswordForm
Form to change a user's password in order to login.
Definition: LoginChangePasswordForm.inc.php:18
LoginChangePasswordForm\execute
execute(... $functionArgs)
Definition: LoginChangePasswordForm.inc.php:61
Validation\checkCredentials
static checkCredentials($username, $password)
Definition: Validation.inc.php:188
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
LoginChangePasswordForm\readInputData
readInputData()
Definition: LoginChangePasswordForm.inc.php:53