Spaces:
Running
Running
File size: 839 Bytes
84e853d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
```php
<?php
require_once 'config.php';
use Firebase\JWT\JWT;
// Handle admin login
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$data = json_decode(file_get_contents("php://input"));
// Validate admin credentials
if($data->username === 'admin' && $data->password === 'admin123') {
$token = array(
"iss" => "cebelarstvo_cigoj",
"iat" => time(),
"exp" => time() + (60 * 60),
"data" => array(
"username" => "admin",
"role" => "admin"
)
);
$jwt = JWT::encode($token, JWT_SECRET);
echo json_encode(array("success" => true, "token" => $jwt));
} else {
http_response_code(401);
echo json_encode(array("success" => false, "message" => "Invalid credentials"));
}
}
?>
``` |