public function formSucceeded(Form $form) { try { $p = $this->getPresenter(); $values = $form->getValues(); if (strlen($values->__anti) > 0) { throw new FormSentBySpamException($this->translator->translate('locale.form.spam_attempt_sign_reset')); } unset($values->__anti); $user = $this->userRepository->getByEmail($values->email); if (!$user) { throw new UserNotFoundException(); } $token = $this->userRepository->prepareNewToken($user); $link = $p->link('//:Admin:Sign:password', array('uid' => $user->id, 'token' => $token)); $this->sendEmail($this->contactEmail, $values->email, $this->translator->translate('locale.sign.new_password_request'), $link); $p->flashMessage($this->translator->translate('locale.sign.new_password_request_email_sent'), FlashType::INFO); } catch (FormSentBySpamException $e) { $this->addFormError($form, $e); $this->redrawControl('formErrors'); } catch (UserNotFoundException $e) { $this->addFormError($form, $e, $this->translator->translate('locale.error.occurred')); $this->redrawControl('formErrors'); } catch (\PDOException $e) { $this->addFormError($form, $e, $this->translator->translate('locale.error.occurred')); $this->redrawControl('formErrors'); } $p->redirect(':Front:Homepage:default'); }
/** * @throws Nette\Security\AuthenticationException * @return Nette\Security\Identity */ public function authenticate(array $credentials) { list($email, $password) = $credentials; $user = $this->userRepository->getByEmail($email); if (!$user) { throw new Nette\Security\AuthenticationException($this->translator->translate('locale.sign.incorrect_email'), self::IDENTITY_NOT_FOUND); } elseif (!$user->isAuthenticated) { throw new Nette\Security\AuthenticationException($this->translator->translate('locale.sign.authentication_waiting'), self::NOT_APPROVED); } elseif (!Passwords::verify($password . $user->salt, $user->password)) { throw new Nette\Security\AuthenticationException($this->translator->translate('locale.sign.incorrect_password'), self::INVALID_CREDENTIAL); } elseif (Passwords::needsRehash($user->password)) { $this->userRepository->updatePassword($user, $user->password); } return $this->updateIdentity($user); }