corss(); $rst = []; $rst[] = [ "privilege" => "Admin Lab", "menus" => [ ["title" => "Pasien", "path" => "/masterdata/pasien" ], ["title" => "Pemeriksaan", "path" => "/masterdata/px" ], ] ]; $rst[] = [ "privilege" => "Keu", "menus" => [ ["title" => "Company", "path" => "/masterdata/company" ], ["title" => "Agreement", "path" => "/masterdata/agreement" ], ] ]; echo json_encode(["status" => "OK", "data" => $rst]); } function old_menu() { //for preflight $this->corss(); $rst = [ ["id"=>1,"icon" => "SendIcon","label" => "Menu 01", "target" => "url:/other_module" , "level" => 1], ["id"=>2,"icon" => "DrafsIcon","label" => "Menu 02", "target" => "", "level" => 1, "children" => [ ["id"=>3,"icon" => "DrafsIcon","label" => "Sub Menu 0201", "target" => "link:/def", "level" => 2,], ["id"=>4,"icon" => "StarIcon","label" => "Sub Menu 0202", "target" => "link:/def", "level" => 2], ["id"=>5,"icon" => "InboxIcon","label" => "Sub Menu 0203", "target" => "link:/def", "level" => 2], ["id"=>6,"icon" => "","label" => "Sub Menu 0204", "target" => "link:/def", "level" => 2, "children" => [ ["id"=>7,"icon" => "DrafsIcon","label" => "Sub Menu 020401", "target" => "link:/def", "level" => 3], ["id"=>8,"icon" => "StarIcon","label" => "Sub Menu 020402", "target" => "link:/def", "level" => 3], ["id"=>9,"icon" => "InboxIcon","label" => "Sub Menu 020403", "target" => "link:/def", "level" => 3], ["id"=>10,"icon" => "","label" => "Sub Menu 020404", "target" => "link:/def" , "level" => 3], ], ] ], ], ["id"=>11,"icon" => "InboxIcon","label" => "Menu 03", "target" => "url:/other_module", "level" => 1 ], ["id"=>12,"icon" => "StarIcon","label" => "Menu 04", "target" => "url:/other_module", "level" => 1 ], ["id"=>13,"icon" => "SendIcon","label" => "Menu 05", "target" => "url:/other_module" , "level" => 1], ]; echo json_encode(["status"=>"OK","records" => $rst ]); } function check_token() { $req_headers = $headers = array_change_key_case(getallheaders(), CASE_LOWER); $isLogin = false; $user = []; if (isset($req_headers["authorization"])) { //have bearer list($bearer, $token) = explode(" ", trim($req_headers["authorization"])); $user =JWT::decode($token,$this->SECRET_KEY); $isLogin = true; } return [$isLogin,$user]; } function info() { list($isLogin,$user) = $this->check_token(); echo json_encode(["isLogin" => $isLogin,"user" => $user]); } function refresh_token () { list($isLogin,$user) = $this->check_token(); if (! $isLogin) { $this->sys_error("Invalid Token"); } else { $token_expire = date("Y-m-d H:i:s",strtotime("now + 5 minute")); $user["token_expire"] = $token_expire; $token = JWT::encode($user,$this->SECRET_KEY); $data = array( "status" => "OK", "user" => $user, "token" => $token, "token_expire" => $token_expire ); echo json_encode($data); } } function login() { $this->corss(); $prm = json_decode(file_get_contents("php://input"),true); if ($prm["username"] =="admin" && $prm["password"] == "123") { $token_expire = date("Y-m-d H:i:s",strtotime("now + 5 minute")); $user = ["name" => "The Admin" , "level" => "Admin", "expire" => $token_expire]; $this->load->library("Jwt"); $token = JWT::encode($user,$this->SECRET_KEY); echo json_encode([ "status" => "OK", "token" => $token, "token_expire" => $token_expire, "redirect" => "/xinfo", "user" => $user ]); exit; } echo json_encode(["status" => "ERR" , "message" => "Invalid username/password"]); } function logout() { echo json_encode(["status" => "OK" , "message" => ""]); } } ?>