Fixed login/logout issue
This commit is contained in:
@@ -52,46 +52,60 @@ class Router
|
||||
public function dispatch($url)
|
||||
{
|
||||
// Check token
|
||||
if (isset($_SERVER['HTTP_X-Token'])) {
|
||||
if (!$this->checkToken($_SERVER['HTTP_X-Token'])) {
|
||||
if (isset($_SERVER['HTTP_X_Token'])) {
|
||||
if (!$this->checkToken($_SERVER['HTTP_X_Token'])) {
|
||||
// Logout
|
||||
$controller = 'Home';
|
||||
$controller = $this->getNamespace($controller);
|
||||
$obj = new $controller();
|
||||
$obj->logout();
|
||||
|
||||
Redirect::to('/mithril');
|
||||
Redirect::to('/');
|
||||
}
|
||||
}
|
||||
|
||||
$query_string = $this->getQueryStringVariable($url);
|
||||
if ($query_string) {
|
||||
$sessid = explode('=', $query_string[0]);
|
||||
$sessid = $sessid[1];
|
||||
$userid = explode('=', $query_string[1]);
|
||||
$userid = $userid[1];
|
||||
if ($url != '/login' && $url != '/') {
|
||||
$query_string = $this->getQueryStringVariable($url);
|
||||
if ($query_string) {
|
||||
$sessid = explode('=', $query_string[0]);
|
||||
$sessid = $sessid[1];
|
||||
$userid = explode('=', $query_string[1]);
|
||||
$userid = $userid[1];
|
||||
|
||||
// Check if user login
|
||||
if (is_array(\App\Models\ClientSession::fetch([
|
||||
'uid' => $userid,
|
||||
'id' => $sessid
|
||||
]))) {
|
||||
$token = Token::generate($userid);
|
||||
header("X-Token: $token");
|
||||
}
|
||||
} elseif ($query_string == false) {
|
||||
// echo ['status' => true, 'message' => 'atas'];die();
|
||||
// Get user ip
|
||||
$ip_address = isset($_SERVER['HTTP_X_FORWADED_FOR']) ? $_SERVER['HTTP_X_FORWADED_FOR'] : $_SERVER['REMOTE_ADDR'];
|
||||
$record = \App\Models\ClientSession::fetch(['ip_address' => $ip_address]);
|
||||
if (is_array($record)) {
|
||||
$obj = 'Home';
|
||||
$obj = $this->getNamespace($obj);
|
||||
$obj = new $obj();
|
||||
$obj->logout($record['uid']);
|
||||
header('Location: http://lepisi.dev/mithril');
|
||||
// Redirect::to('/mithril');
|
||||
die();
|
||||
// Check if user login
|
||||
$session = \App\Models\ClientSession::fetch([
|
||||
'uid' => $userid,
|
||||
'id' => $sessid
|
||||
]);
|
||||
if (is_array($session)) {
|
||||
$token = Token::generate($userid);
|
||||
header("X-Token: $token");
|
||||
} else {
|
||||
$ip_address = isset($_SERVER['HTTP_X_FORWADED_FOR']) ? $_SERVER['HTTP_X_FORWADED_FOR'] : $_SERVER['REMOTE_ADDR'];
|
||||
$record = \App\Models\ClientSession::fetch(['ip_address' => $ip_address]);
|
||||
$obj = 'Home';
|
||||
$obj = $this->getNamespace($obj);
|
||||
if (is_array($record)) {
|
||||
$obj = new $obj();
|
||||
$obj->logout($record['uid']);
|
||||
die();
|
||||
} else {
|
||||
$obj = new $obj();
|
||||
$obj->logout($userid);
|
||||
}
|
||||
header('Location: /');
|
||||
}
|
||||
} elseif ($query_string == false) {
|
||||
$ip_address = isset($_SERVER['HTTP_X_FORWADED_FOR']) ? $_SERVER['HTTP_X_FORWADED_FOR'] : $_SERVER['REMOTE_ADDR'];
|
||||
$record = \App\Models\ClientSession::fetch(['ip_address' => $ip_address]);
|
||||
if (is_array($record)) {
|
||||
$obj = 'Home';
|
||||
$obj = $this->getNamespace($obj);
|
||||
$obj = new $obj();
|
||||
$obj->logout($record['uid']);
|
||||
header('Location: /');
|
||||
die();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -151,7 +165,7 @@ class Router
|
||||
return $parts[0];
|
||||
}
|
||||
|
||||
private function getQueryStringVariable($url)
|
||||
protected function getQueryStringVariable($url)
|
||||
{
|
||||
$exploded = explode('?', $url);
|
||||
if (isset($exploded[1])) {
|
||||
|
||||
@@ -12,12 +12,48 @@ class RouterApi extends Router
|
||||
// Logout
|
||||
$obj = new Home();
|
||||
$obj->logout();
|
||||
header('Location: /mithril');
|
||||
header('Location: /');
|
||||
}
|
||||
// $request = Token::generate(2);
|
||||
// var_dump($request, Token::validate($request));
|
||||
// return true;
|
||||
|
||||
if (isset($_SERVER['HTTP_X_QUERY'])) {
|
||||
// $obj = new Home();
|
||||
// $obj->logout();
|
||||
// header('Location: /');
|
||||
$query_string = $this->getQueryStringVariable($_SERVER['HTTP_X_QUERY']);
|
||||
$sessid = explode('=', $query_string[0]);
|
||||
$sessid = $sessid[1];
|
||||
$userid = explode('=', $query_string[1]);
|
||||
$userid = $userid[1];
|
||||
|
||||
// Check if user login
|
||||
$session = \App\Models\ClientSession::fetch([
|
||||
'uid' => $userid,
|
||||
'id' => $sessid
|
||||
]);
|
||||
|
||||
if (is_array($session)) {
|
||||
$token = Token::generate($userid);
|
||||
header("X-Token: $token");
|
||||
} else {
|
||||
$response = [];
|
||||
$response['status'] = 401;
|
||||
$response['message'] = 'Unauthorized';
|
||||
echo json_encode($response); die();
|
||||
// $ip_address = isset($_SERVER['HTTP_X_FORWADED_FOR']) ? $_SERVER['HTTP_X_FORWADED_FOR'] : $_SERVER['REMOTE_ADDR'];
|
||||
// $record = \App\Models\ClientSession::fetch(['ip_address' => $ip_address]);
|
||||
// $obj = 'Home';
|
||||
// $obj = $this->getNamespace($obj);
|
||||
// if (is_array($record)) {
|
||||
// $obj = new $obj();
|
||||
// $obj->logout($record['uid']);
|
||||
// } else {
|
||||
// $obj = new $obj();
|
||||
// $obj->logout($userid);
|
||||
// }
|
||||
// header('Location: /');
|
||||
die();
|
||||
}
|
||||
}
|
||||
|
||||
$object = new Api();
|
||||
if (isset($this->params['action'])) {
|
||||
|
||||
Reference in New Issue
Block a user