setExpiration() public method

Enables log out after inactivity.
public setExpiration ( $time, $whenBrowserIsClosed = TRUE, $clearIdentity = FALSE ) : self
return self
示例#1
0
 public function formSucceeded($form, $values)
 {
     $this->user->setExpiration('14 days', FALSE);
     try {
         $this->user->login($values->email, $values->password);
     } catch (Nette\Security\AuthenticationException $e) {
         $form->addError($e->getMessage());
     }
 }
示例#2
0
 /**
  * @param Form $form
  */
 public function processForm(Form $form)
 {
     $values = $form->getValues();
     try {
         $this->user->login($values->username, $values->password);
         $this->user->setExpiration('30 minutes', true);
         $this->onSuccess();
     } catch (AuthenticationException $e) {
         $form->addError('Invalid credentials.');
     }
 }
示例#3
0
 /**
  * @param \Nette\Application\UI\Form $form
  */
 public function processForm(Form $form)
 {
     try {
         if ($form->values->persistent) {
             $this->user->setExpiration('+30 days', FALSE);
         }
         $this->user->login($form->values->email, $form->values->password);
     } catch (AuthenticationException $e) {
         $form->addError('Nesprávné uživatelské údaje');
     }
 }
示例#4
0
 public function formSucceeded($form, $values)
 {
     // $stop();
     $user = $this->userManager->add($values->fullname, $values->role, $values->email, $values->password);
     if ($user == false) {
         $form->addError('Tento email je již používán!');
     } else {
         $this->user->login($values->email, $values->password);
         $this->user->setExpiration('14 days', FALSE);
     }
 }
示例#5
0
 public function formSucceeded(Form $form, $values)
 {
     if ($values->remember) {
         $this->user->setExpiration('14 days', FALSE);
     } else {
         $this->user->setExpiration('20 minutes', TRUE);
     }
     try {
         $this->user->login($values->email, $values->password);
     } catch (Nette\Security\AuthenticationException $e) {
         $form->addError($form->translate('errors.wrong_login'));
     }
 }
 public function formSucceeded(Form $oForm, $oValues)
 {
     if ($oValues->remember) {
         $this->oUser->setExpiration('14 days', FALSE);
     } else {
         $this->oUser->setExpiration('20 minutes', TRUE);
     }
     try {
         $this->oUser->login($oValues->username, $oValues->password);
     } catch (Nette\Security\AuthenticationException $e) {
         $oForm->addError("Špatný login nebo heslo.");
     }
 }
 public function formSucceeded(Form $form, \stdClass $values)
 {
     if ($values->remember) {
         $this->user->setExpiration('14 days', FALSE);
     } else {
         $this->user->setExpiration('20 minutes', TRUE);
     }
     try {
         $this->user->login($values->username, $values->password);
     } catch (Nette\Security\AuthenticationException $e) {
         $form->addError('Přihlašovací údaje nejsou správné.');
     }
 }
示例#8
0
 /**
  * Prihlaseni uzivatele
  * @param Form $form
  * @param ArrayHash $values
  */
 public function formSucceeded(Form $form, $values)
 {
     if ($values->remember) {
         $this->user->setExpiration('14 days', FALSE);
     } else {
         $this->user->setExpiration('20 minutes', TRUE);
     }
     try {
         $this->user->login($values->username, $values->password);
     } catch (Nette\Security\AuthenticationException $e) {
         $form->addError($form->getTranslator()->translate('system.credentialsLogError'));
     }
 }
示例#9
0
文件: User.php 项目: rixxi/user
 public function signIn(IUser $user)
 {
     $this->onSignIn($user);
     if ($this->expiration !== NULL) {
         $this->security->setExpiration($this->expiration);
     }
     if ($this->backlink !== NULL) {
         $presenter = $this->application->getPresenter();
         if (isset($presenter->{$this->backlink})) {
             $presenter->restoreRequest($presenter->{$this->backlink});
         }
     }
 }
 public function formSucceeded(Form $form, $values)
 {
     if ($values->remember) {
         $this->user->setExpiration('14 days', FALSE);
     } else {
         $this->user->setExpiration('20 minutes', TRUE);
     }
     try {
         $this->user->login($values->username, $values->password);
     } catch (Nette\Security\AuthenticationException $e) {
         $form->addError('The username or password you entered is incorrect.');
     }
 }
示例#11
0
 public function formSucceeded(Form $form, $values)
 {
     if ($values->remember) {
         $this->user->setExpiration('14 days', FALSE);
     } else {
         $this->user->setExpiration('20 minutes', TRUE);
     }
     try {
         $this->user->login($values->username, $values->password);
     } catch (Nette\Security\AuthenticationException $e) {
         $form->addError($e->getMessage());
     }
 }
示例#12
0
 * @param array $texts
 * @return Nette\Application\UI\Form */
  public function create($texts)
  {
      $form = new Form();
      $form->addProtection();
      $form->addText('username', $texts['base_SignInForm_username'], 40, 20)->setRequired($texts['base_SignInForm_username_req']);
      $form->addPassword('password', $texts['base_SignInForm_password'], 40)->setRequired($texts['base_SignInForm_password_req']);
      $form->addCheckbox('remember', $texts['base_SignInForm_remember']);
      $form->addSubmit('login', $texts['base_SignInForm_login'])->setAttribute('class', 'btn btn-success')->onClick[] = [$this, 'signInFormSubmitted'];
      return $form;
  }
  /** 
 * Overenie po prihlaseni
 * @param Nette\Forms\Controls\SubmitButton $button Data formulara */
示例#13
0
 public function process(Form $form)
 {
     $values = $form->values;
     try {
         if ($values->remember) {
             $this->user->setExpiration('14 days', FALSE);
         } else {
             $this->user->setExpiration(0, TRUE);
         }
         $this->user->login($values->username, $values->password);
     } catch (AuthenticationException $e) {
         $form->addError($e->getMessage());
     }
 }
示例#14
0
 public function processForm($values)
 {
     if ($values->remember) {
         $this->user->setExpiration('14 days', FALSE);
     } else {
         $this->user->setExpiration('20 minutes', TRUE);
     }
     try {
         $this->user->login($values->username, $values->password);
         $this->presenter->redirect("Homepage:");
     } catch (Nette\Security\AuthenticationException $e) {
         $this->addError($e->getMessage());
     }
 }
示例#15
0
 public function formSucceeded(RegistrationForm $form)
 {
     if ($form['remember']->getValue()) {
         $this->user->setExpiration('14 days', false);
     } else {
         $this->user->setExpiration('20 minutes', true);
     }
     $date = DateTime::createFromFormat('Y-m-d', date("Y-m-d"));
     try {
         $this->manager->add($form['username']->getValue(), $form['password']->getValue(), $form['email']->getValue(), $date);
         $this->user->login($form['username']->getValue(), $form['password']->getValue());
     } catch (Nette\Security\AuthenticationException $e) {
         $form->addError($e->getMessage());
     }
 }
示例#16
0
 public function process(Form $form)
 {
     $values = $form->getValues();
     try {
         $this->userSecurity->setExpiration('+ 14 days', FALSE);
         $this->userSecurity->login($values->email, $values->pass);
     } catch (\Exception $e) {
         throw $e;
         $form->addError("We are sorry, error occured during login process");
         return;
     }
     // restore backlink if exists
     $form->presenter->restoreRequest($form->presenter->backlink);
     // or redirect
     $form->presenter->redirect(':Admin:ErrorList:');
 }
示例#17
0
 public function processForm(Form $form, $values)
 {
     if ($values->remember) {
         $this->user->setExpiration('14 days', FALSE);
     } else {
         $this->user->setExpiration('20 minutes', TRUE);
     }
     try {
         $this->user->login($values->username, $values->password);
         $this->setErrorCount(0);
     } catch (AuthenticationException $e) {
         $form->addError($this->errorMessage());
         return;
     }
     $this->onSave($this);
 }
 public function formSucceeded(Form $form, $values)
 {
     if ($values->remember) {
         $this->user->setExpiration('14 days', FALSE);
     } else {
         $this->user->setExpiration('20 minutes', TRUE);
     }
     try {
         $userManager = new Model\UserManager($this->user, $this->database);
         $userManager->login($values->username, $values->password);
     } catch (Nette\Security\AuthenticationException $e) {
         $form->addError($e->getMessage());
     }
     if ($form->getPresenter()->isAjax()) {
         $form->getPresenter()->redrawControl('sign');
     }
 }
示例#19
0
 public function formSuccess(Form $form)
 {
     $values = $form->getValues();
     try {
         if ($values->remember) {
             $this->user->setExpiration('+ 14 days', FALSE);
         } else {
             $this->user->setExpiration('+ 60 minutes', TRUE);
         }
         $this->user->login($values->username, $values->password);
         foreach ($this->onSuccess as $callback) {
             $callback($form);
         }
     } catch (AuthenticationException $e) {
         $form->addError($e->getMessage());
     }
 }
示例#20
0
 /**
  * @return Form
  */
 public function create(callable $onSuccess)
 {
     $form = $this->factory->create();
     $form->addText('username', 'Username:'******'Please enter your username.');
     $form->addPassword('password', 'Password:'******'Please enter your password.');
     $form->addCheckbox('remember', 'Keep me signed in');
     $form->addSubmit('send', 'Sign in');
     $form->onSuccess[] = function (Form $form, $values) use($onSuccess) {
         try {
             $this->user->setExpiration($values->remember ? '14 days' : '20 minutes');
             $this->user->login($values->username, $values->password);
         } catch (Nette\Security\AuthenticationException $e) {
             $form->addError('The username or password you entered is incorrect.');
             return;
         }
         $onSuccess();
     };
     return $form;
 }
 public function formSucceeded($form, $values)
 {
     if ($values->remember) {
         $this->user->setExpiration('14 days', FALSE);
     } else {
         $this->user->setExpiration('20 minutes', TRUE);
     }
     try {
         $this->user->login($values->username, $values->password);
     } catch (Security\AuthenticationException $e) {
         if ($e->getCode() === Security\IAuthenticator::IDENTITY_NOT_FOUND) {
             $form['username']->addError($e->getMessage());
         } elseif ($e->getCode() === Security\IAuthenticator::INVALID_CREDENTIAL) {
             $form['password']->addError($e->getMessage());
         } else {
             $form->addError($e->getMessage());
         }
     }
 }
示例#22
0
 private function addEventListeners($permanentLoginExpiration)
 {
     $this->onValidate[] = function () {
         $values = $this->getValues();
         try {
             $this->user->login($values->email, $values->password);
             $this->currentCartService->consolidateCurrentCartWithCurrentUser();
         } catch (AuthenticationException $e) {
             $this->addError('Invalid credentials.');
         }
     };
     $this->onSuccess[] = function () use($permanentLoginExpiration) {
         $values = $this->getValues();
         if ($values->permanent) {
             $this->user->setExpiration($permanentLoginExpiration, false);
         } else {
             $this->user->setExpiration(0, true);
         }
     };
 }
示例#23
0
 /**
  * @param Form $form
  */
 public function processForm(Form $form)
 {
     $values = $form->getValues();
     $login = $this->session->getSection('login');
     if (isset($login->counter) && $login->counter > 5) {
         sleep(2);
     }
     if ($values->remember) {
         $this->user->setExpiration('14 days', FALSE);
     } else {
         $this->user->setExpiration('20 minutes', TRUE);
     }
     try {
         $this->user->login($values->username, $values->password);
         $login->counter = 0;
         $this->onSuccess();
     } catch (AuthenticationException $e) {
         $login->counter++;
         $form->addError($e->getMessage());
     }
 }
示例#24
0
文件: Login.php 项目: vipercz/sandbox
 /**
  * @param Form $form
  */
 public function LoginFormSubmitted(Form $form)
 {
     $values = $form->getValues();
     $username = $values["nick"];
     $password = $values["pass"];
     // nastavíme expiraci
     $this->user->setExpiration('+ 15 minutes', TRUE, TRUE);
     if (!$this->user->isLoggedIn()) {
         try {
             // pokusíme se přihlásit uživatele...
             $this->user->login("db", $username, $password);
             // nastavíme expiraci
             if ($values['remember']) {
                 $this->user->setExpiration('+ 365 day', TRUE);
             } else {
                 $this->user->setExpiration('+ 15 minutes', TRUE);
             }
             // ...a v případě úspěchu presměrujeme na další stránku
             $this->notify("Uživatel se úspěšně přihlášil.");
             if ($this->getPresenter()->isAjax()) {
                 $json = new \stdClass();
                 $json->isLogin = TRUE;
                 $response = new JsonResponse($json);
                 $this->getPresenter()->sendResponse($response);
             } else {
                 $this->getPresenter()->redirect("Homepage:");
             }
         } catch (AuthenticationException $e) {
             $this->notify("Uživateli " . $username . " se nepovedlo přihlásit.");
             $this->flashMessage($e->getMessage());
             $this->getPresenter()->redirect("Homepage:");
         }
     } elseif ($this->getPresenter()->isAjax()) {
         $json = new \stdClass();
         $json->isLogin = TRUE;
         $response = new JsonResponse($json);
         $this->getPresenter()->sendResponse($response);
     }
 }