Skip to content

Commit

Permalink
bug(middleware)
Browse files Browse the repository at this point in the history
  • Loading branch information
mohamadreza1388 committed Sep 11, 2024
1 parent c9739fa commit 83fc10f
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions app/Middleware/mvc/Login.php
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}
}

0 comments on commit 83fc10f

Please sign in to comment.