admin 4
This commit is contained in:
@@ -8,16 +8,14 @@ require_once __DIR__ . '/../../core/bootstrap.php';
|
|||||||
$con = Database::get('main');
|
$con = Database::get('main');
|
||||||
|
|
||||||
// التحقق من الصلاحيات: فقط المشرفين يمكنهم الإضافة
|
// التحقق من الصلاحيات: فقط المشرفين يمكنهم الإضافة
|
||||||
// إذا لم يكن هناك أي مدير في النظام، نسمح بالإضافة الأولى لإعداد النظام
|
// إذا لم يكن هناك أي مدير في النظام، نسمح// تم تعطيل التحقق للسماح بإعادة التهيئة في مرحلة التطوير
|
||||||
$adminCount = $con->query("SELECT COUNT(*) FROM adminUser")->fetchColumn();
|
// $count = $con->query("SELECT COUNT(*) FROM adminUser")->fetchColumn();
|
||||||
if ($adminCount > 0) {
|
// if ($count > 0) die("Access Denied: Admin already initialized.");
|
||||||
// تفعيل المصادقة هنا لاحقاً لضمان الأمان
|
|
||||||
// $auth = JwtService::authenticate($redis);
|
// $auth = JwtService::authenticate($redis);
|
||||||
// if ($auth['role'] !== 'super_admin' && $auth['role'] !== 'admin') {
|
// if ($auth['role'] !== 'super_admin' && $auth['role'] !== 'admin') {
|
||||||
// jsonError("Unauthorized. Only Admins can add staff.");
|
// jsonError("Unauthorized. Only Admins can add staff.");
|
||||||
// exit;
|
// exit;
|
||||||
// }
|
// }
|
||||||
}
|
|
||||||
|
|
||||||
$name = filterRequest("name");
|
$name = filterRequest("name");
|
||||||
$phone = filterRequest("phone");
|
$phone = filterRequest("phone");
|
||||||
@@ -41,24 +39,33 @@ try {
|
|||||||
$encPhone = $encryptionHelper->encryptData($phone);
|
$encPhone = $encryptionHelper->encryptData($phone);
|
||||||
$encEmail = $encryptionHelper->encryptData($email);
|
$encEmail = $encryptionHelper->encryptData($email);
|
||||||
|
|
||||||
|
// تشفير البصمة وهش البصمة
|
||||||
|
$encFp = $encryptionHelper->encryptData($fingerprint);
|
||||||
|
$fpHash = hash('sha256', $fingerprint);
|
||||||
|
$uniqueId = bin2hex(random_bytes(16));
|
||||||
|
|
||||||
if ($role === 'admin') {
|
if ($role === 'admin') {
|
||||||
// الإضافة لجدول المديرين
|
// الإضافة لجدول المديرين
|
||||||
$sql = "INSERT INTO adminUser (id, fingerprint, name, password, role, created_at)
|
$sql = "INSERT INTO adminUser (id, fingerprint, fingerprint_hash, name, password, role, created_at)
|
||||||
VALUES (UUID(), :fp, :name, :pass, :role, NOW())";
|
VALUES (:id, :fp, :fp_hash, :name, :pass, :role, NOW())";
|
||||||
$stmt = $con->prepare($sql);
|
$stmt = $con->prepare($sql);
|
||||||
$stmt->execute([
|
$stmt->execute([
|
||||||
':fp' => $fingerprint,
|
':id' => $uniqueId,
|
||||||
|
':fp' => $encFp,
|
||||||
|
':fp_hash' => $fpHash,
|
||||||
':name' => $encName,
|
':name' => $encName,
|
||||||
':pass' => $hashedPassword,
|
':pass' => $hashedPassword,
|
||||||
':role' => $role
|
':role' => $role
|
||||||
]);
|
]);
|
||||||
} else {
|
} else {
|
||||||
// الإضافة لجدول المستخدمين (خدمة العملاء)
|
// الإضافة لجدول المستخدمين (خدمة العملاء)
|
||||||
$sql = "INSERT INTO users (id, fingerprint, phone, email, gender, password, birthdate, user_type, first_name, created_at)
|
$sql = "INSERT INTO users (id, fingerprint, fingerprint_hash, phone, email, gender, password, birthdate, user_type, first_name, created_at)
|
||||||
VALUES (UUID(), :fp, :phone, :email, :gender, :pass, :bdate, 'service', :fname, NOW())";
|
VALUES (:id, :fp, :fp_hash, :phone, :email, :gender, :pass, :bdate, 'service', :fname, NOW())";
|
||||||
$stmt = $con->prepare($sql);
|
$stmt = $con->prepare($sql);
|
||||||
$stmt->execute([
|
$stmt->execute([
|
||||||
':fp' => $fingerprint,
|
':id' => $uniqueId,
|
||||||
|
':fp' => $encFp,
|
||||||
|
':fp_hash' => $fpHash,
|
||||||
':phone' => $encPhone,
|
':phone' => $encPhone,
|
||||||
':email' => $encEmail,
|
':email' => $encEmail,
|
||||||
':gender' => $gender,
|
':gender' => $gender,
|
||||||
|
|||||||
@@ -7,11 +7,11 @@
|
|||||||
require_once __DIR__ . '/../../core/bootstrap.php';
|
require_once __DIR__ . '/../../core/bootstrap.php';
|
||||||
$con = Database::get('main');
|
$con = Database::get('main');
|
||||||
|
|
||||||
// التحقق من أن الجدول فارغ لضمان الأمان
|
// تم تعطيل التحقق للسماح بإعادة التهيئة
|
||||||
$count = $con->query("SELECT COUNT(*) FROM adminUser")->fetchColumn();
|
// $count = $con->query("SELECT COUNT(*) FROM adminUser")->fetchColumn();
|
||||||
if ($count > 0) {
|
// if ($count > 0) {
|
||||||
die("Access Denied: Admin already initialized.");
|
// die("Access Denied: Admin already initialized.");
|
||||||
}
|
// }
|
||||||
|
|
||||||
$password = "malDev@2101"; // كلمة المرور المؤقتة
|
$password = "malDev@2101"; // كلمة المرور المؤقتة
|
||||||
$hashedPass = password_hash($password, PASSWORD_DEFAULT);
|
$hashedPass = password_hash($password, PASSWORD_DEFAULT);
|
||||||
|
|||||||
Reference in New Issue
Block a user