Skip to content

Commit

Permalink
Check Login
Browse files Browse the repository at this point in the history
  • Loading branch information
douglas committed Feb 19, 2020
1 parent c27992a commit b5be604
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 6 deletions.
1 change: 0 additions & 1 deletion app/Model/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ class User extends Model
public function user(){
$id = $_SESSION["loginInfo"]["idUser"];
$user = $this->select()->where("id",$id)->first();

return $user;
}
}
2 changes: 1 addition & 1 deletion bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@
$whoops = new Whoops();
$whoops->run($container);

$middleware = new Middleware();
$middleware = new Middleware();
2 changes: 1 addition & 1 deletion phinx.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ environments:
host: localhost
name: twig_slim
user: root
pass: 'nokia5233'
pass: '1475'
port: 3306
charset: utf8

Expand Down
2 changes: 1 addition & 1 deletion public/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down
25 changes: 23 additions & 2 deletions src/Middleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ class Middleware
{



public function auth($role){
public function auth($role){

$config = Load::file("/config.php");

Expand All @@ -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;
}

}

0 comments on commit b5be604

Please sign in to comment.