aboutsummaryrefslogtreecommitdiff
path: root/shared/src/commonMain/kotlin/mx
diff options
context:
space:
mode:
authorIván Ávalos <avalos@disroot.org>2022-01-14 23:01:39 -0600
committerIván Ávalos <avalos@disroot.org>2022-01-14 23:01:39 -0600
commite1360bc0fad1838a8c431d5142ce13cc81c10480 (patch)
tree8fe678322d0370ce4f138ad748f86c4748fcc5e8 /shared/src/commonMain/kotlin/mx
parenta22a13de9b4d1e46bb64371242fa3528bfac7675 (diff)
downloadetbsa-trackermap-mobile-e1360bc0fad1838a8c431d5142ce13cc81c10480.tar.gz
etbsa-trackermap-mobile-e1360bc0fad1838a8c431d5142ce13cc81c10480.tar.bz2
etbsa-trackermap-mobile-e1360bc0fad1838a8c431d5142ce13cc81c10480.zip
Refactored even more session management code into SessionController
Diffstat (limited to 'shared/src/commonMain/kotlin/mx')
-rw-r--r--shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/controllers/SessionController.kt22
1 files changed, 22 insertions, 0 deletions
diff --git a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/controllers/SessionController.kt b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/controllers/SessionController.kt
index 8f5ac56..ed65824 100644
--- a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/controllers/SessionController.kt
+++ b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/controllers/SessionController.kt
@@ -19,11 +19,25 @@ class SessionController(
object PasswordMissing : LoginState()
object Failure : LoginState()
object Success : LoginState()
+ object SignOut : LoginState()
}
val loginStateFlow = MutableStateFlow<LoginState?>(null)
val userFlow = MutableStateFlow<User?>(null)
+ fun getSession() {
+ loginStateFlow.value = LoginState.Loading
+ GlobalScope.launch {
+ try {
+ userFlow.value = sessionApi.sessionGet()
+ Log.d("LoginViewModel", userFlow.value.toString())
+ loginStateFlow.value = LoginState.Success
+ } catch (e: Exception) {
+ loginStateFlow.value = LoginState.Failure
+ }
+ }
+ }
+
fun restoreSession() {
loginStateFlow.value = LoginState.Loading
GlobalScope.launch {
@@ -62,4 +76,12 @@ class SessionController(
}
}
}
+
+ fun logout() {
+ GlobalScope.launch {
+ loginStateFlow.value = LoginState.Loading
+ sessionApi.sessionDelete()
+ loginStateFlow.value = LoginState.SignOut
+ }
+ }
} \ No newline at end of file