facut pana la video 7
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace app\core\middlewares;
|
||||
use app\core\Application;
|
||||
use app\core\exceptions\ForbiddenException;
|
||||
|
||||
class AuthMiddleware extends BaseMiddleware{
|
||||
public array $actions = [];
|
||||
|
||||
public function __construct(array $actions = []){
|
||||
$this->actions = $actions;
|
||||
}
|
||||
|
||||
public function execute(){
|
||||
if(Application::isLoggedIn()){
|
||||
if(empty($this->actions) || in_array(Application::$app->controller->action, $this->actions)){
|
||||
throw new ForbiddenException;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
<?php
|
||||
|
||||
namespace app\core\middlewares;
|
||||
|
||||
abstract class BaseMiddleware{
|
||||
abstract public function execute();
|
||||
}
|
||||
Reference in New Issue
Block a user