diff --git a/app/Middleware/mvc/Login.php b/app/Middleware/mvc/Login.php index 1bd1c21..27d30fe 100644 --- a/app/Middleware/mvc/Login.php +++ b/app/Middleware/mvc/Login.php @@ -10,9 +10,19 @@ class Login extends Controller public function before(): void { if (array_key_exists('token', $_COOKIE)) { - dd("Token exists: " . $_COOKIE['token']); + $header_token = $_COOKIE['token']; + $db = Flight::db(); + $tokenCount = $db->prepare('SELECT COUNT(*) as token_count FROM tokens WHERE `token` = :token'); + $tokenCount->execute([ + ':token' => $header_token, + ]); + $result = $tokenCount->fetchAll(); + $result = end($result)['token_count']; + if (intval($result) === 0) { + Flight::redirect("https://editor.salamlang.ir"); + } } else { - dd("Token not set."); + Flight::redirect("https://editor.salamlang.ir"); } } }