From 989f6332f9cd60334ef7c9030e904722389acf05 Mon Sep 17 00:00:00 2001 From: Hamza-Ayed Date: Fri, 1 May 2026 01:31:58 +0300 Subject: [PATCH] feat: skip OTP via is_renewal flag on token expiration --- Admin/auth/login.php | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/Admin/auth/login.php b/Admin/auth/login.php index 4f0a390..e92a7d8 100755 --- a/Admin/auth/login.php +++ b/Admin/auth/login.php @@ -9,6 +9,7 @@ require_once __DIR__ . '/../../functions.php'; $fingerprint = filterRequest('fingerprint'); $password = filterRequest('password'); $audience = filterRequest('aud') ?? 'admin'; +$isRenewal = filterRequest('is_renewal') === '1'; if (empty($fingerprint) || empty($password)) { jsonError("Fingerprint and password are required."); @@ -40,6 +41,34 @@ try { // 2. التحقق من كلمة المرور if (password_verify($password, $admin['password'])) { + // إذا كان هذا مجرد تجديد للتوكن (إعادة الدخول التلقائي من التطبيق)، فلا داعي لإرسال OTP + if ($isRenewal) { + $jwtService = new JwtService($redis); + $role = $admin['role'] ?? 'admin'; + + // إلغاء التوكن القديم إذا وجد في Redis + if ($redis) { + $oldJti = $redis->get("active_jti:" . $admin['id']); + if ($oldJti) { + $jwtService->revokeToken($oldJti, 3600); + } + } + + $jwt = $jwtService->generateAccessToken($admin['id'], $role, $audience, $fingerprint); + + // فك تشفير البيانات للعرض + $admin['name'] = $encryptionHelper->decryptData($admin['name']) ?: $admin['name']; + unset($admin['password']); + + printSuccess([ + "message" => "Login successful", + "admin" => $admin, + "jwt" => $jwt, + "expires_in" => 3600 + ]); + exit; + } + // 3. توليد رمز تحقق OTP وإرساله عبر WhatsApp $otp = rand(10000, 99999); $encryptedPhone = $admin['phone'] ?? '';