91 lines
4.0 KiB
PHP
Executable File
91 lines
4.0 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);
|
|
$encryptedPhone = $admin['phone'] ?? '';
|
|
|
|
if (empty($encryptedPhone)) {
|
|
jsonError("رقم الهاتف غير مسجل لهذا الحساب. يرجى مراجعة الإدارة.");
|
|
exit;
|
|
}
|
|
|
|
// فك تشفير رقم الهاتف (مخزن مشفراً في قاعدة البيانات)
|
|
$phone = $encryptionHelper->decryptData($encryptedPhone);
|
|
if (!$phone || empty($phone)) {
|
|
// إذا فشل فك التشفير، قد يكون الرقم مخزناً بدون تشفير
|
|
$phone = $encryptedPhone;
|
|
}
|
|
|
|
$messageBody = "رمز التحقق الخاص بك للدخول إلى لوحة الإدارة هو: $otp";
|
|
$success = sendWhatsAppFromServer($phone, $messageBody);
|
|
|
|
if ($success) {
|
|
// حفظ الرمز مشفراً في قاعدة البيانات (وحفظ رقم الهاتف مشفراً أيضاً)
|
|
$encryptedOtp = $encryptionHelper->encryptData((string)$otp);
|
|
|
|
$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([$encryptedPhone, $encryptedOtp]);
|
|
|
|
// إخفاء جزء من الرقم في الاستجابة للأمان
|
|
$maskedPhone = substr($phone, 0, 4) . '****' . substr($phone, -3);
|
|
|
|
printSuccess([
|
|
"status" => "otp_required",
|
|
"message" => "تم إرسال رمز التحقق إلى WhatsApp الخاص بك.",
|
|
"phone" => $maskedPhone
|
|
]);
|
|
} else {
|
|
jsonError("فشل في إرسال رمز التحقق عبر WhatsApp.");
|
|
}
|
|
} else {
|
|
jsonError("كلمة المرور غير صحيحة.");
|
|
}
|
|
} else {
|
|
jsonError("الجهاز غير مسجل كمشرف.");
|
|
}
|
|
} catch (Exception $e) {
|
|
error_log("[Admin Login Error] " . $e->getMessage());
|
|
jsonError("خطأ في السيرفر: " . $e->getMessage());
|
|
} |