fix: Resolve OTP verification instant transition and ensure bulletproof non-crashing conversation contact listing
This commit is contained in:
@@ -34,7 +34,11 @@ class ChatController
|
||||
[$tId]
|
||||
);
|
||||
}
|
||||
} catch (\Throwable $e) {
|
||||
error_log("Seed teacher note: " . $e->getMessage());
|
||||
}
|
||||
|
||||
try {
|
||||
// Ensure default sample students if no students exist
|
||||
$student = Database::selectOne("SELECT id FROM users WHERE role = 'student' LIMIT 1");
|
||||
if (!$student) {
|
||||
@@ -55,8 +59,8 @@ class ChatController
|
||||
);
|
||||
}
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
error_log("Seed users note: " . $e->getMessage());
|
||||
} catch (\Throwable $e) {
|
||||
error_log("Seed students note: " . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,7 +85,7 @@ class ChatController
|
||||
ORDER BY u.id DESC
|
||||
LIMIT 100
|
||||
", [$userId]);
|
||||
} catch (\Exception $e) {
|
||||
} catch (\Throwable $e) {
|
||||
error_log("Users select in getConversations error: " . $e->getMessage());
|
||||
}
|
||||
|
||||
@@ -107,12 +111,20 @@ class ChatController
|
||||
WHERE sender_id = ? AND receiver_id = ? AND is_read = 0
|
||||
", [$otherId, $userId]);
|
||||
$unreadCount = (int)($unreadRow['cnt'] ?? 0);
|
||||
} catch (\Exception $e) {
|
||||
} catch (\Throwable $e) {
|
||||
// Ignore per-user message query issue if any
|
||||
}
|
||||
|
||||
$rawName = (string)($row['encrypted_name'] ?? '');
|
||||
$decryptedName = Security::decrypt($rawName) ?: $rawName;
|
||||
$decryptedName = $rawName;
|
||||
try {
|
||||
$dec = Security::decrypt($rawName);
|
||||
if (!empty($dec)) {
|
||||
$decryptedName = $dec;
|
||||
}
|
||||
} catch (\Throwable $e) {
|
||||
$decryptedName = $rawName;
|
||||
}
|
||||
|
||||
$conversations[] = [
|
||||
'user_id' => $otherId,
|
||||
|
||||
@@ -1300,6 +1300,7 @@ class StudentPortal
|
||||
}
|
||||
document.cookie = "saqel_student_jwt=" + token + "; path=/; max-age=2592000; SameSite=Lax";
|
||||
initWebSocket(token);
|
||||
renderDashboard(user);
|
||||
await checkStudentSession(token);
|
||||
} else {
|
||||
showError(data.message || 'رمز التحقق غير صحيح');
|
||||
|
||||
@@ -957,12 +957,14 @@ class TeacherPortal
|
||||
if (res.ok && data.status === 'success' && data.data?.token) {
|
||||
const token = data.data.token;
|
||||
const user = data.data.user;
|
||||
const profile = data.data.profile || {};
|
||||
localStorage.setItem('saqel_teacher_jwt', token);
|
||||
if (user) {
|
||||
localStorage.setItem('saqel_teacher_user', JSON.stringify(user));
|
||||
localStorage.setItem('saqel_teacher_user', JSON.stringify({ ...user, ...profile }));
|
||||
}
|
||||
document.cookie = "saqel_teacher_jwt=" + token + "; path=/; max-age=2592000; SameSite=Lax";
|
||||
initWebSocket(token);
|
||||
renderDashboard(user, profile);
|
||||
await checkTeacherSession(token);
|
||||
} else {
|
||||
showError(data.message || 'رمز التحقق غير صحيح');
|
||||
|
||||
Reference in New Issue
Block a user