Guest User

Untitled

a guest
Dec 9th, 2018
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.19 KB | None | 0 0
  1. <?php
  2. /**
  3.  * Log presenter.
  4.  *
  5.  * @author   Roland "DOBss" Dobos
  6.  * @package  Pekarstvo.sk
  7.  */
  8.  
  9. namespace FrontModule;
  10.  
  11. use \Nette\Security as NS, \dibi;
  12.  
  13. class LogPresenter extends BasePresenter{
  14.  
  15.     public function actionIn(){
  16.         if(!empty($_POST['login']) && !empty($_POST['pw'])){
  17.             try{
  18.                 $user = $this->getUser();
  19.                 $pass = \User::hashPassword($_POST['pw']);
  20.                 $this->getUser()->setExpiration('+ 14 days', FALSE);
  21.                 $user->login($_POST['login'], $pass);
  22.                 if ($this->isAjax()){
  23.                     $this->payload->message = 'ok';
  24.                     $this->terminate();
  25.                 }
  26.             }catch(NS\AuthenticationException $e){
  27.                 if ($this->isAjax()){
  28.                     $this->payload->message = $e->getMessage();
  29.                     $this->terminate();
  30.                 }else
  31.                     $this->flashMessage($e->getMessage(), "success");
  32.             }
  33.         }else if($this->isAjax()){ $this->payload->message = 'Musíte vyplniť všetky polia.'; $this->terminate(); }
  34.     }
  35.    
  36.     public function actionOut(){
  37.         $this->getUser()->logout();
  38.         if ($this->isAjax()){ $this->payload->message = 'ok'; $this->terminate(); }
  39.         else $this->flashMessage("Boli ste úspešne odhlásený", "success");
  40.     }
  41.  
  42.     public function beforeRender(){
  43.         $this->redirect("Homepage:");
  44.     }
  45. }
Add Comment
Please, Sign In to add comment