81 lines
3.5 KiB
PHP
Executable File
81 lines
3.5 KiB
PHP
Executable File
<?php
|
|
/**
|
|
* Admin/auth/login.php
|
|
* تسجيل دخول المشرفين باستخدام البصمة وكلمة المرور المشفرة
|
|
*/
|
|
require_once __DIR__ . '/../../core/bootstrap.php';
|
|
require_once __DIR__ . '/../../functions.php';
|
|
|
|
$fingerprint = filterRequest('fingerprint');
|
|
$password = filterRequest('password');
|
|
$audience = filterRequest('aud') ?? 'admin';
|
|
|
|
if (empty($fingerprint) || empty($password)) {
|
|
jsonError("Fingerprint and password are required.");
|
|
exit;
|
|
}
|
|
|
|
try {
|
|
$con = Database::get('main');
|
|
|
|
// البحث عن المشرف باستخدام بصمة الجهاز (Fingerprint Hash)
|
|
$fpHash = hash('sha256', $fingerprint);
|
|
$stmt = $con->prepare("SELECT * FROM adminUser WHERE fingerprint_hash = :fp LIMIT 1");
|
|
$stmt->execute([':fp' => $fpHash]);
|
|
$admin = $stmt->fetch(PDO::FETCH_ASSOC);
|
|
|
|
if ($admin) {
|
|
// 1. التحقق من حالة الحساب
|
|
if ($admin['status'] === 'pending') {
|
|
jsonError("حسابك قيد المراجعة حالياً. يرجى الانتظار للموافقة.");
|
|
exit;
|
|
} elseif ($admin['status'] === 'suspended') {
|
|
jsonError("هذا الحساب معلق. يرجى التواصل مع المدير.");
|
|
exit;
|
|
} elseif ($admin['status'] === 'rejected') {
|
|
jsonError("تم رفض طلب الانضمام لهذا الحساب.");
|
|
exit;
|
|
}
|
|
|
|
// 2. التحقق من كلمة المرور
|
|
if (password_verify($password, $admin['password'])) {
|
|
|
|
// 3. توليد رمز تحقق OTP وإرساله عبر WhatsApp
|
|
$otp = rand(10000, 99999);
|
|
$phone = $admin['phone'] ?? ''; // تأكد من وجود حقل الهاتف في الجدول
|
|
|
|
if (empty($phone)) {
|
|
// Fallback للأرقام المسموح لها إذا لم يكن الرقم مسجلاً في الجدول
|
|
// (قد نحتاج لتحسين هذه النقطة لاحقاً)
|
|
jsonError("رقم الهاتف غير مسجل لهذا الحساب. يرجى مراجعة الإدارة.");
|
|
exit;
|
|
}
|
|
|
|
$messageBody = "رمز التحقق الخاص بك للدخول إلى لوحة الإدارة هو: $otp";
|
|
$success = sendWhatsAppFromServer($phone, $messageBody);
|
|
|
|
if ($success) {
|
|
// حفظ الرمز في قاعدة البيانات للتحقق لاحقاً
|
|
$stmt = $con->prepare("INSERT INTO token_verification_admin (phone_number, token, expiration_time)
|
|
VALUES (?, ?, DATE_ADD(NOW(), INTERVAL 10 MINUTE))
|
|
ON DUPLICATE KEY UPDATE token = VALUES(token), expiration_time = VALUES(expiration_time)");
|
|
$stmt->execute([$phone, $otp]);
|
|
|
|
printSuccess([
|
|
"status" => "otp_required",
|
|
"message" => "تم إرسال رمز التحقق إلى WhatsApp الخاص بك.",
|
|
"phone" => $phone
|
|
]);
|
|
} else {
|
|
jsonError("فشل في إرسال رمز التحقق عبر WhatsApp.");
|
|
}
|
|
} else {
|
|
jsonError("كلمة المرور غير صحيحة.");
|
|
}
|
|
} else {
|
|
jsonError("الجهاز غير مسجل كمشرف.");
|
|
}
|
|
} catch (Exception $e) {
|
|
error_log("[Admin Login Error] " . $e->getMessage());
|
|
jsonError("خطأ في السيرفر: " . $e->getMessage());
|
|
} |