_user = $user; $this->_site = $site; // Validation checks for this form $this->addCheck(new \PKP\form\validation\FormValidatorCustom($this, 'oldPassword', 'required', 'user.profile.form.oldPasswordInvalid', function ($password) use ($user) { return Validation::checkCredentials($user->getUsername(), $password); })); $this->addCheck(new \PKP\form\validation\FormValidatorLength($this, 'password', 'required', 'user.register.form.passwordLengthRestriction', '>=', $site->getMinPasswordLength())); $this->addCheck(new \PKP\form\validation\FormValidator($this, 'password', 'required', 'user.profile.form.newPasswordRequired')); $form = $this; $this->addCheck(new \PKP\form\validation\FormValidatorCustom($this, 'password', 'required', 'user.register.form.passwordsDoNotMatch', function ($password) use ($form) { return $password == $form->getData('password2'); })); $this->addCheck(new \PKP\form\validation\FormValidatorCustom($this, 'password', 'required', 'user.profile.form.passwordSameAsOld', function ($password) use ($form) { return $password != $form->getData('oldPassword'); })); $this->addCheck(new \PKP\form\validation\FormValidatorPost($this)); $this->addCheck(new \PKP\form\validation\FormValidatorCSRF($this)); } /** * Get the user associated with this password */ public function getUser() { return $this->_user; } /** * Get the site */ public function getSite() { return $this->_site; } /** * @copydoc Form::fetch * * @param null|mixed $template */ public function fetch($request, $template = null, $display = false) { $templateMgr = TemplateManager::getManager(); $templateMgr->assign([ 'minPasswordLength' => $this->getSite()->getMinPasswordLength(), 'username' => $this->getUser()->getUsername(), ]); return parent::fetch($request, $template, $display); } /** * Assign form data to user-submitted data. */ public function readInputData() { $this->readUserVars(['oldPassword', 'password', 'password2']); } /** * @copydoc Form::execute() */ public function execute(...$functionArgs) { $user = $this->getUser(); $user->setPassword(Validation::encryptCredentials($user->getUsername(), $this->getData('password'))); parent::execute(...$functionArgs); Repo::user()->edit($user); } } if (!PKP_STRICT_MODE) { class_alias('\PKP\user\form\ChangePasswordForm', '\ChangePasswordForm'); }