Update: 2026-06-12 20:40:40
This commit is contained in:
29
backend/serviceapp/login.php
Executable file → Normal file
29
backend/serviceapp/login.php
Executable file → Normal file
@@ -3,6 +3,7 @@ require_once __DIR__ . '/../core/bootstrap.php';
|
||||
|
||||
$fingerprint = filterRequest('fingerprint');
|
||||
$password = filterRequest('password');
|
||||
$email = filterRequest('email');
|
||||
$audience = filterRequest('aud') ?? 'service';
|
||||
|
||||
if (empty($fingerprint) || empty($password)) {
|
||||
@@ -10,6 +11,10 @@ if (empty($fingerprint) || empty($password)) {
|
||||
exit();
|
||||
}
|
||||
|
||||
// Rate Limiting: 5 محاولات في الدقيقة لكل IP
|
||||
$rateLimiter = new RateLimiter($redis);
|
||||
$rateLimiter->enforce(RateLimiter::identifier(), 'login');
|
||||
|
||||
try {
|
||||
$con = Database::get('main');
|
||||
|
||||
@@ -20,6 +25,28 @@ try {
|
||||
$stmt->execute([':fp' => $fpHash]);
|
||||
$user = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
|
||||
// إذا لم يتم العثور بالبصمة، وتم تمرير الإيميل (تسجيل دخول لأول مرة أو من جهاز جديد)
|
||||
if (!$user && !empty($email)) {
|
||||
$encEmailInput = $encryptionHelper->encryptData($email);
|
||||
$stmtEmail = $con->prepare("SELECT * FROM `users` WHERE `email` = :email AND `user_type` = 'service' LIMIT 1");
|
||||
$stmtEmail->execute([':email' => $encEmailInput]);
|
||||
$user = $stmtEmail->fetch(PDO::FETCH_ASSOC);
|
||||
|
||||
// تأكيد كلمة المرور وتحديث بصمة الجهاز إذا تم إيجاد الحساب
|
||||
if ($user && password_verify($password, $user['password'])) {
|
||||
$encFpRaw = $encryptionHelper->encryptData($fingerprint);
|
||||
$updateStmt = $con->prepare("UPDATE `users` SET fingerprint = :fp_raw, fingerprint_hash = :fp WHERE id = :id");
|
||||
$updateStmt->execute([
|
||||
':fp_raw' => $encFpRaw,
|
||||
':fp' => $fpHash,
|
||||
':id' => $user['id']
|
||||
]);
|
||||
$user['fingerprint_hash'] = $fpHash; // Update locally
|
||||
} else if ($user) {
|
||||
// Password incorrect, fail later.
|
||||
}
|
||||
}
|
||||
|
||||
if ($user) {
|
||||
// التحقق من حالة الحساب
|
||||
if ($user['status'] === 'pending') {
|
||||
@@ -94,7 +121,7 @@ try {
|
||||
jsonError("Incorrect password");
|
||||
}
|
||||
} else {
|
||||
jsonError("الجهاز غير مسجل لموظف خدمة.");
|
||||
jsonError("الجهاز أو الحساب غير مسجل. يرجى إدخال البريد الإلكتروني وكلمة المرور إذا كان هذا أول تسجيل دخول لك.");
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
error_log("[ServiceApp Login Error] " . $e->getMessage());
|
||||
|
||||
Reference in New Issue
Block a user