fix(web): перепроверять статус сессии
This commit is contained in:
@@ -42,4 +42,5 @@ data class MeResponse(
|
||||
val role: String,
|
||||
val name: String,
|
||||
val mustChangePassword: Boolean,
|
||||
val active: Boolean = true,
|
||||
)
|
||||
|
||||
@@ -73,22 +73,25 @@ class AuthService(
|
||||
}
|
||||
|
||||
private fun ensureLoginAllowed(account: Account) {
|
||||
if (account.status != AccountStatus.ACTIVE) {
|
||||
throw UnauthorizedException("Аккаунт архивирован")
|
||||
}
|
||||
if (account.role != LmsRole.STUDENT) return
|
||||
val status = students.findById(account.id).map { it.status }.orElse(null)
|
||||
if (status in setOf(StudentStatus.EXPELLED, StudentStatus.GRADUATED, StudentStatus.ARCHIVED)) {
|
||||
throw UnauthorizedException("Доступ к системе закрыт")
|
||||
}
|
||||
ensureGroupOpen(account)
|
||||
loginDeniedReason(account)?.let { throw UnauthorizedException(it) }
|
||||
}
|
||||
|
||||
private fun ensureGroupOpen(account: Account) {
|
||||
val groupStatus = enrollments.findByStudentAccountId(account.id)?.group?.status
|
||||
if (groupStatus in setOf(GroupStatus.GRADUATED, GroupStatus.ARCHIVED)) {
|
||||
throw UnauthorizedException("Группа закрыта")
|
||||
/** Причина запрета входа или null, если вход разрешён. Используется и в me(). */
|
||||
private fun loginDeniedReason(account: Account): String? {
|
||||
if (account.status != AccountStatus.ACTIVE) {
|
||||
return "Аккаунт архивирован"
|
||||
}
|
||||
if (account.role != LmsRole.STUDENT) return null
|
||||
val status = students.findById(account.id).map { it.status }.orElse(null)
|
||||
if (status in setOf(StudentStatus.EXPELLED, StudentStatus.GRADUATED, StudentStatus.ARCHIVED)) {
|
||||
return "Доступ к системе закрыт"
|
||||
}
|
||||
return groupDeniedReason(account)
|
||||
}
|
||||
|
||||
private fun groupDeniedReason(account: Account): String? {
|
||||
val groupStatus = enrollments.findByStudentAccountId(account.id)?.group?.status
|
||||
return if (groupStatus in setOf(GroupStatus.GRADUATED, GroupStatus.ARCHIVED)) "Группа закрыта" else null
|
||||
}
|
||||
|
||||
@Transactional(readOnly = true)
|
||||
@@ -103,6 +106,7 @@ class AuthService(
|
||||
role = account.role.name,
|
||||
name = displayName(account),
|
||||
mustChangePassword = account.mustChangePassword,
|
||||
active = loginDeniedReason(account) == null,
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user