diff --git a/core/Auth/JwtService.php b/core/Auth/JwtService.php index 6de5757..40d29fd 100644 --- a/core/Auth/JwtService.php +++ b/core/Auth/JwtService.php @@ -57,6 +57,8 @@ class JwtService $ttl = 14400; } elseif ($role === 'passenger') { $ttl = 3600; + } elseif ($role === 'service') { + $ttl = 14400; // 4 hours as requested } $payload = [ diff --git a/serviceapp/register.php b/serviceapp/register.php new file mode 100644 index 0000000..da0c7f9 --- /dev/null +++ b/serviceapp/register.php @@ -0,0 +1,76 @@ +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, status, created_at) + VALUES (:id, :fname, :lname, :email, :phone, :pass, :fp, :fp_hash, 'service', 0, 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("خطأ في السيرفر: " . $e->getMessage()); +} + +exit();