1 | <?php |
||
34 | class Bootstrap extends Application |
||
|
|||
35 | { |
||
36 | /** |
||
37 | * {@inheritdoc} |
||
38 | * |
||
39 | * @param Controller $controller |
||
40 | * |
||
41 | * @return void |
||
42 | * @throws \Application\Exception |
||
43 | * @throws \Bluz\Auth\AuthException |
||
44 | * @throws \InvalidArgumentException |
||
45 | */ |
||
46 | protected function preDispatch($controller) |
||
47 | { |
||
48 | // example of setup default title |
||
49 | Layout::title('Bluz Skeleton'); |
||
50 | |||
51 | if (!AuthProxy::getIdentity() && $controller->getModule() !== Router::getErrorModule()) { |
||
52 | if ($token = Request::getCookie('Auth-Token')) { |
||
53 | // try to login by token from cookies |
||
54 | try { |
||
55 | Auth\Provider\Cookie::authenticate($token); |
||
56 | } catch (AuthException $e) { |
||
57 | $this->getResponse()->setCookie('Auth-Token', '', 1, '/'); |
||
58 | } |
||
59 | } elseif ($token = Request::getHeader('Auth-Token')) { |
||
60 | // try to login by token from headers |
||
61 | Auth\Provider\Token::authenticate($token); |
||
62 | } |
||
63 | } |
||
64 | parent::preDispatch($controller); |
||
65 | } |
||
66 | |||
67 | /** |
||
68 | * Denied access |
||
69 | * |
||
70 | * @param ForbiddenException $exception |
||
71 | * |
||
72 | * @return \Bluz\Controller\Controller|null |
||
73 | */ |
||
74 | public function forbidden(ForbiddenException $exception) |
||
92 | |||
93 | /** |
||
94 | * Render with debug headers |
||
95 | * |
||
96 | * @return void |
||
97 | */ |
||
98 | public function render() |
||
114 | |||
115 | /** |
||
116 | * Finish it |
||
117 | * |
||
118 | * @return void |
||
119 | */ |
||
120 | public function end() |
||
126 | |||
127 | /** |
||
128 | * Send information headers |
||
129 | * |
||
130 | * @return void |
||
131 | */ |
||
132 | protected function sendInfoHeaders() |
||
149 | |||
150 | /** |
||
151 | * sendErrorBody |
||
152 | * |
||
153 | * @param array $errors |
||
154 | * |
||
155 | * @return void |
||
156 | */ |
||
157 | protected function sendErrors($errors) |
||
163 | } |
||
164 |