[API/Vulcan] Fix Web login with multiple student IDs.

This commit is contained in:
Kuba Szczodrzyński 2021-10-31 18:19:07 +01:00
parent a1b5560977
commit dda0d88f19
No known key found for this signature in database
GPG Key ID: 70CB8A85BA1633CB

View File

@ -137,31 +137,6 @@ open class VulcanWebMain(open val data: DataVulcan, open val lastSync: Long?) {
}
}
data.webPermissions = data.webPermissions.toMutableMap().also { map ->
val permissions = Regexes.VULCAN_WEB_PERMISSIONS.find(text)?.let { it[1] }
if (permissions?.isNotBlank() == true) {
val studentId = permissions.split("|")
.getOrNull(0)
?.base64DecodeToString()
?.toJsonObject()
?.getJsonArray("AuthInfos")
?.asJsonObjectList()
?.flatMap { authInfo ->
authInfo.getJsonArray("UczenIds")
?.map { it.asInt }
?: listOf()
}
?.firstOrNull()
?.toString()
data.app.cookieJar.set(
data.webHost ?: "vulcan.net.pl",
"idBiezacyUczen",
studentId
)
}
map[symbol] = permissions
}
val schoolSymbols = mutableListOf<String>()
val clientUrl = "://uonetplus-uczen.${data.webHost}/$symbol/"
var clientIndex = text.indexOf(clientUrl)
@ -186,6 +161,42 @@ open class VulcanWebMain(open val data: DataVulcan, open val lastSync: Long?) {
return
}
data.webPermissions = data.webPermissions.toMutableMap().also { map ->
val permissions = Regexes.VULCAN_WEB_PERMISSIONS.find(text)?.let { it[1] }
if (permissions?.isNotBlank() == true) {
val json = permissions.split("|")
.getOrNull(0)
?.base64DecodeToString()
?.toJsonObject()
val unitIds = json
?.getJsonArray("Units")
?.asJsonObjectList()
?.filter { unit ->
unit.getString("Symbol") in schoolSymbols
}
?.mapNotNull { it.getInt("Id") } ?: emptyList()
val studentId = json
?.getJsonArray("AuthInfos")
?.asJsonObjectList()
?.filter { authInfo ->
authInfo.getInt("JednostkaSprawozdawczaId") in unitIds
}
?.flatMap { authInfo ->
authInfo.getJsonArray("UczenIds")
?.map { it.asInt }
?: listOf()
}
?.firstOrNull()
?.toString()
data.app.cookieJar.set(
data.webHost ?: "vulcan.net.pl",
"idBiezacyUczen",
studentId
)
}
map[symbol] = permissions
}
onSuccess(text, schoolSymbols)
}