1: <?php
2:
3:
4: 5: 6: 7: 8: 9: 10: 11:
12:
13: namespace App\Modules\BaseModule\Presenters;
14:
15: use Nette,
16: App\Lib\Statics\Cons,
17: Nette\Application\UI\Form,
18: App\Presenters\BasePresenter,
19: Nette\Utils\ArrayHash;
20:
21: 22: 23: 24:
25: class SignPresenter extends BasePresenter {
26:
27:
28: public $backlink = '';
29:
30: 31: 32: 33:
34: protected function createComponentSignInForm() {
35: $form = new Form;
36: $form->addText(Cons::COLUMN_USERNAME, 'Uživatel:')
37: ->setRequired('Prosím vložte své jméno.');
38: $form->addPassword(Cons::COLUMN_PASSWORD, 'Heslo:')
39: ->setRequired('Prosím vložte heslo.');
40: $form->addCheckbox('remember', 'Zapamatovat si mě');
41: $form->addSubmit('send', 'Login');
42: $form->onSuccess[] = array($this, 'signInFormSucceeded');
43: return $form;
44: }
45:
46: 47: 48: 49: 50:
51: public function signInFormSucceeded(Form $form, ArrayHash $values) {
52: ($values->remember) ? $this->user->setExpiration('3 days', FALSE) :
53: $this->user->setExpiration('20 minutes', TRUE);
54: try {
55: $this->user->login($values->username, $values->password);
56: $this->restoreRequest($this->backlink);
57: $this->homeRedirect();
58: } catch (Nette\Security\AuthenticationException $e) {
59: $form->addError($e->getMessage());
60: }
61: }
62:
63: 64: 65:
66: public function actionOut() {
67: $this->user->logout(TRUE);
68: $this->flashMessage('Uživatel byl odhlášen.');
69: $this->redirect('in');
70: }
71:
72: 73: 74:
75: protected function startup() {
76: parent::startup();
77: if ($this->user->isLoggedIn() && $this->presenter->action === 'in') {
78: $this->homeRedirect();
79: }
80: }
81: 82: 83:
84: private function homeRedirect(){
85: $this->redirect($this->user->identity->data[Cons::USER_HOME], $this->user->identity->data[Cons::USER_SOURCE]);
86: }
87: }
88: