forked from github/szkolny
[API/Edudziennik] Save and use semester cookie instead of currentSemester in profile.
This commit is contained in:
parent
15f126416f
commit
21fd59c196
@ -22,6 +22,9 @@ 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()) {
|
||||
@ -65,6 +68,11 @@ 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 }
|
||||
|
@ -70,7 +70,7 @@ open class EdudziennikWeb(open val data: DataEdudziennik) {
|
||||
.secure().httpOnly().build(),
|
||||
Cookie.Builder()
|
||||
.name("semester")
|
||||
.value((profile?.currentSemester ?: 1).toString())
|
||||
.value((data.webSemester).toString())
|
||||
.domain("dziennikel.appspot.com")
|
||||
.secure().httpOnly().build()
|
||||
))
|
||||
|
@ -69,7 +69,7 @@ class EdudziennikWebAttendance(override val data: DataEdudziennik,
|
||||
id,
|
||||
lesson?.displayTeacherId ?: -1,
|
||||
lesson?.displaySubjectId ?: -1,
|
||||
profile.currentSemester,
|
||||
data.currentSemester,
|
||||
name,
|
||||
date,
|
||||
lesson?.displayStartTime ?: startTime,
|
||||
|
@ -107,7 +107,7 @@ class EdudziennikWebGrades(override val data: DataEdudziennik,
|
||||
name,
|
||||
value,
|
||||
if (gradeCountToAverage) weight else 0f,
|
||||
profile.currentSemester,
|
||||
data.currentSemester,
|
||||
teacher.id,
|
||||
subject.id
|
||||
).apply {
|
||||
@ -137,7 +137,7 @@ class EdudziennikWebGrades(override val data: DataEdudziennik,
|
||||
proposed,
|
||||
proposed.toFloatOrNull() ?: 0f,
|
||||
0f,
|
||||
profile.currentSemester,
|
||||
data.currentSemester,
|
||||
-1,
|
||||
subject.id
|
||||
).apply {
|
||||
@ -170,7 +170,7 @@ class EdudziennikWebGrades(override val data: DataEdudziennik,
|
||||
final,
|
||||
final.toFloatOrNull() ?: 0f,
|
||||
0f,
|
||||
profile.currentSemester,
|
||||
data.currentSemester,
|
||||
-1,
|
||||
subject.id
|
||||
).apply {
|
||||
@ -201,7 +201,7 @@ class EdudziennikWebGrades(override val data: DataEdudziennik,
|
||||
TYPE_SEMESTER1_FINAL,
|
||||
TYPE_SEMESTER2_FINAL
|
||||
).map {
|
||||
DataRemoveModel.Grades.semesterWithType(profile.currentSemester, it)
|
||||
DataRemoveModel.Grades.semesterWithType(data.currentSemester, it)
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -42,7 +42,7 @@ class EdudziennikWebNotes(override val data: DataEdudziennik,
|
||||
profileId,
|
||||
id,
|
||||
description,
|
||||
profile.currentSemester,
|
||||
data.currentSemester,
|
||||
Notice.TYPE_NEUTRAL,
|
||||
teacher.id
|
||||
)
|
||||
|
@ -61,6 +61,7 @@ class EdudziennikLoginWeb(val data: DataEdudziennik, val onSuccess: () -> Unit)
|
||||
|
||||
val cookies = data.app.cookieJar.getForDomain("dziennikel.appspot.com")
|
||||
val sessionId = cookies.firstOrNull { it.name() == "sessionid" }?.value()
|
||||
val semester = cookies.firstOrNull { it.name() == "semester" }?.value()?.toIntOrNull()
|
||||
|
||||
if (sessionId == null) {
|
||||
data.error(ApiError(TAG, ERROR_LOGIN_EDUDZIENNIK_WEB_NO_SESSION_ID)
|
||||
@ -70,6 +71,7 @@ class EdudziennikLoginWeb(val data: DataEdudziennik, val onSuccess: () -> Unit)
|
||||
}
|
||||
|
||||
data.webSessionId = sessionId
|
||||
semester?.let { data.webSemester = it }
|
||||
data.webSessionIdExpiryTime = response.getUnixDate() + 45 * 60 /* 45 min */
|
||||
onSuccess()
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user