forked from github/szkolny
[APIv2/Librus] Update Librus login methods.
This commit is contained in:
parent
e95d9ee514
commit
4cbb573d17
@ -1,6 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) Kuba Szczodrzyński 2019-9-21.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package pl.szczodrzynski.edziennik.api.v2.librus
|
|
||||||
|
|
@ -5,13 +5,34 @@
|
|||||||
package pl.szczodrzynski.edziennik.api.v2.librus.data
|
package pl.szczodrzynski.edziennik.api.v2.librus.data
|
||||||
|
|
||||||
import pl.szczodrzynski.edziennik.App
|
import pl.szczodrzynski.edziennik.App
|
||||||
import pl.szczodrzynski.edziennik.api.interfaces.ProgressCallback
|
import pl.szczodrzynski.edziennik.api.v2.LOGIN_METHOD_LIBRUS_API
|
||||||
|
import pl.szczodrzynski.edziennik.api.v2.LOGIN_METHOD_LIBRUS_MESSAGES
|
||||||
|
import pl.szczodrzynski.edziennik.api.v2.LOGIN_METHOD_LIBRUS_PORTAL
|
||||||
|
import pl.szczodrzynski.edziennik.api.v2.LOGIN_METHOD_LIBRUS_SYNERGIA
|
||||||
import pl.szczodrzynski.edziennik.api.v2.models.Data
|
import pl.szczodrzynski.edziennik.api.v2.models.Data
|
||||||
|
import pl.szczodrzynski.edziennik.currentTimeUnix
|
||||||
import pl.szczodrzynski.edziennik.datamodels.LoginStore
|
import pl.szczodrzynski.edziennik.datamodels.LoginStore
|
||||||
import pl.szczodrzynski.edziennik.datamodels.Profile
|
import pl.szczodrzynski.edziennik.datamodels.Profile
|
||||||
|
import pl.szczodrzynski.edziennik.isNotNullNorEmpty
|
||||||
|
|
||||||
class DataLibrus(app: App, profile: Profile?, loginStore: LoginStore) : Data(app, profile, loginStore) {
|
class DataLibrus(app: App, profile: Profile?, loginStore: LoginStore) : Data(app, profile, loginStore) {
|
||||||
|
|
||||||
|
fun isPortalLoginValid() = portalTokenExpiryTime-30 > currentTimeUnix() && portalRefreshToken.isNotNullNorEmpty() && portalAccessToken.isNotNullNorEmpty()
|
||||||
|
fun isApiLoginValid() = apiTokenExpiryTime-30 > currentTimeUnix() && apiAccessToken.isNotNullNorEmpty()
|
||||||
|
fun isSynergiaLoginValid() = synergiaSessionIdExpiryTime-30 > currentTimeUnix() && synergiaSessionId.isNotNullNorEmpty()
|
||||||
|
fun isMessagesLoginValid() = messagesSessionIdExpiryTime-30 > currentTimeUnix() && messagesSessionId.isNotNullNorEmpty()
|
||||||
|
|
||||||
|
override fun satisfyLoginMethods() {
|
||||||
|
if (isPortalLoginValid())
|
||||||
|
loginMethods += LOGIN_METHOD_LIBRUS_PORTAL
|
||||||
|
if (isApiLoginValid())
|
||||||
|
loginMethods += LOGIN_METHOD_LIBRUS_API
|
||||||
|
if (isSynergiaLoginValid())
|
||||||
|
loginMethods += LOGIN_METHOD_LIBRUS_SYNERGIA
|
||||||
|
if (isMessagesLoginValid())
|
||||||
|
loginMethods += LOGIN_METHOD_LIBRUS_MESSAGES
|
||||||
|
}
|
||||||
|
|
||||||
/* _____ _ _
|
/* _____ _ _
|
||||||
| __ \ | | | |
|
| __ \ | | | |
|
||||||
| |__) |__ _ __| |_ __ _| |
|
| |__) |__ _ __| |_ __ _| |
|
||||||
|
@ -37,7 +37,7 @@ class LoginLibrusApi {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data.apiTokenExpiryTime-30 > currentTimeUnix() && data.apiAccessToken.isNotNullNorEmpty()) {
|
if (data.isApiLoginValid()) {
|
||||||
onSuccess()
|
onSuccess()
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -20,27 +20,33 @@ class LoginLibrusMessages(val data: DataLibrus, val onSuccess: () -> Unit) {
|
|||||||
return@run
|
return@run
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data.messagesSessionIdExpiryTime-30 > currentTimeUnix() && data.messagesSessionId.isNotNullNorEmpty()) {
|
if (data.isMessagesLoginValid()) {
|
||||||
onSuccess()
|
onSuccess()
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
when (data.loginStore.mode) {
|
if (data.loginMethods.contains(LOGIN_METHOD_LIBRUS_SYNERGIA)) {
|
||||||
LOGIN_MODE_LIBRUS_SYNERGIA -> loginWithCredentials()
|
loginWithSynergia()
|
||||||
else -> {
|
}
|
||||||
loginWithSynergia()
|
else if (data.apiLogin != null && data.apiPassword != null) {
|
||||||
}
|
loginWithCredentials()
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
data.error(TAG, ERROR_LOGIN_DATA_MISSING)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* XML (Flash messages website) login method. Uses a Synergia login and password.
|
||||||
|
*/
|
||||||
private fun loginWithCredentials() {
|
private fun loginWithCredentials() {
|
||||||
if (data.apiLogin == null || data.apiPassword == null) {
|
|
||||||
if (!data.loginMethods.contains(LOGIN_METHOD_LIBRUS_SYNERGIA)) {
|
}
|
||||||
data.error(TAG, ERROR_LOGIN_METHOD_NOT_SATISFIED)
|
|
||||||
return
|
/**
|
||||||
}
|
* A login method using the Synergia website (/wiadomosci2 Auto Login).
|
||||||
data.error(TAG, ERROR_LOGIN_DATA_MISSING)
|
*/
|
||||||
return
|
private fun loginWithSynergia() {
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -33,7 +33,7 @@ class LoginLibrusPortal(val data: DataLibrus, val onSuccess: () -> Unit) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// succeed having a non-expired access token and a refresh token
|
// succeed having a non-expired access token and a refresh token
|
||||||
if (data.portalTokenExpiryTime-30 > currentTimeUnix() && data.portalRefreshToken.isNotNullNorEmpty() && data.portalAccessToken.isNotNullNorEmpty()) {
|
if (data.isPortalLoginValid()) {
|
||||||
onSuccess()
|
onSuccess()
|
||||||
}
|
}
|
||||||
else if (data.portalRefreshToken != null) {
|
else if (data.portalRefreshToken != null) {
|
||||||
|
@ -29,7 +29,7 @@ class LoginLibrusSynergia(val data: DataLibrus, val onSuccess: () -> Unit) {
|
|||||||
return@run
|
return@run
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data.synergiaSessionIdExpiryTime-30 > currentTimeUnix() && data.synergiaSessionId.isNotNullNorEmpty()) {
|
if (data.isSynergiaLoginValid()) {
|
||||||
onSuccess()
|
onSuccess()
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -48,6 +48,7 @@ class LoginLibrusSynergia(val data: DataLibrus, val onSuccess: () -> Unit) {
|
|||||||
/**
|
/**
|
||||||
* HTML form-based login method. Uses a Synergia login and password.
|
* HTML form-based login method. Uses a Synergia login and password.
|
||||||
*/
|
*/
|
||||||
|
// TODO if loginWithCredentials fails and it is possible to use API, use it
|
||||||
private fun loginWithCredentials() {
|
private fun loginWithCredentials() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -25,6 +25,14 @@ open class Data(val app: App, val profile: Profile?, val loginStore: LoginStore)
|
|||||||
*/
|
*/
|
||||||
val loginMethods = mutableListOf<Int>()
|
val loginMethods = mutableListOf<Int>()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A method which may be overridden in child Data* classes.
|
||||||
|
*
|
||||||
|
* Calling it should populate [loginMethods] with all
|
||||||
|
* already available login methods (e.g. non-expired OAuth token).
|
||||||
|
*/
|
||||||
|
open fun satisfyLoginMethods() {}
|
||||||
|
|
||||||
val teacherList = LongSparseArray<Teacher>()
|
val teacherList = LongSparseArray<Teacher>()
|
||||||
val subjectList = LongSparseArray<Subject>()
|
val subjectList = LongSparseArray<Subject>()
|
||||||
val teamList = mutableListOf<Team>()
|
val teamList = mutableListOf<Team>()
|
||||||
|
Loading…
Reference in New Issue
Block a user