Example #1
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 #2
0
 /**
  * @param string $email
  * @param \Model\Core\User\User $user
  */
 private function sendActivationEmail($email, $user)
 {
     $template = $this->template;
     $template->setFile(__DIR__ . "/activate.email.latte");
     $template->appname = $this->presenter->getAppName();
     $template->username = $user->getUsername();
     $key = $this->actionKey->createKey(\Model\Core\ActionKey\ActionKeyTypeCode::REGISTER, $user->getId());
     $template->link = $this->presenter->link("//Homepage:activate", array("id" => $user->getId(), "key" => $key->getKey()));
     $template->activate = $this->container->getParameters()["register"]["activation"];
     $this->mailer->createMessage($email, "Vítejte na " . $this->presenter->getAppName(), (string) $template);
     $this->mailer->send();
 }
Example #3
0
 /**
  * @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);
         }
     }
 }