/** * @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"); } }
/** * @param string $key * @param int $user */ public function renderForgotPass($key = null, $user = null) { if (!is_null($key) && !is_null($user)) { $ok = FALSE; try { $actionKey = $this->actionKeyRepository->findByKeyAndUser($key, $user); if (!is_null($actionKey) && $actionKey->isValid()) { $ok = TRUE; } else { $this->flashMessage($this->t("forms.forgot-password.errors.not-exists-key"), "danger"); } } catch (\Exception $e) { $this->catchException($e, $e->getMessage()); } if ($ok) { $this["forgotPassword"]->setStep(\Components\Forms\ForgotPassStep::SET_NEW); $this["forgotPassword"]->setActionKey($actionKey); } } }