1: <?php
2: 3: 4: 5:
6:
7: use Nette\Application\UI,
8: Nette\Security as NS;
9: 10: 11:
12: class SignPresenter extends Nette\Application\UI\Presenter
13: {
14:
15: public $backlink = '';
16:
17: 18: 19: 20:
21: protected function createComponentSignInForm()
22: {
23: $form = new UI\Form;
24: $form->addText('username', 'Přihlašovací jméno',30)
25: ->setRequired('Vyplňte přihlašovací jméno');
26:
27: $form->addPassword('password', 'Heslo',30)
28: ->setRequired('Vyplňte heslo');
29:
30: $form->addCheckbox('remember', 'Zapamatovat si mě na tomto počítači');
31:
32: $form->addSubmit('send', 'Přihlásit');
33:
34: $form->onSuccess[] = callback($this, 'signInFormSubmitted');
35: return $form;
36: }
37:
38:
39: 40: 41: 42: 43:
44: public function signInFormSubmitted($form)
45: {
46: try {
47: $values = $form->getValues();
48: if ($values->remember) {
49: $this->getUser()->setExpiration('+ 14 days', FALSE);
50: } else {
51: $this->getUser()->setExpiration('+ 20 minutes', TRUE);
52: }
53: $this->getUser()->login($values->username, $values->password);
54: $this->application->restoreRequest($this->backlink);
55: $this->redirect('Cekarna:view');
56:
57: } catch (NS\AuthenticationException $e) {
58: $form->addError($e->getMessage());
59: }
60: }
61:
62: 63: 64: 65:
66: public function actionOut()
67: {
68: $this->getUser()->logout();
69: $this->flashMessage('Byl jste odhlášen');
70: $this->redirect('in');
71: }
72:
73: }