public function testCanCreateUpdatePasswordForm() { $updatePasswordForm = new UpdatePasswordForm('testform'); $updatePasswordForm->prepare(); $this->assertTrue($updatePasswordForm->get('password') instanceof Element); $this->assertTrue($updatePasswordForm->get('confirmpassword') instanceof Element); $this->assertTrue($updatePasswordForm->get('send') instanceof Element); }
public function updatePasswordAction() { $passwordResetCode = $this->getEvent()->getRouteMatch()->getParam('password-reset-code'); if (empty($passwordResetCode)) { $this->redirect()->toRoute('home'); } $userId = $this->getUserService()->getUserIdFromPasswordResetCode($passwordResetCode); if (!$userId) { $this->flashMessenger()->addErrorMessage($this->translate('Your password reset request has expired. Please try again.')); $this->redirect()->toRoute('home'); } $form = new UpdatePasswordForm('update-password'); $form->setTranslator($this->getServiceLocator()->get('translator')); $form->prepare(); $inputFilter = new InputFilter(); $inputFilter->add($this->getPasswordFilter()); $inputFilter->add($this->getConfirmPasswordFilter()); $form->setInputFilter($inputFilter); $request = $this->getRequest(); if ($request->isPost()) { $data = $request->getPost(); $form->setData($data); if ($form->isValid()) { $password = $this->getUserService()->encryptPassword($data['password']); $user = $this->loadModel('User', $userId); $user->set('passwordresetcode', '0'); $user->set('password', $password); $user->save(); $this->flashMessenger()->addSuccessMessage($this->translate('Your password was successfully updated.')); $this->redirect()->toRoute('home'); } } return array("form" => $form, "code" => $passwordResetCode); }