Skip to content
This repository has been archived by the owner on Jan 13, 2024. It is now read-only.

Commit

Permalink
bug fix and improve
Browse files Browse the repository at this point in the history
bug fix lock screen
improve auth api
  • Loading branch information
fherryfherry committed Sep 20, 2016
1 parent d7b5a31 commit f83ffc2
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 59 deletions.
4 changes: 1 addition & 3 deletions src/controllers/ApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,7 @@ public function hook_api_message($message) {
$this->hook_api_message = $message;
}

public function execute_api() {
auth_api();

public function execute_api() {
$this->init_setting();

$posts = Request::all();
Expand Down
56 changes: 1 addition & 55 deletions src/middlewares/CBAuthAPI.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,61 +21,7 @@ public function handle($request, Closure $next)
{


$screetkey = Cache::get('screetkey');
$useragent = $_SERVER['HTTP_USER_AGENT'];

if( get_setting('api_debug_mode') == 'false') {

$result = array();
$validator = Validator::make(
[
'screetkey' =>$screetkey,
'useragent' =>$useragent,
'X-Authorization-Token' =>Request::header('X-Authorization-Token'),
'X-Authorization-Time' =>Request::header('X-Authorization-Time')
],
[
'screetkey' =>'required',
'useragent' =>'required',
'X-Authorization-Token' =>'required',
'X-Authorization-Time' =>'required',
]
);

if ($validator->fails())
{
$message = $validator->errors()->all();
$result['api_status'] = 0;
$result['api_message'] = implode(', ',$message);
response()->json($result,400)->send();
exit;
}

//verifikasi trust token
$token_md5 = md5($screetkey.Request::header('X-Authorization-Time').$useragent);

$your_data = array('screetkey'=>$screetkey,'token'=>Request::header('X-Authorization-Token'),'time'=>Request::header('X-Authorization-Time'));

//Check token is expired or not
if(Cache::has('api_token_'.$token_md5)) {
response()->json(['api_status'=>0,'api_message'=>'TOKEN_EXPIRED','YOUR_DATA'=>$your_data],401)->send();
exit;
}

if($token_md5 != Request::header('X-Authorization-Token')) {
$result['api_status'] = 0;
$result['api_message'] = "INVALID_TOKEN";
$result['YOUR_DATA'] = $your_data;
$res = response()->json($result,401);
$res->send();
exit;
}else{

//Save token to cache
Cache::put('api_token_'.$token_md5,$token_md5,3600);
}

} //end debug
auth_api();

return $next($request);
}
Expand Down
2 changes: 1 addition & 1 deletion src/middlewares/CBBackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function handle($request, Closure $next)
return redirect($url)->with('message','You are not logged in !');
}
if(get_is_locked()){
$url = url($admin_path.'/lockscreen');
$url = url($admin_path.'/lock-screen');
return redirect($url);
}

Expand Down

0 comments on commit f83ffc2

Please sign in to comment.