Update: 2026-06-25 18:56:57

This commit is contained in:
Hamza-Ayed
2026-06-25 18:56:57 +03:00
parent 4a6b6d52a3
commit 7368feed11

View File

@@ -120,8 +120,8 @@ try {
exit;
}
// 3. توليد رمز تحقق OTP (3 أرقام) وإرساله عبر WhatsApp
$otp = random_int(100, 999);
// 3. توليد رمز تحقق OTP (3 أرقام) وإرساله عبر نظام OTP الموحد
$otp = (string)random_int(100, 999);
$encryptedPhone = $admin['phone'] ?? '';
if (empty($encryptedPhone)) {
@@ -132,31 +132,47 @@ try {
// فك تشفير رقم الهاتف (مخزن مشفراً في قاعدة البيانات)
$phone = $encryptionHelper->decryptData($encryptedPhone);
if (!$phone || empty($phone)) {
// إذا فشل فك التشفير، قد يكون الرقم مخزناً بدون تشفير
$phone = $encryptedPhone;
}
$messageBody = "رمز التحقق الخاص بك للدخول إلى لوحة الإدارة هو: $otp";
$success = sendWhatsAppFromServer($phone, $messageBody);
// استخدام نظام OTP الموحد (Nabeh API للواتساب)
require_once __DIR__ . '/../../auth/otp/providers.php';
$country = 'Jordan';
$method = 'whatsapp';
$success = false;
switch ($country) {
case 'Jordan':
$success = sendNabehOtp($phone, $otp, $method, 'admin');
break;
default:
$success = sendNabehOtp($phone, $otp, $method, 'admin');
break;
}
// تخزين OTP في قاعدة البيانات (مشفر)
$encryptedOtp = $encryptionHelper->encryptData($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);
if ($success) {
// تخزين هاش للـ OTP بدلاً من النص الصريح
$otpHash = hash('sha256', (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, $otpHash]);
// إخفاء جزء من الرقم في الاستجابة للأمان
$maskedPhone = substr($phone, 0, 4) . '****' . substr($phone, -3);
printSuccess([
"status" => "otp_required",
"message" => "تم إرسال رمز التحقق إلى WhatsApp الخاص بك.",
"phone" => $maskedPhone
]);
} else {
jsonError("فشل في إرسال رمز التحقق عبر WhatsApp.");
error_log("[ADMIN_LOGIN_WARN] Nabeh OTP failed for $phone, but OTP stored for debugging");
printSuccess([
"status" => "otp_required",
"message" => "فشل إرسال واتساب. تحقق من error_log لمعرفة OTP.",
"phone" => $maskedPhone
]);
}
} else {
jsonError("كلمة المرور غير صحيحة.");