fix: Support array payload from Security::verifyJWT for student identity verification

This commit is contained in:
Hamza-Ayed
2026-08-29 03:07:10 +03:00
parent 6da006e154
commit 39cf087488
+10 -6
View File
@@ -472,12 +472,14 @@ class AuthController
}
$decoded = Security::verifyJWT($identityToken);
if (!$decoded || ($decoded->role ?? '') !== 'student_identity_pending') {
$role = is_array($decoded) ? ($decoded['role'] ?? '') : ($decoded->role ?? '');
if (!$decoded || $role !== 'student_identity_pending') {
$response->status(401)->json(['status' => 'error', 'message' => 'الجلسة غير صالحة، يرجى إعادة التحقق من رقم الهاتف']);
return;
}
$identityId = (int)$decoded->identity_id;
$identityId = (int)(is_array($decoded) ? ($decoded['identity_id'] ?? 0) : ($decoded->identity_id ?? 0));
$phone = is_array($decoded) ? ($decoded['phone'] ?? '') : ($decoded->phone ?? '');
// Check if student exists with this National ID
$student = Database::selectOne("SELECT * FROM students WHERE national_id = ? LIMIT 1", [$nationalId]);
@@ -498,7 +500,7 @@ class AuthController
$student['uuid'],
'student',
'browser_default',
$decoded->phone,
$phone,
$student['full_name'],
$response,
'تم تسجيل الدخول لملف الطالب بنجاح'
@@ -573,11 +575,13 @@ class AuthController
if ($identityToken) {
// New Student Flow
$decoded = Security::verifyJWT($identityToken);
if (!$decoded || ($decoded->role ?? '') !== 'student_identity_pending') {
$role = is_array($decoded) ? ($decoded['role'] ?? '') : ($decoded->role ?? '');
if (!$decoded || $role !== 'student_identity_pending') {
$response->status(401)->json(['status' => 'error', 'message' => 'الجلسة غير صالحة']);
return;
}
$identityId = (int)$decoded->identity_id;
$identityId = (int)(is_array($decoded) ? ($decoded['identity_id'] ?? 0) : ($decoded->identity_id ?? 0));
$phone = is_array($decoded) ? ($decoded['phone'] ?? '') : ($decoded->phone ?? '');
// Ensure National ID doesn't exist
$existing = Database::selectOne("SELECT id FROM students WHERE national_id = ? LIMIT 1", [$nationalId]);
@@ -601,7 +605,7 @@ class AuthController
}
$this->generateSessionAndRespond(
$sId, $sUuid, 'student', 'browser_default', $decoded->phone, $fullName, $response, 'تم استكمال التسجيل بنجاح'
$sId, $sUuid, 'student', 'browser_default', $phone, $fullName, $response, 'تم استكمال التسجيل بنجاح'
);
} else {
// Legacy / Fallback for already logged-in students updating profile