diff --git a/app/Model/User.php b/app/Model/User.php index ac8f72c..9e2f477 100755 --- a/app/Model/User.php +++ b/app/Model/User.php @@ -13,7 +13,6 @@ class User extends Model public function user(){ $id = $_SESSION["loginInfo"]["idUser"]; $user = $this->select()->where("id",$id)->first(); - return $user; } } \ No newline at end of file diff --git a/bootstrap.php b/bootstrap.php index d82d9db..d32cda0 100755 --- a/bootstrap.php +++ b/bootstrap.php @@ -36,4 +36,4 @@ $whoops = new Whoops(); $whoops->run($container); -$middleware = new Middleware(); +$middleware = new Middleware(); \ No newline at end of file diff --git a/phinx.yml b/phinx.yml index 152fc11..e11a407 100755 --- a/phinx.yml +++ b/phinx.yml @@ -19,7 +19,7 @@ environments: host: localhost name: twig_slim user: root - pass: 'nokia5233' + pass: '1475' port: 3306 charset: utf8 diff --git a/public/index.php b/public/index.php index 14ad6ab..7b58016 100755 --- a/public/index.php +++ b/public/index.php @@ -3,7 +3,7 @@ require __DIR__ . "/../bootstrap.php"; //var_dump($_SESSION); -$app->get("/login","LoginController:index"); +$app->get("/login","LoginController:index")->add($middleware->checkLoggedIn()); $app->post("/login","LoginController:store"); $app->get("/logout","LoginController:destroy"); diff --git a/src/Middleware.php b/src/Middleware.php index 87c8802..6a7cc02 100644 --- a/src/Middleware.php +++ b/src/Middleware.php @@ -12,8 +12,7 @@ class Middleware { - - public function auth($role){ + public function auth($role){ $config = Load::file("/config.php"); @@ -37,4 +36,26 @@ public function auth($role){ return $admin; } + + + public function checkLoggedIn() + { + + $config = Load::file("/config.php"); + + $checkLogin = function (Request $request, Response $response, $next) use($config){ + if(isset($_SESSION["loginInfo"])) { + foreach ($config["permission"] as $key => $value) { + if ($_SESSION["loginInfo"]["roleUser"] == $key) { + return $response->withRedirect($value); + } + } + }else{ + return $response = $next($request, $response); + } + }; + + return $checkLogin; + } + } \ No newline at end of file