Guest User

Untitled

a guest
Dec 9th, 2018
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.73 KB | None | 0 0
  1. <?php
  2. /**
  3. * Login presenter.
  4. *
  5. * @author Roland "DOBss" Dobos
  6. * @package Pekarstvo.sk
  7. */
  8.  
  9. namespace AdminModule;
  10.  
  11. use \Nette\Application\UI\Form;
  12.  
  13. class LoginPresenter extends BasePresenter{
  14.  
  15. public function beforeRender(){
  16. if($this->getUser()->isLoggedIn()) $this->redirect("Panel:");
  17. $this->template->h1c = 'mainc';
  18. // try{
  19. // $user = $this->getUser();
  20. // $pass = \User::hashPassword('himes0411');
  21. // $user->login('DOBss', $pass);
  22. // $this->flashMessage("Boli ste úspešne prihlásení","success");
  23. // }catch(\Nette\Security\AuthenticationException $e){
  24. // $this->flashMessage($e->getMessage(),"error");
  25. // }
  26. dump($this->getUser()->getIdentity());
  27. }
  28.  
  29. public function actionOut(){
  30. $this->getUser()->logout();
  31. $this->flashMessage("Boli ste úspešne odhlásený", "success");
  32. $this->redirect("Login:");
  33. }
  34.  
  35. public function createComponentLoginForm(){
  36. $form = new Form;
  37.  
  38. $form->addText('login','Meno:');
  39. $form->addPassword('pass','Heslo:');
  40. $form->addsubmit('send','Prihlásiť:');
  41.  
  42. $form->onSuccess[] = callback($this, 'loginFormSubmitted');
  43.  
  44. return $form;
  45. }
  46.  
  47. public function loginFormSubmitted(Form $form){
  48. if(empty($form->values->login) || empty($form->values->pass)) $this->flashMessage('Musíte vyplniť všetky polia',"error");
  49. else{
  50. try{
  51. // dump($form->values); exit;
  52. $user = $this->getUser();
  53. $pass = \User::hashPassword($form->values->pass);
  54. $user->login($form->values->login, $pass);
  55. $this->flashMessage("Boli ste úspešne prihlásení","success");
  56. // $this->redirect("Panel:");
  57. }catch(\Nette\Security\AuthenticationException $e){
  58. $this->flashMessage($e->getMessage(),"error");
  59. }
  60. }
  61. }
  62. }
Add Comment
Please, Sign In to add comment