diff options
author | Iván Ávalos <avalos@disroot.org> | 2022-01-14 23:01:39 -0600 |
---|---|---|
committer | Iván Ávalos <avalos@disroot.org> | 2022-01-14 23:01:39 -0600 |
commit | e1360bc0fad1838a8c431d5142ce13cc81c10480 (patch) | |
tree | 8fe678322d0370ce4f138ad748f86c4748fcc5e8 /shared | |
parent | a22a13de9b4d1e46bb64371242fa3528bfac7675 (diff) | |
download | etbsa-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')
-rw-r--r-- | shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/controllers/SessionController.kt | 22 |
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 |