1
|
<?php
|
2
|
|
3
|
|
4
|
namespace App\AdminModule\Presenters;
|
5
|
|
6
|
use App\Enum\EUserRole;
|
7
|
use Nette;
|
8
|
|
9
|
/**
|
10
|
* Základní presenter od kterého dědí všechny presentery v AdminModulu,
|
11
|
* zajišťuje kontrolu práv uživatele
|
12
|
*
|
13
|
* @package App\AdminModule\Presenters
|
14
|
*/
|
15
|
abstract class BaseAdminPresenter extends Nette\Application\UI\Presenter
|
16
|
{
|
17
|
|
18
|
public function startup()
|
19
|
{
|
20
|
parent::startup();
|
21
|
|
22
|
if (!$this->isUserAllowed())
|
23
|
{
|
24
|
throw new Nette\Application\ForbiddenRequestException();
|
25
|
}
|
26
|
}
|
27
|
|
28
|
/**
|
29
|
* Vrací TRUE pokud má uživatel přístup do administrace
|
30
|
*
|
31
|
* @return bool
|
32
|
*/
|
33
|
protected function isUserAllowed()
|
34
|
{
|
35
|
return $this->user->isLoggedIn() && $this->user->isInRole(EUserRole::ADMIN);
|
36
|
}
|
37
|
}
|