a little updates
This commit is contained in:
@@ -16,9 +16,5 @@ kotlin {
|
||||
api project(":postssystem.features.auth.common")
|
||||
}
|
||||
}
|
||||
clientMain {
|
||||
dependencies {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -9,6 +9,8 @@ import dev.inmo.micro_utils.common.Either
|
||||
import dev.inmo.micro_utils.common.either
|
||||
import dev.inmo.micro_utils.repos.*
|
||||
import dev.inmo.postssystem.features.auth.client.createAuthorizedFeaturesDIModule
|
||||
import dev.inmo.postssystem.features.auth.client.ui.AuthUIError.AuthIncorrect
|
||||
import dev.inmo.postssystem.features.auth.client.ui.AuthUIError.ServerUnavailable
|
||||
import dev.inmo.postssystem.features.common.common.DBDropper
|
||||
import kotlinx.coroutines.*
|
||||
import kotlinx.coroutines.flow.*
|
||||
@@ -83,8 +85,8 @@ data class DefaultAuthSettings(
|
||||
currentModule ?.let { koin.loadModules(listOf(currentModule)) }
|
||||
}
|
||||
return when {
|
||||
!serverAvailable -> ServerUnavailableAuthUIError
|
||||
!authCorrect -> AuthIncorrectAuthUIError
|
||||
!serverAvailable -> ServerUnavailable
|
||||
!authCorrect -> AuthIncorrect
|
||||
else -> {
|
||||
_authorizedDIModule.value = newModule
|
||||
null
|
||||
|
@@ -3,18 +3,23 @@ package dev.inmo.postssystem.features.auth.client.ui
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable
|
||||
sealed class AuthUIError
|
||||
@Serializable
|
||||
object ServerUnavailableAuthUIError : AuthUIError()
|
||||
@Serializable
|
||||
object AuthIncorrectAuthUIError : AuthUIError()
|
||||
sealed class AuthUIError {
|
||||
@Serializable
|
||||
object ServerUnavailable : AuthUIError()
|
||||
@Serializable
|
||||
object AuthIncorrect : AuthUIError()
|
||||
}
|
||||
|
||||
@Serializable
|
||||
sealed class AuthUIState
|
||||
@Serializable
|
||||
data class InitAuthUIState(val showError: AuthUIError? = null) : AuthUIState()
|
||||
val DefaultInitAuthUIState = InitAuthUIState()
|
||||
@Serializable
|
||||
object LoadingAuthUIState : AuthUIState()
|
||||
@Serializable
|
||||
object AuthorizedAuthUIState : AuthUIState()
|
||||
sealed class AuthUIState {
|
||||
@Serializable
|
||||
data class Init(val showError: AuthUIError? = null) : AuthUIState()
|
||||
@Serializable
|
||||
object Loading : AuthUIState()
|
||||
@Serializable
|
||||
object Authorized : AuthUIState()
|
||||
|
||||
companion object {
|
||||
val DefaultInit = Init()
|
||||
}
|
||||
}
|
||||
|
@@ -9,26 +9,26 @@ import kotlinx.coroutines.launch
|
||||
class DefaultAuthUIModel(
|
||||
private val scope: CoroutineScope,
|
||||
private val authSettings: AuthSettings
|
||||
) : AbstractUIModel<AuthUIState>(LoadingAuthUIState), AuthUIModel {
|
||||
) : AbstractUIModel<AuthUIState>(AuthUIState.Loading), AuthUIModel {
|
||||
init {
|
||||
scope.launch {
|
||||
_currentState.value = LoadingAuthUIState
|
||||
_currentState.value = AuthUIState.Loading
|
||||
authSettings.loadingJob.join()
|
||||
if (authSettings.authorizedDIModule.value == null) {
|
||||
_currentState.value = DefaultInitAuthUIState
|
||||
_currentState.value = AuthUIState.DefaultInit
|
||||
} else {
|
||||
_currentState.value = AuthorizedAuthUIState
|
||||
_currentState.value = AuthUIState.Authorized
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun initAuth(serverUrl: String, creds: AuthCreds) {
|
||||
_currentState.value = LoadingAuthUIState
|
||||
_currentState.value = AuthUIState.Loading
|
||||
val authError = authSettings.auth(serverUrl, creds)
|
||||
if (authError == null) {
|
||||
_currentState.value = AuthorizedAuthUIState
|
||||
_currentState.value = AuthUIState.Authorized
|
||||
} else {
|
||||
_currentState.value = InitAuthUIState(authError)
|
||||
_currentState.value = AuthUIState.Init(authError)
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -9,6 +9,8 @@ import dev.inmo.postssystem.features.auth.client.ui.*
|
||||
import dev.inmo.micro_utils.coroutines.launchSafelyWithoutExceptions
|
||||
import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions
|
||||
import dev.inmo.micro_utils.fsm.common.StatesMachine
|
||||
import dev.inmo.postssystem.features.auth.client.ui.AuthUIError.AuthIncorrect
|
||||
import dev.inmo.postssystem.features.auth.client.ui.AuthUIError.ServerUnavailable
|
||||
import dev.inmo.postssystem.features.common.common.*
|
||||
import dev.inmo.postssystem.features.common.common.ui.JSView
|
||||
import dev.inmo.postssystem.features.common.common.ui.fsm.*
|
||||
@@ -19,9 +21,11 @@ import org.jetbrains.compose.web.attributes.InputType
|
||||
import org.jetbrains.compose.web.dom.Text
|
||||
import org.w3c.dom.*
|
||||
|
||||
@ExperimentalStdlibApi
|
||||
@EagerInitialization
|
||||
val loader = DefaultModuleLoader {
|
||||
factory { AuthView(get(), get(DefaultQualifiers.UIScopeQualifier), getAllDistinct()) }
|
||||
singleWithRandomQualifier<UIFSMHandler.Registrator> {
|
||||
singleWithRandomQualifier {
|
||||
UIFSMHandler.Registrator {
|
||||
strictlyOn(get<AuthView>())
|
||||
}
|
||||
@@ -64,13 +68,13 @@ class AuthView(
|
||||
}
|
||||
}
|
||||
|
||||
TextField(
|
||||
StandardInput(
|
||||
InputType.Text,
|
||||
usernameState,
|
||||
disabled,
|
||||
"Username",
|
||||
)
|
||||
TextField(
|
||||
StandardInput(
|
||||
InputType.Password,
|
||||
passwordState,
|
||||
disabled,
|
||||
@@ -90,23 +94,23 @@ class AuthView(
|
||||
|
||||
val viewJob = viewModel.currentState.subscribeSafelyWithoutExceptions(uiScope) {
|
||||
when (it) {
|
||||
is InitAuthUIState -> {
|
||||
is AuthUIState.Init -> {
|
||||
disabled.value = false
|
||||
|
||||
errorText.value = when (it.showError) {
|
||||
ServerUnavailableAuthUIError -> "Server unavailable"
|
||||
AuthIncorrectAuthUIError -> {
|
||||
ServerUnavailable -> "Server unavailable"
|
||||
AuthIncorrect -> {
|
||||
passwordState.value = ""
|
||||
"Username or password is incorrect"
|
||||
}
|
||||
null -> null
|
||||
}
|
||||
}
|
||||
LoadingAuthUIState -> {
|
||||
AuthUIState.Loading -> {
|
||||
disabled.value = true
|
||||
errorText.value = null
|
||||
}
|
||||
AuthorizedAuthUIState -> {
|
||||
AuthUIState.Authorized -> {
|
||||
completion.complete(state.from)
|
||||
}
|
||||
}
|
||||
|
@@ -33,9 +33,10 @@ expect class FileBasedInputProvider : SimpleInputProvider {
|
||||
}
|
||||
|
||||
@Serializable(SimpleInputProviderSerializer::class)
|
||||
class CustomInputProvider(private val provider: () -> Input) : SimpleInputProvider {
|
||||
override val contentBytes: Long?
|
||||
get() = null
|
||||
class CustomInputProvider(
|
||||
override val contentBytes: Long? = null,
|
||||
private val provider: () -> Input
|
||||
) : SimpleInputProvider {
|
||||
override fun invoke(): Input = provider()
|
||||
}
|
||||
|
||||
|
@@ -7,11 +7,7 @@ import kotlinx.serialization.encoding.*
|
||||
import kotlinx.serialization.json.*
|
||||
|
||||
@Serializable(RoleSerializer::class)
|
||||
interface Role {
|
||||
companion object {
|
||||
fun serializer() = RoleSerializer
|
||||
}
|
||||
}
|
||||
interface Role
|
||||
|
||||
@Serializable
|
||||
data class UnknownRole(val originalJson: JsonElement) : Role
|
||||
|
@@ -8,11 +8,7 @@ import kotlinx.serialization.Serializable
|
||||
private val justForLoading = RolesManagerRoleSerializer
|
||||
|
||||
@Serializable(RolesManagerRoleSerializer::class)
|
||||
interface RolesManagerRole : Role {
|
||||
companion object {
|
||||
fun serializer() = RolesManagerRoleSerializer
|
||||
}
|
||||
}
|
||||
interface RolesManagerRole : Role
|
||||
|
||||
@Serializable
|
||||
object GeneralRolesManagerRole : RolesManagerRole {
|
||||
|
Reference in New Issue
Block a user