Example #1
0
 /**
  * @param \Nette\Application\UI\Form $form
  */
 public function processRegister(\Nette\Application\UI\Form $form)
 {
     $values = $form->getValues();
     if ($this->userRepository->existsUsername($values->username)) {
         $form["username"]->addError($this->t("forms.register.errors.exists-username"));
     } else {
         if ($this->userRepository->existsEmail($values->email)) {
             $form["email"]->addError($this->t("forms.register.errors.exists-email"));
         } else {
             $this->getDbUtils()->begin();
             try {
                 $registerOptions = $this->container->getParameters()["register"];
                 if ($registerOptions["activation"]) {
                     $status = \Model\Common\RecordStatus::UNFINISHED;
                 } else {
                     $status = \Model\Common\RecordStatus::VALID;
                 }
                 $user = $this->userRepository->createNewUser($values, $registerOptions["defaultGroupId"], $status);
                 if ($registerOptions["activation"]) {
                     $this->sendActivationEmail($values->email, $user);
                     $this->flashMessage($this->t("forms.register.messages.need-activate"), "info");
                 } else {
                     $this->flashMessage($this->t("forms.register.messages.register-success"), "success");
                 }
                 $form->setDefaults(array("username" => "", "email" => ""), TRUE);
                 $this->getDbUtils()->commit();
             } catch (\Exception $e) {
                 $this->getDbUtils()->rollback();
                 $this->catchFormError($e, $form, $this->t("global.errors.database-error"));
             }
         }
     }
     $this->redrawControl("registerForm");
 }
Example #2
0
 /**
  * @param array $credentials
  * @return \Nette\Security\Identity
  * @throws \Nette\Security\AuthenticationException
  */
 public function authenticate(array $credentials)
 {
     list($username, $password) = $credentials;
     $user = $this->repository->findUserByName($username);
     if (!is_null($user) && \Nette\Security\Passwords::verify($password, $user->getPassword())) {
         $group = $this->repository->findGroupById($user->getGroupId());
         return new \Nette\Security\Identity($user->id, $group->getName(), $user->getIdentity());
     } else {
         throw new \Nette\Security\AuthenticationException($this->t("forms.sign.errors.wrong-credentials"), self::IDENTITY_NOT_FOUND);
     }
 }
Example #3
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");
     }
 }
Example #4
0
 /**
  * @param string $key
  * @param int $id
  */
 public function actionActivate($key, $id)
 {
     $ok = false;
     $this->dbUtils->begin();
     try {
         $this->userRepository->activateUser($id, $key);
         $this->flashMessage($this->t("forms.register.messages.activated"), "success");
         $ok = true;
         $this->dbUtils->commit();
     } catch (\Nette\UnexpectedValueException $e) {
         $this->dbUtils->rollback();
         $this->catchException($e, $e->getMessage());
     } catch (\Exception $e) {
         $this->dbUtils->rollback();
         $this->catchException($e, $e->getMessage());
     }
     if ($ok) {
         $this->redirect("Homepage:default");
     }
 }