|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace FrontendModule; |
|
4
|
|
|
|
|
5
|
|
|
use Nette\Application\UI; |
|
6
|
|
|
use Kdyby\BootstrapFormRenderer\BootstrapRenderer; |
|
7
|
|
|
use Nette\Security as NS; |
|
8
|
|
|
|
|
9
|
|
|
class LoginPresenter extends \FrontendModule\BasePresenter |
|
10
|
|
|
{ |
|
11
|
|
|
public function beforeRender() |
|
12
|
|
|
{ |
|
13
|
|
|
parent::beforeRender(); |
|
14
|
|
|
|
|
15
|
|
|
if ($this->getUser()->isLoggedIn()) { |
|
16
|
|
|
$this->forward('Homepage:'); |
|
17
|
|
|
} |
|
18
|
|
|
} |
|
19
|
|
|
|
|
20
|
|
|
protected function startup() |
|
21
|
|
|
{ |
|
22
|
|
|
parent::startup(); |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* Sign in form component factory. |
|
27
|
|
|
* @return UI\Form |
|
28
|
|
|
*/ |
|
29
|
|
|
protected function createComponentSignInForm($name) |
|
|
|
|
|
|
30
|
|
|
{ |
|
31
|
|
|
$form = new UI\Form(); |
|
32
|
|
|
|
|
33
|
|
|
$form->getElementPrototype()->action = $this->link('default', array( |
|
34
|
|
|
'path' => 'loginfe', |
|
35
|
|
|
'abbr' => $this->abbr, |
|
36
|
|
|
'do' => 'signInForm-submit', |
|
37
|
|
|
)); |
|
38
|
|
|
|
|
39
|
|
|
$form->setRenderer(new BootstrapRenderer()); |
|
40
|
|
|
|
|
41
|
|
|
$form->addText('username', 'Přihlašovací jméno') |
|
42
|
|
|
->setRequired('Please provide a username.') |
|
43
|
|
|
->setAttribute('placeholder', 'Přihlašovací jméno'); |
|
|
|
|
|
|
44
|
|
|
|
|
45
|
|
|
$form->addPassword('password', 'Heslo') |
|
46
|
|
|
->setRequired('Please provide a password.') |
|
47
|
|
|
->setAttribute('placeholder', 'Heslo'); |
|
|
|
|
|
|
48
|
|
|
|
|
49
|
|
|
$form->addCheckbox('remember', 'Permanent login?'); |
|
50
|
|
|
|
|
51
|
|
|
$form->addSubmit('send', 'Přihlásit'); |
|
52
|
|
|
|
|
53
|
|
|
$form->onSuccess[] = callback($this, 'signInFormSubmitted'); |
|
54
|
|
|
|
|
55
|
|
|
return $form; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
public function renderDefault() |
|
59
|
|
|
{ |
|
60
|
|
|
$this->setLayout('login'); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
View Code Duplication |
public function signInFormSubmitted($form) |
|
|
|
|
|
|
64
|
|
|
{ |
|
65
|
|
|
|
|
66
|
|
|
try { |
|
67
|
|
|
$values = $form->getValues(); |
|
68
|
|
|
if ($values->remember) { |
|
69
|
|
|
$this->getUser()->setExpiration('+ 14 days', false); |
|
70
|
|
|
} else { |
|
71
|
|
|
$this->getUser()->setExpiration('+ 20 minutes', true); |
|
72
|
|
|
} |
|
73
|
|
|
$this->getUser()->login($values->username, $values->password); |
|
74
|
|
|
$this->flashMessage('Přihlášení bylo úspěšné', 'success'); |
|
75
|
|
|
|
|
76
|
|
|
//TODO bude upraveno - ted nestiham :) |
|
77
|
|
|
//$this->forward('Homepage:'); |
|
78
|
|
|
$this->redirectUrl('https://www.zajistenainvestice.cz/uvod'); |
|
79
|
|
|
} catch (NS\AuthenticationException $e) { |
|
80
|
|
|
$this->flashMessage($this->translation[$e->getMessage()], 'danger'); |
|
81
|
|
|
$form->addError($e->getMessage()); |
|
82
|
|
|
} |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
public function actionOut() |
|
86
|
|
|
{ |
|
87
|
|
|
$this->getUser()->logout(); |
|
88
|
|
|
$this->flashMessage('Odhlášení bylo úspěšné', 'success'); |
|
89
|
|
|
$this->forward('Homepage:'); |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
} |
|
93
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.