forked from github/szkolny
[API/Edudziennik] Save cookie with semester in student data. Change semester date on semester change.
This commit is contained in:
parent
30c5b2d1c9
commit
bce74a408c
@ -22,9 +22,6 @@ class DataEdudziennik(app: App, profile: Profile?, loginStore: LoginStore) : Dat
|
||||
|
||||
fun isWebLoginValid() = webSessionIdExpiryTime-30 > currentTimeUnix() && webSessionId.isNotNullNorEmpty()
|
||||
|
||||
val currentSemester: Int
|
||||
get() = webSemester
|
||||
|
||||
override fun satisfyLoginMethods() {
|
||||
loginMethods.clear()
|
||||
if (isWebLoginValid()) {
|
||||
@ -70,11 +67,6 @@ class DataEdudziennik(app: App, profile: Profile?, loginStore: LoginStore) : Dat
|
||||
get() { mWebSessionId = mWebSessionId ?: loginStore.getLoginData("webSessionId", null); return mWebSessionId }
|
||||
set(value) { loginStore.putLoginData("webSessionId", value); mWebSessionId = value }
|
||||
|
||||
private var mWebSemester: Int? = null
|
||||
var webSemester: Int
|
||||
get() { mWebSemester = mWebSemester ?: loginStore.getLoginData("webSemester", 1); return mWebSemester ?: 1 }
|
||||
set(value) { loginStore.putLoginData("webSemester", value); mWebSemester = value }
|
||||
|
||||
private var mWebSessionIdExpiryTime: Long? = null
|
||||
var webSessionIdExpiryTime: Long
|
||||
get() { mWebSessionIdExpiryTime = mWebSessionIdExpiryTime ?: loginStore.getLoginData("webSessionIdExpiryTime", 0L); return mWebSessionIdExpiryTime ?: 0L }
|
||||
@ -86,6 +78,11 @@ class DataEdudziennik(app: App, profile: Profile?, loginStore: LoginStore) : Dat
|
||||
| | | | __| '_ \ / _ \ '__|
|
||||
| |__| | |_| | | | __/ |
|
||||
\____/ \__|_| |_|\___|*/
|
||||
private var mCurrentSemester: Int? = null
|
||||
var currentSemester: Int
|
||||
get() { mCurrentSemester = mCurrentSemester ?: profile?.getStudentData("currentSemester", 1); return mCurrentSemester ?: 1 }
|
||||
set(value) { profile?.putStudentData("currentSemester", value) ?: return; mCurrentSemester = value }
|
||||
|
||||
private var mSchoolName: String? = null
|
||||
var schoolName: String?
|
||||
get() { mSchoolName = mSchoolName ?: profile?.getStudentData("schoolName", null); return mSchoolName }
|
||||
|
@ -70,7 +70,7 @@ open class EdudziennikWeb(open val data: DataEdudziennik) {
|
||||
.secure().httpOnly().build(),
|
||||
Cookie.Builder()
|
||||
.name("semester")
|
||||
.value((data.webSemester).toString())
|
||||
.value((data.currentSemester).toString())
|
||||
.domain("dziennikel.appspot.com")
|
||||
.secure().httpOnly().build()
|
||||
))
|
||||
|
@ -13,6 +13,7 @@ import pl.szczodrzynski.edziennik.data.api.models.ApiError
|
||||
import pl.szczodrzynski.edziennik.getUnixDate
|
||||
import pl.szczodrzynski.edziennik.isNotNullNorEmpty
|
||||
import pl.szczodrzynski.edziennik.utils.Utils.d
|
||||
import pl.szczodrzynski.edziennik.utils.models.Date
|
||||
|
||||
class EdudziennikLoginWeb(val data: DataEdudziennik, val onSuccess: () -> Unit) {
|
||||
companion object {
|
||||
@ -71,7 +72,14 @@ class EdudziennikLoginWeb(val data: DataEdudziennik, val onSuccess: () -> Unit)
|
||||
}
|
||||
|
||||
data.webSessionId = sessionId
|
||||
semester?.let { data.webSemester = it }
|
||||
|
||||
if (data.profile != null && semester != null) {
|
||||
data.currentSemester = semester
|
||||
|
||||
if (semester == 2 && data.profile.dateSemester2Start > Date.getToday())
|
||||
data.profile.dateSemester2Start = Date.getToday().stepForward(0, 0, -1)
|
||||
}
|
||||
|
||||
data.webSessionIdExpiryTime = response.getUnixDate() + 45 * 60 /* 45 min */
|
||||
onSuccess()
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user