Initial commit with updated Auth and media ignored
This commit is contained in:
46
Admin/auth/verify_otp_admin.php
Executable file
46
Admin/auth/verify_otp_admin.php
Executable file
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/../../connect.php';
|
||||
|
||||
$phone = filterRequest("phone_number");
|
||||
$otp = filterRequest("otp");
|
||||
$deviceNumber = filterRequest("device_number");
|
||||
|
||||
if (empty($phone) || empty($otp)) {
|
||||
jsonError("رقم الهاتف أو رمز التحقق مفقود.");
|
||||
exit;
|
||||
}
|
||||
|
||||
// التحقق من رمز التحقق (OTP)
|
||||
$stmt = $con->prepare("SELECT * FROM token_verification_admin
|
||||
WHERE phone_number = ? AND token = ?
|
||||
AND expiration_time >= NOW()");
|
||||
$stmt->execute([$phone, $otp]);
|
||||
|
||||
if ($stmt->rowCount() > 0) {
|
||||
// ✅ تحقق ناجح - ننتقل إلى إدخال أو تحديث سجل adminUser
|
||||
|
||||
// تحقق إن كان المستخدم موجود مسبقًا
|
||||
$checkAdmin = $con->prepare("SELECT * FROM adminUser WHERE name = ?");
|
||||
$checkAdmin->execute([$phone]);
|
||||
|
||||
$now = date("Y-m-d H:i:s");
|
||||
|
||||
if ($checkAdmin->rowCount() > 0) {
|
||||
// المستخدم موجود ✅ تحديث device_number و updated_at
|
||||
$update = $con->prepare("UPDATE adminUser
|
||||
SET device_number = ?, updated_at = ?
|
||||
WHERE name = ?");
|
||||
$update->execute([$deviceNumber, $now, $phone]);
|
||||
jsonSuccess(["message" => "verified and updated existing admin"]);
|
||||
} else {
|
||||
// المستخدم غير موجود ✅ إدخال جديد
|
||||
$insert = $con->prepare("INSERT INTO adminUser (device_number, name, created_at, updated_at)
|
||||
VALUES (?, ?, ?, ?)");
|
||||
$insert->execute([$deviceNumber, $phone, $now, $now]);
|
||||
jsonSuccess(["message" => "verified and new admin created"]);
|
||||
}
|
||||
|
||||
} else {
|
||||
// ❌ رمز التحقق غير صالح
|
||||
jsonError("رمز التحقق غير صالح أو منتهي.");
|
||||
}
|
||||
Reference in New Issue
Block a user