fix: Support array payload from Security::verifyJWT for student identity verification
This commit is contained in:
@@ -472,12 +472,14 @@ class AuthController
|
|||||||
}
|
}
|
||||||
|
|
||||||
$decoded = Security::verifyJWT($identityToken);
|
$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' => 'الجلسة غير صالحة، يرجى إعادة التحقق من رقم الهاتف']);
|
$response->status(401)->json(['status' => 'error', 'message' => 'الجلسة غير صالحة، يرجى إعادة التحقق من رقم الهاتف']);
|
||||||
return;
|
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
|
// Check if student exists with this National ID
|
||||||
$student = Database::selectOne("SELECT * FROM students WHERE national_id = ? LIMIT 1", [$nationalId]);
|
$student = Database::selectOne("SELECT * FROM students WHERE national_id = ? LIMIT 1", [$nationalId]);
|
||||||
@@ -498,7 +500,7 @@ class AuthController
|
|||||||
$student['uuid'],
|
$student['uuid'],
|
||||||
'student',
|
'student',
|
||||||
'browser_default',
|
'browser_default',
|
||||||
$decoded->phone,
|
$phone,
|
||||||
$student['full_name'],
|
$student['full_name'],
|
||||||
$response,
|
$response,
|
||||||
'تم تسجيل الدخول لملف الطالب بنجاح'
|
'تم تسجيل الدخول لملف الطالب بنجاح'
|
||||||
@@ -573,11 +575,13 @@ class AuthController
|
|||||||
if ($identityToken) {
|
if ($identityToken) {
|
||||||
// New Student Flow
|
// New Student Flow
|
||||||
$decoded = Security::verifyJWT($identityToken);
|
$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' => 'الجلسة غير صالحة']);
|
$response->status(401)->json(['status' => 'error', 'message' => 'الجلسة غير صالحة']);
|
||||||
return;
|
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
|
// Ensure National ID doesn't exist
|
||||||
$existing = Database::selectOne("SELECT id FROM students WHERE national_id = ? LIMIT 1", [$nationalId]);
|
$existing = Database::selectOne("SELECT id FROM students WHERE national_id = ? LIMIT 1", [$nationalId]);
|
||||||
@@ -601,7 +605,7 @@ class AuthController
|
|||||||
}
|
}
|
||||||
|
|
||||||
$this->generateSessionAndRespond(
|
$this->generateSessionAndRespond(
|
||||||
$sId, $sUuid, 'student', 'browser_default', $decoded->phone, $fullName, $response, 'تم استكمال التسجيل بنجاح'
|
$sId, $sUuid, 'student', 'browser_default', $phone, $fullName, $response, 'تم استكمال التسجيل بنجاح'
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
// Legacy / Fallback for already logged-in students updating profile
|
// Legacy / Fallback for already logged-in students updating profile
|
||||||
|
|||||||
Reference in New Issue
Block a user