Files
Siro/backend/serviceapp/register.php
Hamza-Ayed 72eeb24cd7 Fix #18: Exception leak remediation across 87 PHP files
- Replaced all client-facing $e->getMessage() with generic error messages
- Added error_log() with filename prefix to all catch blocks
- Covered jsonError(), echo, and json_encode() response patterns
- Also fixed 2 remaining display_errors=1 and add_invoice.php leak
- Script-assisted fix for 75 files, manual fix for 12 remaining edge cases
2026-06-17 07:48:31 +03:00

91 lines
3.8 KiB
PHP

<?php
/**
* serviceapp/register.php
* التسجيل الذاتي لموظفي خدمة العملاء - الحساب يكون بحالة pending بانتظار موافقة الإدارة
*/
require_once __DIR__ . '/../core/bootstrap.php';
$firstName = filterRequest('first_name');
$lastName = filterRequest('last_name');
$email = filterRequest('email');
$phone = filterRequest('phone');
$password = filterRequest('password');
$fingerprint = filterRequest('fingerprint');
if (empty($firstName) || empty($lastName) || empty($email) || empty($phone) || empty($password) || empty($fingerprint)) {
jsonError("All fields are required.");
exit;
}
try {
// 1. التحقق من البيئة (Environment Whitelist)
$allowedPhonesStr = getenv('AUTHORIZED_SERVICE_PHONES');
if (!$allowedPhonesStr) {
jsonError("غير مصرح لك بالتسجيل كموظف خدمة (القائمة البيضاء غير معدة).");
exit;
}
$allowedPhones = array_map('trim', explode(',', $allowedPhonesStr));
if (!in_array($phone, $allowedPhones)) {
jsonError("أنت غير مصرح لك بالتسجيل كموظف خدمة. يرجى مراجعة الإدارة.");
exit;
}
$con = Database::get('main');
// 1. التحقق من عدم وجود الحساب مسبقاً (عن طريق البريد الإلكتروني، الهاتف أو البصمة)
$fpHash = hash('sha256', $fingerprint);
$check = $con->prepare("SELECT id FROM users WHERE email = ? OR phone = ? OR fingerprint_hash = ? LIMIT 1");
// تشفير الحقول للبحث عنها إذا كانت مشفرة في قاعدة البيانات (حسب تصميم النظام)
$encEmail = $encryptionHelper->encryptData($email);
// ملاحظة: البحث بالهاتف والبريد المشفر يتطلب مطابقة دقيقة أو البحث بالـ Hash إذا كان متوفراً
// هنا سنفترض البحث بالبيانات الممرة مباشرة أو المشفرة حسب ما تقتضيه سياسة connect.php
$check->execute([$email, $phone, $fpHash]);
if ($check->rowCount() > 0) {
jsonError("هذا الحساب أو الجهاز مسجل مسبقاً.");
exit;
}
// 2. تجهيز البيانات
$id = bin2hex(random_bytes(16));
$hashedPassword = password_hash($password, PASSWORD_DEFAULT);
// تشفير البيانات الحساسة قبل التخزين
$encFirstName = $encryptionHelper->encryptData($firstName);
$encLastName = $encryptionHelper->encryptData($lastName);
$encEmail = $encryptionHelper->encryptData($email);
$encPhone = $encryptionHelper->encryptData($phone);
$encFp = $encryptionHelper->encryptData($fingerprint);
// 3. الإدخال في قاعدة البيانات (الحالة الافتراضية هي 0 أو pending)
$sql = "INSERT INTO users (id, first_name, last_name, email, phone, password, fingerprint, fingerprint_hash, user_type, created_at)
VALUES (:id, :fname, :lname, :email, :phone, :pass, :fp, :fp_hash, 'service', NOW())";
$stmt = $con->prepare($sql);
$stmt->execute([
':id' => $id,
':fname' => $encFirstName,
':lname' => $encLastName,
':email' => $encEmail,
':phone' => $encPhone,
':pass' => $hashedPassword,
':fp' => $encFp,
':fp_hash' => $fpHash
]);
printSuccess([
"status" => "pending",
"message" => "تم تقديم طلب التسجيل بنجاح. يرجى انتظار موافقة الإدارة."
]);
} catch (Exception $e) {
error_log("[Service Register Error] " . $e->getMessage());
jsonError("An internal error occurred. Please try again later.");
}
exit();