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_up')); } unset($values->__anti); $user = $this->userRepository->createRegistration($values); $link = $p->link('//:Admin:Sign:unlock', array('uid' => $user->id, 'token' => $user->token)); $this->sendEmail($this->contactEmail, $user->email, $this->translator->translate('locale.sign.sign_up_request'), $link); $p->flashMessage($this->translator->translate('locale.sign.sign_up_email_sent'), FlashType::SUCCESS); } catch (FormSentBySpamException $e) { $this->addFormError($form, $e); $this->redrawControl('formErrors'); } catch (PossibleUniqueKeyDuplicationException $e) { $this->addFormError($form, $e); $this->redrawControl('formErrors'); } catch (\Exception $e) { $this->addFormError($form, $e, $this->translator->translate('locale.error.occurred')); $this->redrawControl('formErrors'); } if (!empty($user)) { $p->redirect('Homepage:default'); } }
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'); }
/** * @param string $email * @param string $password * * @return IIdentity * * @throws AuthenticationException */ public function authenticateWithEmail($email, $password) { try { $user = $this->userRepository->findOneBy(['email' => $email]); return $this->authenticate(['authenticator' => self::AUTH_EMAIL, 'user' => $user, 'password' => $password]); } catch (IOException $e) { throw new AuthenticationException('User not found.'); } }
/** * Returns user when is authenticated. * * @return \App\Model\Entities\User * @throws AuthorizationException */ public function getUser() { if ($this->isLoggedIn()) { if (empty($this->user)) { $this->user = $this->userRepository->find($this->id); } return $this->user; } else { throw new AuthorizationException('The user is not authenticated.'); } }
public function formSucceeded(Form $form) { try { $p = $this->getPresenter(); $values = $form->getValues(); $this->userRepository->updatePassword($this->item, $values->password, true); $p->flashMessage($this->translator->translate('locale.sign.password_changed_sign_in'), FlashType::INFO); } catch (PossibleUniqueKeyDuplicationException $e) { $this->addFormError($form, $e); } catch (\PDOException $e) { $this->addFormError($form, $e, $this->translator->translate('locale.error.occurred')); } $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); }
public function formSucceeded(Form $form) { try { $p = $this->getPresenter(); $values = $form->getValues(); $user = $this->userRepository->updateProfileSettings($values, $this->item); $this->userStorage->setIdentity($this->authenticator->updateIdentity($user)); $p->flashMessage($this->translator->translate('locale.settings.changed_successfully'), FlashType::SUCCESS); } catch (PossibleUniqueKeyDuplicationException $e) { $this->addFormError($form, $e); } catch (\Exception $e) { $this->addFormError($form, $e, $this->translator->translate('locale.error.occurred')); } $p->redirect('this'); }
/** * @param array|null $withoutUsers * @return array */ public function findAllUsers(array $withoutUsers = null) { $users = $this->userRepository->findAllUsers($withoutUsers); return $users; }
public function changePassword($userId, $password) { $this->repository->update($userId, ["password" => Passwords::hash($password)]); }