Initial commit with updated Auth and media ignored
This commit is contained in:
38
auth/google_auth/check_status.php
Executable file
38
auth/google_auth/check_status.php
Executable file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
// File: check_status.php
|
||||
// هذا الملف الذي سيقوم التطبيق بالاتصال به بشكل دوري.
|
||||
// يتحقق من حالة الجلسة ويرجع البيانات عند نجاحها.
|
||||
|
||||
header('Content-Type: application/json');
|
||||
|
||||
// 1. استقبال الـ loginToken من التطبيق
|
||||
$input = json_decode(file_get_contents('php://input'), true);
|
||||
if (!isset($input['loginToken'])) {
|
||||
http_response_code(400);
|
||||
echo json_encode(['status' => 'error', 'message' => 'Login token is missing.']);
|
||||
exit();
|
||||
}
|
||||
$loginToken = basename($input['loginToken']); // حماية
|
||||
|
||||
// 2. التحقق من ملف الجلسة
|
||||
$pollDir = __DIR__ . '/polls';
|
||||
$sessionFile = $pollDir . '/' . $loginToken . '.json';
|
||||
|
||||
if (file_exists($sessionFile)) {
|
||||
$sessionData = json_decode(file_get_contents($sessionFile), true);
|
||||
|
||||
// إذا نجحت العملية، أرجع البيانات واحذف الملف
|
||||
if ($sessionData['status'] === 'success') {
|
||||
echo json_encode($sessionData);
|
||||
unlink($sessionFile); // حذف الملف بعد النجاح
|
||||
} else {
|
||||
// إذا كانت لا تزال معلقة
|
||||
echo json_encode(['status' => 'pending']);
|
||||
}
|
||||
} else {
|
||||
// إذا انتهت المهلة أو حدث خطأ
|
||||
http_response_code(404);
|
||||
echo json_encode(['status' => 'expired', 'message' => 'Session not found or expired.']);
|
||||
}
|
||||
exit();
|
||||
?>
|
||||
Reference in New Issue
Block a user