Correction bug Autorisation dans AdminController
This commit is contained in:
parent
3013d2768c
commit
b0af05880b
@ -11,9 +11,11 @@ namespace app\modules\user\controllers;
|
|||||||
use Piko\HttpException;
|
use Piko\HttpException;
|
||||||
use function Piko\I18n\__;
|
use function Piko\I18n\__;
|
||||||
use Piko\User as PikoUser;
|
use Piko\User as PikoUser;
|
||||||
|
use app\modules\user\Module;
|
||||||
use app\modules\user\models\Role;
|
use app\modules\user\models\Role;
|
||||||
use app\modules\user\models\User;
|
use app\modules\user\models\User;
|
||||||
use app\modules\user\models\Permission;
|
use app\modules\user\models\Permission;
|
||||||
|
use Piko\Controller\Event\BeforeActionEvent;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* User admin controller
|
* User admin controller
|
||||||
@ -36,21 +38,15 @@ class AdminController extends \Piko\Controller
|
|||||||
$db = $app->getComponent('PDO');
|
$db = $app->getComponent('PDO');
|
||||||
assert($db instanceof \PDO);
|
assert($db instanceof \PDO);
|
||||||
$this->db = $db;
|
$this->db = $db;
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
$this->on(BeforeActionEvent::class, function () {
|
||||||
* {@inheritDoc}
|
$module = $this->module;
|
||||||
* @see \piko\Controller::runAction()
|
assert($module instanceof Module);
|
||||||
*/
|
|
||||||
public function runAction($id)
|
|
||||||
{
|
|
||||||
assert($this->module instanceof \app\modules\user\Module);
|
|
||||||
|
|
||||||
if (!$this->user->can($this->module->adminRole)) {
|
if (!$this->user->can($module->adminRole)) {
|
||||||
throw new HttpException('Not authorized.', 403);
|
throw new HttpException(403, 'Not authorized.');
|
||||||
}
|
}
|
||||||
|
});
|
||||||
return parent::runAction($id);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user