mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2024-11-26 03:16:02 +03:00
Login screens: USER_IN_USE error
This commit is contained in:
parent
41ac2c6d70
commit
381084b2ab
4 changed files with 52 additions and 0 deletions
|
@ -54,6 +54,9 @@ class ErrorFormatter @Inject constructor(private val stringProvider: StringProvi
|
|||
&& throwable.error.message == "Invalid password" -> {
|
||||
stringProvider.getString(R.string.auth_invalid_login_param)
|
||||
}
|
||||
throwable.error.code == MatrixError.USER_IN_USE -> {
|
||||
stringProvider.getString(R.string.login_signup_error_user_in_use)
|
||||
}
|
||||
else -> {
|
||||
throwable.error.message.takeIf { it.isNotEmpty() }
|
||||
?: throwable.error.code.takeIf { it.isNotEmpty() }
|
||||
|
|
|
@ -177,5 +177,18 @@ class LoginFragment @Inject constructor(
|
|||
// Success is handled by the LoginActivity
|
||||
is Success -> Unit
|
||||
}
|
||||
|
||||
when (state.asyncRegistration) {
|
||||
is Loading -> {
|
||||
// Ensure password is hidden
|
||||
passwordShown = false
|
||||
renderPasswordField()
|
||||
}
|
||||
is Fail -> {
|
||||
loginFieldTil.error = errorFormatter.toHumanReadable(state.asyncRegistration.error)
|
||||
}
|
||||
// Success is handled by the LoginActivity
|
||||
is Success -> Unit
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -74,6 +74,24 @@ class LoginViewModel @AssistedInject constructor(@Assisted initialState: LoginVi
|
|||
private var homeServerConnectionConfig: HomeServerConnectionConfig? = null
|
||||
private var currentTask: Cancelable? = null
|
||||
|
||||
private val registrationCallback = object : MatrixCallback<RegistrationResult> {
|
||||
override fun onSuccess(data: RegistrationResult) {
|
||||
when (data) {
|
||||
is RegistrationResult.Success -> onSessionCreated(data.session)
|
||||
is RegistrationResult.FlowResponse -> onFlowResponse(data.flowResult)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onFailure(failure: Throwable) {
|
||||
// TODO Handled JobCancellationException
|
||||
setState {
|
||||
copy(
|
||||
asyncRegistration = Fail(failure)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun handle(action: LoginAction) {
|
||||
when (action) {
|
||||
is LoginAction.UpdateServerType -> handleUpdateServerType(action)
|
||||
|
@ -83,10 +101,27 @@ class LoginViewModel @AssistedInject constructor(@Assisted initialState: LoginVi
|
|||
is LoginAction.Login -> handleLogin(action)
|
||||
is LoginAction.WebLoginSuccess -> handleWebLoginSuccess(action)
|
||||
is LoginAction.ResetPassword -> handleResetPassword(action)
|
||||
is LoginAction.RegisterAction -> handleRegisterAction(action)
|
||||
is LoginAction.ResetAction -> handleResetAction(action)
|
||||
}
|
||||
}
|
||||
|
||||
private fun handleRegisterAction(action: LoginAction.RegisterAction) {
|
||||
when (action) {
|
||||
is LoginAction.RegisterWith -> handleRegisterWith(action)
|
||||
}
|
||||
}
|
||||
|
||||
private fun handleRegisterWith(action: LoginAction.RegisterWith) {
|
||||
setState {
|
||||
copy(
|
||||
asyncRegistration = Loading()
|
||||
)
|
||||
}
|
||||
|
||||
currentTask = registrationWizard?.createAccount(action.username, action.password, null /* TODO InitialDisplayName */, registrationCallback)
|
||||
}
|
||||
|
||||
private fun handleResetAction(action: LoginAction.ResetAction) {
|
||||
// Cancel any request
|
||||
currentTask?.cancel()
|
||||
|
|
|
@ -93,5 +93,6 @@
|
|||
<string name="login_signup_username_hint">Username</string>
|
||||
<string name="login_signup_password_hint">Password</string>
|
||||
<string name="login_signup_submit">Next</string>
|
||||
<string name="login_signup_error_user_in_use">That username is taken</string>
|
||||
|
||||
</resources>
|
||||
|
|
Loading…
Reference in a new issue