Ejemplo n.º 1
0
 /**
  * @param \Nette\Application\UI\Form $form
  */
 public function setNewPassword(\Nette\Application\UI\Form $form)
 {
     $values = $form->getValues();
     $ok = FALSE;
     try {
         $actionKey = $this->actionKeyRepository->findByKeyAndUser($values->key, $values->id);
         if (is_null($actionKey) || !$actionKey->isValid()) {
             throw new \Nette\UnexpectedValueException("forms.forgot-password.errors.not-exists-key");
         } else {
             $actionKey->setStatus(\Model\Common\RecordStatus::DELETED);
             $user = $this->userRepository->find($values->id);
             $user->setPassword(\Nette\Security\Passwords::hash($values->password));
             $this->userRepository->saveUser($user);
             $this->actionKeyRepository->save($actionKey);
             $ok = TRUE;
         }
     } catch (\Nette\UnexpectedValueException $e) {
         $this->flashMessage($this->t($e->getMessage()), "danger");
         $this->step = ForgotPassStep::SEND;
     } catch (\Exception $e) {
         $this->catchException($e, $this);
     }
     if ($ok) {
         $this->presenter->flashMessage($this->t("forms.forgot-password.messages.recovered"), "success");
         $this->presenter->redirect("Homepage:default");
     }
 }