_user = $user; $this->_site = $site; $this->_hash = $hash; $this->addCheck(new FormValidatorLength($this, 'password', 'required', 'user.register.form.passwordLengthRestriction', '>=', $site->getMinPasswordLength())); $this->addCheck(new FormValidator($this, 'password', 'required', 'user.profile.form.newPasswordRequired')); $form = $this; $this->addCheck(new FormValidatorCustom($this, 'password', 'required', 'user.register.form.passwordsDoNotMatch', function ($password) use ($form) { return $password == $form->getData('password2'); })); $this->addCheck(new FormValidatorPost($this)); $this->addCheck(new FormValidatorCSRF($this)); } /** * Get the user associated with this password */ public function getUser() { return $this->_user; } /** * Get the site */ public function getSite() { return $this->_site; } /** * Get the password reset hash */ public function getHash() { return $this->_hash; } /** * @copydoc Form::display * * @param null|mixed $request * @param null|mixed $template */ public function display($request = null, $template = null) { $templateMgr = TemplateManager::getManager($request); $templateMgr->assign([ 'minPasswordLength' => $this->getSite()->getMinPasswordLength(), 'username' => $this->getUser()->getUsername(), 'hash' => $this->getHash(), ]); parent::display($request, $template); } /** * Assign form data to user-submitted data. */ public function readInputData() { $this->readUserVars(['username', 'hash', 'password', 'password2']); } /** * @copydoc Form::execute() */ public function execute(...$functionArgs) { $user = $this->getUser(); $user->setPassword(Validation::encryptCredentials($user->getUsername(), $this->getData('password'))); $user->setMustChangePassword(0); SessionManager::getManager()->invalidateSessions($user->getId()); Repo::user()->edit($user); parent::execute(...$functionArgs); return true; } /** * Validate the password reset hash */ public function validatePasswordResetHash() { if (Validation::verifyPasswordResetHash($this->getUser()->getId(), $this->getHash())) { return true; } return false; } /** * Display the error page when passed invalid password reset hash * * @param null|mixed $template */ public function displayInvalidHashErrorMessage($request, $template = null) { $this->setTemplate('frontend/pages/error.tpl'); $templateMgr = TemplateManager::getManager($request); $templateMgr->assign([ 'errorMsg' => 'user.login.lostPassword.invalidHash', 'backLink' => $request->url(null, null, 'lostPassword'), 'backLinkLabel' => 'user.login.resetPassword', ]); parent::display($request, $template); } }