Overview

Namespaces

  • App
    • Components
    • Interfaces
    • Lib
      • Files
      • Forms
        • Controls
      • Html
      • Repair
      • Statics
    • Model
    • Modules
      • BaseModule
        • Presenters
      • PartnersModule
        • Presenters
      • ProductModule
        • Presenters
      • SaleModule
        • Model
        • Presenters
      • SettingsModule
        • Model
        • Presenters
      • StoreModule
        • Model
        • Presenters
    • Presenters
    • Router
  • PHP

Classes

  • DateTime
  • SplFileInfo

Interfaces

  • ArrayAccess
  • Countable
  • Exception
  • Iterator
  • Traversable
  • Overview
  • Namespace
  • Class
  • Tree
  • Deprecated
  • Download
 1: <?php
 2: 
 3: 
 4: /**
 5:  * Project sberp
 6:  *
 7:  * @file SignPresenter
 8:  * @author Jaromír Polášek
 9:  * @version 0.7.6.RELATION
10:  * Encoding UTF-8
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:  * Přihlašovací / odhlašovací presenter
23:  * Sign in/out presenters.
24:  */
25: class SignPresenter extends BasePresenter {
26:     
27:     /** @persistent */
28:     public $backlink = '';
29: 
30:     /**
31:      * Přihlašovací form factory.
32:      * @return Nette\Application\UI\Form
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:      * Přijetí formuláře
48:      * @param \Nette\Application\UI\Form $form
49:      * @param \Nette\Utils\ArrayHash $values
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:      * Odhlášení uživatele
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:      * Kontrola přihlášení a následné přesměrování
74:      */
75:     protected function startup() {
76:     parent::startup();
77:     if ($this->user->isLoggedIn() && $this->presenter->action === 'in') {
78:         $this->homeRedirect();
79:     }
80:     }
81:     /**
82:      * Přesměruje uživatele na jeho výchozí presenter
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: 
sberp API API documentation generated by ApiGen