EquinoxAuthViewModel

abstract class EquinoxAuthViewModel(    val snackbarHostState: SnackbarHostState,     val requester: EquinoxRequester,     val localUser: EquinoxLocalUser) : EquinoxViewModel

The EquinoxAuthViewModel class is the support class used to execute the authentication requests to the backend

Author

N7ghtm4r3 - Tecknobit

Parameters

snackbarHostState

The host to launch the snackbar messages

requester

The instance to manage the requests with the backend

localUser

The user of the current logged-in session, used to make the requests to the backend

See also

Constructors

Link copied to clipboard
constructor(snackbarHostState: SnackbarHostState, requester: EquinoxRequester, localUser: EquinoxLocalUser)

Properties

Link copied to clipboard
lateinit var email: MutableState<String>

email the email of the user

Link copied to clipboard

emailError whether the email field is not valid

Link copied to clipboard
lateinit var host: MutableState<String>

host the value of the host to reach

Link copied to clipboard

hostError whether the host field is not valid

Link copied to clipboard

isSignUp whether the auth request to execute is sign up or sign in

Link copied to clipboard
Link copied to clipboard
lateinit var name: MutableState<String>

name the name of the user

Link copied to clipboard

nameError whether the name field is not valid

Link copied to clipboard

password the password of the user

Link copied to clipboard

passwordError whether the password field is not valid

Link copied to clipboard
Link copied to clipboard
private val retriever: Retriever

retriever the manager used to fetch the data from the backend

Link copied to clipboard

serverSecret the value of the server secret

Link copied to clipboard

serverSecretError whether the serverSecret field is not valid

Link copied to clipboard
Link copied to clipboard
lateinit var surname: MutableState<String>

surname the surname of the user

Link copied to clipboard

surnameError whether the surname field is not valid

Functions

Link copied to clipboard
expect open fun addCloseable(closeable: AutoCloseable)
expect fun addCloseable(key: String, closeable: AutoCloseable)
Link copied to clipboard
fun auth()

Wrapper function to execute the specific authentication request

Link copied to clipboard
open override fun canRetrieverStart(): Boolean

Method used to get whether the viewModelScope can start, so if there aren't other jobs that routine is already executing

Link copied to clipboard
open override fun continueToRetrieve(currentContext: KClass<*>): Boolean

Method used to suspend the current viewModelScope to execute other requests to the backend, the isRefreshing instance will be set as false to allow the restart of the routine after executing the other requests

Link copied to clipboard
expect fun <T : AutoCloseable> getCloseable(key: String): T?
Link copied to clipboard
protected open fun getSignInCustomParameters(): Array<out Any?>

Method used to get the list of the custom parameters to use in the signIn request.

Link copied to clipboard
protected open fun getSignUpCustomParameters(): Array<out Any?>

Method used to get the list of the custom parameters to use in the signUp request

Link copied to clipboard
protected fun getUserLanguage(): String

Method used to get the current user language

Link copied to clipboard

Method used to get a supported language for the user

Link copied to clipboard
protected open fun launchApp(response: JsonObject, name: String, surname: String, language: String, vararg custom: Any?)

Method used to launch the application after the authentication request, will be instantiated with the user details both the requester and the localUser

Link copied to clipboard
protected expect open fun onCleared()
Link copied to clipboard
open override fun restartRetriever()

Method used to restart the current viewModelScope after other requests has been executed, the isRefreshing instance will be set as true to deny the restart of the routine after executing the other requests

Link copied to clipboard
open fun restartRetrieverIf(condition: Boolean)

Method used to conditionally restart the current retrieverScope after other requests has been executed, the isRefreshing instance will be set as true to deny the restart of the routine after executing the other requests

Link copied to clipboard
open override fun retrieve(currentContext: KClass<*>, routine: suspend () -> Unit, repeatRoutine: Boolean, refreshDelay: Long)

Method used to execute the refresh routine designed

Link copied to clipboard
open fun setActiveContext(currentContext: KClass<*>)

Method used to set the current active context where the retrieverScope is executing

Link copied to clipboard
fun showSnackbarMessage(    message: String,     actionLabel: String? = null,     onDismiss: () -> Unit? = null,     onActionPerformed: () -> Unit? = null,     withDismissAction: Boolean = false,     duration: SnackbarDuration = if (actionLabel == null) SnackbarDuration.Short else SnackbarDuration.Indefinite)
fun showSnackbarMessage(    response: JsonObject,     actionLabel: String? = null,     onDismiss: () -> Unit? = null,     onActionPerformed: () -> Unit? = null,     withDismissAction: Boolean = false,     duration: SnackbarDuration = if (actionLabel == null) SnackbarDuration.Short else SnackbarDuration.Indefinite)
fun showSnackbarMessage(    message: StringResource,     actionLabel: StringResource? = null,     onDismiss: () -> Unit? = null,     onActionPerformed: () -> Unit? = null,     withDismissAction: Boolean = false,     duration: SnackbarDuration = if (actionLabel == null) SnackbarDuration.Short else SnackbarDuration.Indefinite)

Method used to display a response message with a snackbar

Link copied to clipboard
private fun signIn(onFailure: (JsonObject) -> Unit = { showSnackbarMessage(it) })

Method used to execute the sign in authentication request, if successful the localUser will be initialized with the data received by the request

Link copied to clipboard
protected open fun signInFormIsValid(): Boolean

Method used to validate the inputs for the signIn request

Link copied to clipboard
private fun signUp(onFailure: (JsonObject) -> Unit = { showSnackbarMessage(it) })

Method used to execute the sign-up authentication request, if successful the localUser will be initialized with the data received by the request

Link copied to clipboard
protected open fun signUpFormIsValid(): Boolean

Method used to validate the inputs for the signUp request

Link copied to clipboard
open override fun suspendRetriever()

Method used to suspend the current viewModelScope to execute other requests to the backend, the isRefreshing instance will be set as false to allow the restart of the routine after executing the other requests

Link copied to clipboard
open fun suspendRetrieverIf(condition: Boolean)

Method used to conditionally suspend the current retrieverScope to execute other requests to the backend, the isRefreshing instance will be set as false to allow the restart of the routine after executing the other requests