feat: skip OTP via is_renewal flag on token expiration
This commit is contained in:
@@ -9,6 +9,7 @@ require_once __DIR__ . '/../../functions.php';
|
|||||||
$fingerprint = filterRequest('fingerprint');
|
$fingerprint = filterRequest('fingerprint');
|
||||||
$password = filterRequest('password');
|
$password = filterRequest('password');
|
||||||
$audience = filterRequest('aud') ?? 'admin';
|
$audience = filterRequest('aud') ?? 'admin';
|
||||||
|
$isRenewal = filterRequest('is_renewal') === '1';
|
||||||
|
|
||||||
if (empty($fingerprint) || empty($password)) {
|
if (empty($fingerprint) || empty($password)) {
|
||||||
jsonError("Fingerprint and password are required.");
|
jsonError("Fingerprint and password are required.");
|
||||||
@@ -40,6 +41,34 @@ try {
|
|||||||
// 2. التحقق من كلمة المرور
|
// 2. التحقق من كلمة المرور
|
||||||
if (password_verify($password, $admin['password'])) {
|
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
|
// 3. توليد رمز تحقق OTP وإرساله عبر WhatsApp
|
||||||
$otp = rand(10000, 99999);
|
$otp = rand(10000, 99999);
|
||||||
$encryptedPhone = $admin['phone'] ?? '';
|
$encryptedPhone = $admin['phone'] ?? '';
|
||||||
|
|||||||
Reference in New Issue
Block a user