Skip to content
Snippets Groups Projects
Commit a20900fd authored by Sulthan Dzaky Alfaro's avatar Sulthan Dzaky Alfaro
Browse files

make middle ware

parent 7f3b32cd
Branches
Tags
No related merge requests found
<?php
require_once SRC_ROOT_PATH . "/app/exceptions/BadRequestException.php";
require_once SRC_ROOT_PATH . "/app/models/UserModel.php";
class CheckAdmin {
private static $instance;
private function __construct() {}
public static function getInstance() {
if (!isset(self::$instance)) {
self::$instance = new static();
}
return self::$instance;
}
public function __invoke($path,$method){
$admin = UserModel::getInstance()->isAdmin();
if(!$admin){
throw new BadRequestException("You must admin dulu");
}
return true;
}
}
?>
\ No newline at end of file
<?php
require_once SRC_ROOT_PATH . "/app/exceptions/BadRequestException.php";
require_once SRC_ROOT_PATH . "/app/models/UserModel.php";
class CheckLogin {
private static $instance;
private function __construct() {}
public static function getInstance() {
if (!isset(self::$instance)) {
self::$instance = new static();
}
return self::$instance;
}
public function __invoke($path,$method){
if(!isset($_SESSION['user_id'])){
throw new BadRequestException("You must login dulu");
}
return true;
}
}
?>
\ No newline at end of file
......@@ -27,8 +27,8 @@ class LoginModel
$row = $result->fetchAll(PDO::FETCH_ASSOC);
if ($row) {
if(password_verify($password, $row[0]['password_hashed'])){
// $_SESSION['id'] = $row['id'];
// $_SESSION['role'] = $row['role'];
$_SESSION['user_id'] = $row['id'];
$_SESSION['role'] = $row['role'];
return $row[0]['role'];
}
else{
......
......@@ -14,7 +14,7 @@ class UserModel
}
public function isLogin(){
return isset($_SESSION['id']);
return isset($_SESSION['user_id']);
}
protected static $instance;
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment