示例#1
0
 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');
     }
 }
示例#2
0
 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');
 }
示例#3
0
 /**
  * @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.');
     }
 }
示例#4
0
 /**
  * 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.');
     }
 }
示例#5
0
 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');
 }
示例#6
0
 /**
  * @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);
 }
示例#7
0
 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');
 }
示例#8
0
 /**
  * @param array|null $withoutUsers
  * @return array
  */
 public function findAllUsers(array $withoutUsers = null)
 {
     $users = $this->userRepository->findAllUsers($withoutUsers);
     return $users;
 }
示例#9
0
 public function changePassword($userId, $password)
 {
     $this->repository->update($userId, ["password" => Passwords::hash($password)]);
 }