1: <?php
2: namespace Budovy;
3:
4: use Nette;
5:
6: /**
7: * Base presenter for all application presenters.
8: */
9: abstract class BasePresenter extends Nette\Application\UI\Presenter {
10: /** @var \WebLoader\LoaderFactory @inject */
11: public $webLoader;
12:
13: /** @var RoleRepository @inject */
14: public $roleRepository;
15:
16: protected function startup() {
17: parent::startup();
18:
19: $this->checkLogin();
20: }
21:
22: protected function checkLogin() {
23: if (!$this->getUser()->isLoggedIn()) {
24: $this->redirect('Sign:in');
25: }
26:
27: if (!$this->roleRepository->isAllowed($this->getUser(), $this->getName(), $this->getAction(), $this->getParameter('do'))) {
28: $this->flashMessage('Nemáte oprávnění na provedení akce', 'error');
29:
30: $this->redirect('Homepage:default');
31: }
32: }
33:
34: /** @return CssLoader */
35: protected function createComponentCss() {
36: return $this->webLoader->createCssLoader('default');
37: }
38:
39: /** @return JavaScriptLoader */
40: protected function createComponentJs() {
41: return $this->webLoader->createJavaScriptLoader('default');
42: }
43: }