mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2024-11-25 19:05:56 +03:00
directing to the combined login after homeserver check
- also removes the subtitle view which is not needed for login
This commit is contained in:
parent
4b6f74364d
commit
b3bbb0329e
8 changed files with 71 additions and 79 deletions
|
@ -19,7 +19,6 @@ package im.vector.app.features.onboarding
|
|||
import im.vector.app.R
|
||||
import im.vector.app.core.extensions.andThen
|
||||
import im.vector.app.core.resources.StringProvider
|
||||
import im.vector.app.features.onboarding.OnboardingAction.LoginOrRegister
|
||||
import org.matrix.android.sdk.api.MatrixPatterns.getServerName
|
||||
import org.matrix.android.sdk.api.auth.AuthenticationService
|
||||
import org.matrix.android.sdk.api.auth.data.HomeServerConnectionConfig
|
||||
|
@ -33,7 +32,7 @@ class DirectLoginUseCase @Inject constructor(
|
|||
private val uriFactory: UriFactory
|
||||
) {
|
||||
|
||||
suspend fun execute(action: LoginOrRegister, homeServerConnectionConfig: HomeServerConnectionConfig?): Result<Session> {
|
||||
suspend fun execute(action: OnboardingAction.LoginDirect, homeServerConnectionConfig: HomeServerConnectionConfig?): Result<Session> {
|
||||
return fetchWellKnown(action.username, homeServerConnectionConfig)
|
||||
.andThen { wellKnown -> createSessionFor(wellKnown, action, homeServerConnectionConfig) }
|
||||
}
|
||||
|
@ -42,13 +41,13 @@ class DirectLoginUseCase @Inject constructor(
|
|||
authenticationService.getWellKnownData(matrixId, config)
|
||||
}
|
||||
|
||||
private suspend fun createSessionFor(data: WellknownResult, action: LoginOrRegister, config: HomeServerConnectionConfig?) = when (data) {
|
||||
is WellknownResult.Prompt -> loginDirect(action, data, config)
|
||||
private suspend fun createSessionFor(data: WellknownResult, action: OnboardingAction.LoginDirect, config: HomeServerConnectionConfig?) = when (data) {
|
||||
is WellknownResult.Prompt -> loginDirect(action, data, config)
|
||||
is WellknownResult.FailPrompt -> handleFailPrompt(data, action, config)
|
||||
else -> onWellKnownError()
|
||||
else -> onWellKnownError()
|
||||
}
|
||||
|
||||
private suspend fun handleFailPrompt(data: WellknownResult.FailPrompt, action: LoginOrRegister, config: HomeServerConnectionConfig?): Result<Session> {
|
||||
private suspend fun handleFailPrompt(data: WellknownResult.FailPrompt, action: OnboardingAction.LoginDirect, config: HomeServerConnectionConfig?): Result<Session> {
|
||||
// Relax on IS discovery if homeserver is valid
|
||||
val isMissingInformationToLogin = data.homeServerUrl == null || data.wellKnown == null
|
||||
return when {
|
||||
|
@ -57,7 +56,7 @@ class DirectLoginUseCase @Inject constructor(
|
|||
}
|
||||
}
|
||||
|
||||
private suspend fun loginDirect(action: LoginOrRegister, wellKnownPrompt: WellknownResult.Prompt, config: HomeServerConnectionConfig?): Result<Session> {
|
||||
private suspend fun loginDirect(action: OnboardingAction.LoginDirect, wellKnownPrompt: WellknownResult.Prompt, config: HomeServerConnectionConfig?): Result<Session> {
|
||||
val alteredHomeServerConnectionConfig = config?.updateWith(wellKnownPrompt) ?: fallbackConfig(action, wellKnownPrompt)
|
||||
return runCatching {
|
||||
authenticationService.directAuthentication(
|
||||
|
@ -74,7 +73,7 @@ class DirectLoginUseCase @Inject constructor(
|
|||
identityServerUri = wellKnownPrompt.identityServerUrl?.let { uriFactory.parse(it) }
|
||||
)
|
||||
|
||||
private fun fallbackConfig(action: LoginOrRegister, wellKnownPrompt: WellknownResult.Prompt) = HomeServerConnectionConfig(
|
||||
private fun fallbackConfig(action: OnboardingAction.LoginDirect, wellKnownPrompt: WellknownResult.Prompt) = HomeServerConnectionConfig(
|
||||
homeServerUri = uriFactory.parse("https://${action.username.getServerName()}"),
|
||||
homeServerUriBase = uriFactory.parse(wellKnownPrompt.homeServerUrl),
|
||||
identityServerUri = wellKnownPrompt.identityServerUrl?.let { uriFactory.parse(it) }
|
||||
|
|
|
@ -46,10 +46,9 @@ sealed interface OnboardingAction : VectorViewModelAction {
|
|||
data class ResetPassword(val email: String, val newPassword: String) : OnboardingAction
|
||||
object ResetPasswordMailConfirmed : OnboardingAction
|
||||
|
||||
// Login or Register, depending on the signMode
|
||||
data class LoginOrRegister(val username: String, val password: String, val initialDeviceName: String) : OnboardingAction
|
||||
data class Register(val username: String, val password: String, val initialDeviceName: String) : OnboardingAction
|
||||
data class Login(val username: String, val password: String, val initialDeviceName: String) : OnboardingAction
|
||||
data class LoginDirect(val username: String, val password: String, val initialDeviceName: String) : OnboardingAction
|
||||
object StopEmailValidationCheck : OnboardingAction
|
||||
|
||||
data class PostRegisterAction(val registerAction: RegisterAction) : OnboardingAction
|
||||
|
|
|
@ -139,9 +139,9 @@ class OnboardingViewModel @AssistedInject constructor(
|
|||
is OnboardingAction.UpdateSignMode -> handleUpdateSignMode(action)
|
||||
is OnboardingAction.InitWith -> handleInitWith(action)
|
||||
is OnboardingAction.HomeServerChange -> withAction(action) { handleHomeserverChange(action) }
|
||||
is OnboardingAction.LoginOrRegister -> handleLoginOrRegister(action).also { lastAction = action }
|
||||
is OnboardingAction.Register -> handleRegisterWith(action).also { lastAction = action }
|
||||
is OnboardingAction.Login -> handleLogin(action).also { lastAction = action }
|
||||
is OnboardingAction.LoginDirect -> handleDirectLogin(action, homeServerConnectionConfig = null).also { lastAction = action }
|
||||
is OnboardingAction.LoginWithToken -> handleLoginWithToken(action)
|
||||
is OnboardingAction.WebLoginSuccess -> handleWebLoginSuccess(action)
|
||||
is OnboardingAction.ResetPassword -> handleResetPassword(action)
|
||||
|
@ -215,7 +215,7 @@ class OnboardingViewModel @AssistedInject constructor(
|
|||
?.let { it.copy(allowedFingerprints = it.allowedFingerprints + action.fingerprint) }
|
||||
?.let { startAuthenticationFlow(finalLastAction, it) }
|
||||
}
|
||||
is OnboardingAction.LoginOrRegister ->
|
||||
is OnboardingAction.LoginDirect ->
|
||||
handleDirectLogin(
|
||||
finalLastAction,
|
||||
HomeServerConnectionConfig.Builder()
|
||||
|
@ -488,16 +488,7 @@ class OnboardingViewModel @AssistedInject constructor(
|
|||
}
|
||||
}
|
||||
|
||||
private fun handleLoginOrRegister(action: OnboardingAction.LoginOrRegister) = withState { state ->
|
||||
when (state.signMode) {
|
||||
SignMode.Unknown -> error("Developer error, invalid sign mode")
|
||||
SignMode.SignIn -> handleLogin(OnboardingAction.Login(action.username, action.password, action.initialDeviceName))
|
||||
SignMode.SignUp -> handleRegisterWith(OnboardingAction.Register(action.username, action.password, action.initialDeviceName))
|
||||
SignMode.SignInWithMatrixId -> handleDirectLogin(action, null)
|
||||
}
|
||||
}
|
||||
|
||||
private fun handleDirectLogin(action: OnboardingAction.LoginOrRegister, homeServerConnectionConfig: HomeServerConnectionConfig?) {
|
||||
private fun handleDirectLogin(action: OnboardingAction.LoginDirect, homeServerConnectionConfig: HomeServerConnectionConfig?) {
|
||||
setState { copy(isLoading = true) }
|
||||
currentJob = viewModelScope.launch {
|
||||
directLoginUseCase.execute(action, homeServerConnectionConfig).fold(
|
||||
|
@ -654,7 +645,11 @@ class OnboardingViewModel @AssistedInject constructor(
|
|||
when (trigger) {
|
||||
is OnboardingAction.HomeServerChange.EditHomeServer -> {
|
||||
when (awaitState().onboardingFlow) {
|
||||
OnboardingFlow.SignUp -> internalRegisterAction(RegisterAction.StartRegistration) { _ ->
|
||||
OnboardingFlow.SignUp -> internalRegisterAction(RegisterAction.StartRegistration) {
|
||||
updateServerSelection(config, serverTypeOverride, authResult)
|
||||
_viewEvents.post(OnboardingViewEvents.OnHomeserverEdited)
|
||||
}
|
||||
OnboardingFlow.SignIn -> {
|
||||
updateServerSelection(config, serverTypeOverride, authResult)
|
||||
_viewEvents.post(OnboardingViewEvents.OnHomeserverEdited)
|
||||
}
|
||||
|
@ -667,7 +662,10 @@ class OnboardingViewModel @AssistedInject constructor(
|
|||
when (awaitState().onboardingFlow) {
|
||||
OnboardingFlow.SignIn -> {
|
||||
updateSignMode(SignMode.SignIn)
|
||||
_viewEvents.post(OnboardingViewEvents.OnSignModeSelected(SignMode.SignIn))
|
||||
when (vectorFeatures.isOnboardingCombinedLoginEnabled()) {
|
||||
true -> _viewEvents.post(OnboardingViewEvents.OpenCombinedLogin)
|
||||
false -> _viewEvents.post(OnboardingViewEvents.OnSignModeSelected(SignMode.SignIn))
|
||||
}
|
||||
}
|
||||
OnboardingFlow.SignUp -> {
|
||||
updateSignMode(SignMode.SignUp)
|
||||
|
|
|
@ -26,6 +26,7 @@ import androidx.autofill.HintConstants
|
|||
import androidx.core.text.isDigitsOnly
|
||||
import androidx.core.view.isVisible
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import com.airbnb.mvrx.withState
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
import im.vector.app.R
|
||||
import im.vector.app.core.extensions.hideKeyboard
|
||||
|
@ -119,40 +120,49 @@ class FtueAuthLoginFragment @Inject constructor() : AbstractSSOFtueAuthFragment<
|
|||
}
|
||||
|
||||
private fun submit() {
|
||||
cleanupUi()
|
||||
withState(viewModel) { state ->
|
||||
cleanupUi()
|
||||
|
||||
val login = views.loginField.text.toString()
|
||||
val password = views.passwordField.text.toString()
|
||||
val login = views.loginField.text.toString()
|
||||
val password = views.passwordField.text.toString()
|
||||
|
||||
// This can be called by the IME action, so deal with empty cases
|
||||
var error = 0
|
||||
if (login.isEmpty()) {
|
||||
views.loginFieldTil.error = getString(
|
||||
if (isSignupMode) {
|
||||
R.string.error_empty_field_choose_user_name
|
||||
} else {
|
||||
R.string.error_empty_field_enter_user_name
|
||||
}
|
||||
)
|
||||
error++
|
||||
}
|
||||
if (isSignupMode && isNumericOnlyUserIdForbidden && login.isDigitsOnly()) {
|
||||
views.loginFieldTil.error = getString(R.string.error_forbidden_digits_only_username)
|
||||
error++
|
||||
}
|
||||
if (password.isEmpty()) {
|
||||
views.passwordFieldTil.error = getString(
|
||||
if (isSignupMode) {
|
||||
R.string.error_empty_field_choose_password
|
||||
} else {
|
||||
R.string.error_empty_field_your_password
|
||||
}
|
||||
)
|
||||
error++
|
||||
}
|
||||
// This can be called by the IME action, so deal with empty cases
|
||||
var error = 0
|
||||
if (login.isEmpty()) {
|
||||
views.loginFieldTil.error = getString(
|
||||
if (isSignupMode) {
|
||||
R.string.error_empty_field_choose_user_name
|
||||
} else {
|
||||
R.string.error_empty_field_enter_user_name
|
||||
}
|
||||
)
|
||||
error++
|
||||
}
|
||||
if (isSignupMode && isNumericOnlyUserIdForbidden && login.isDigitsOnly()) {
|
||||
views.loginFieldTil.error = getString(R.string.error_forbidden_digits_only_username)
|
||||
error++
|
||||
}
|
||||
if (password.isEmpty()) {
|
||||
views.passwordFieldTil.error = getString(
|
||||
if (isSignupMode) {
|
||||
R.string.error_empty_field_choose_password
|
||||
} else {
|
||||
R.string.error_empty_field_your_password
|
||||
}
|
||||
)
|
||||
error++
|
||||
}
|
||||
|
||||
if (error == 0) {
|
||||
viewModel.handle(OnboardingAction.LoginOrRegister(login, password, getString(R.string.login_default_session_public_name)))
|
||||
if (error == 0) {
|
||||
val initialDeviceName = getString(R.string.login_default_session_public_name)
|
||||
val action = when (state.signMode) {
|
||||
SignMode.Unknown -> error("developer error")
|
||||
SignMode.SignUp -> OnboardingAction.Register(login, password, initialDeviceName)
|
||||
SignMode.SignIn -> OnboardingAction.Login(login, password, initialDeviceName)
|
||||
SignMode.SignInWithMatrixId -> OnboardingAction.LoginDirect(login, password, initialDeviceName)
|
||||
}
|
||||
viewModel.handle(action)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -46,24 +46,10 @@
|
|||
android:gravity="center"
|
||||
android:text="@string/ftue_auth_welcome_back_title"
|
||||
android:textColor="?vctr_content_primary"
|
||||
app:layout_constraintBottom_toTopOf="@id/createAccountHeaderSubtitle"
|
||||
app:layout_constraintEnd_toEndOf="@id/createAccountGutterEnd"
|
||||
app:layout_constraintStart_toStartOf="@id/createAccountGutterStart"
|
||||
app:layout_constraintTop_toBottomOf="@id/headerSpacing" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/createAccountHeaderSubtitle"
|
||||
style="@style/Widget.Vector.TextView.Subtitle"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="8dp"
|
||||
android:gravity="center"
|
||||
android:text="@string/ftue_auth_create_account_subtitle"
|
||||
android:textColor="?vctr_content_secondary"
|
||||
app:layout_constraintBottom_toTopOf="@id/titleContentSpacing"
|
||||
app:layout_constraintEnd_toEndOf="@id/createAccountGutterEnd"
|
||||
app:layout_constraintStart_toStartOf="@id/createAccountGutterStart"
|
||||
app:layout_constraintTop_toBottomOf="@id/createAccountHeaderTitle" />
|
||||
app:layout_constraintTop_toBottomOf="@id/headerSpacing" />
|
||||
|
||||
<Space
|
||||
android:id="@+id/titleContentSpacing"
|
||||
|
@ -71,7 +57,7 @@
|
|||
android:layout_height="0dp"
|
||||
app:layout_constraintBottom_toTopOf="@id/chooseYourServerHeader"
|
||||
app:layout_constraintHeight_percent="0.03"
|
||||
app:layout_constraintTop_toBottomOf="@id/createAccountHeaderSubtitle" />
|
||||
app:layout_constraintTop_toBottomOf="@id/createAccountHeaderTitle" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/chooseYourServerHeader"
|
||||
|
|
|
@ -32,7 +32,7 @@ import org.matrix.android.sdk.api.auth.data.HomeServerConnectionConfig
|
|||
import org.matrix.android.sdk.api.auth.data.WellKnown
|
||||
import org.matrix.android.sdk.api.auth.wellknown.WellknownResult
|
||||
|
||||
private val A_LOGIN_OR_REGISTER_ACTION = OnboardingAction.LoginOrRegister("@a-user:id.org", "a-password", "a-device-name")
|
||||
private val A_LOGIN_OR_REGISTER_ACTION = OnboardingAction.LoginDirect("@a-user:id.org", "a-password", "a-device-name")
|
||||
private val A_WELLKNOWN_SUCCESS_RESULT = WellknownResult.Prompt("https://homeserverurl.com", identityServerUrl = null, WellKnown())
|
||||
private val A_WELLKNOWN_FAILED_WITH_CONTENT_RESULT = WellknownResult.FailPrompt("https://homeserverurl.com", WellKnown())
|
||||
private val A_WELLKNOWN_FAILED_WITHOUT_CONTENT_RESULT = WellknownResult.FailPrompt(null, null)
|
||||
|
|
|
@ -59,7 +59,7 @@ private val A_RESULT_IGNORED_REGISTER_ACTION = RegisterAction.SendAgainThreePid
|
|||
private val A_HOMESERVER_CAPABILITIES = aHomeServerCapabilities(canChangeDisplayName = true, canChangeAvatar = true)
|
||||
private val AN_IGNORED_FLOW_RESULT = FlowResult(missingStages = emptyList(), completedStages = emptyList())
|
||||
private val ANY_CONTINUING_REGISTRATION_RESULT = RegistrationResult.NextStep(AN_IGNORED_FLOW_RESULT)
|
||||
private val A_LOGIN_OR_REGISTER_ACTION = OnboardingAction.LoginOrRegister("@a-user:id.org", "a-password", "a-device-name")
|
||||
private val A_DIRECT_LOGIN = OnboardingAction.LoginDirect("@a-user:id.org", "a-password", "a-device-name")
|
||||
private const val A_HOMESERVER_URL = "https://edited-homeserver.org"
|
||||
private val A_HOMESERVER_CONFIG = HomeServerConnectionConfig(FakeUri().instance)
|
||||
private val SELECTED_HOMESERVER_STATE = SelectedHomeserverState(preferredLoginMode = LoginMode.Password)
|
||||
|
@ -142,11 +142,11 @@ class OnboardingViewModelTest {
|
|||
@Test
|
||||
fun `given has sign in with matrix id sign mode, when handling login or register action, then logs in directly`() = runTest {
|
||||
viewModelWith(initialState.copy(signMode = SignMode.SignInWithMatrixId))
|
||||
fakeDirectLoginUseCase.givenSuccessResult(A_LOGIN_OR_REGISTER_ACTION, config = null, result = fakeSession)
|
||||
fakeDirectLoginUseCase.givenSuccessResult(A_DIRECT_LOGIN, config = null, result = fakeSession)
|
||||
givenInitialisesSession(fakeSession)
|
||||
val test = viewModel.test()
|
||||
|
||||
viewModel.handle(A_LOGIN_OR_REGISTER_ACTION)
|
||||
viewModel.handle(A_DIRECT_LOGIN)
|
||||
|
||||
test
|
||||
.assertStatesChanges(
|
||||
|
@ -161,11 +161,11 @@ class OnboardingViewModelTest {
|
|||
@Test
|
||||
fun `given has sign in with matrix id sign mode, when handling login or register action fails, then emits error`() = runTest {
|
||||
viewModelWith(initialState.copy(signMode = SignMode.SignInWithMatrixId))
|
||||
fakeDirectLoginUseCase.givenFailureResult(A_LOGIN_OR_REGISTER_ACTION, config = null, cause = AN_ERROR)
|
||||
fakeDirectLoginUseCase.givenFailureResult(A_DIRECT_LOGIN, config = null, cause = AN_ERROR)
|
||||
givenInitialisesSession(fakeSession)
|
||||
val test = viewModel.test()
|
||||
|
||||
viewModel.handle(A_LOGIN_OR_REGISTER_ACTION)
|
||||
viewModel.handle(A_DIRECT_LOGIN)
|
||||
|
||||
test
|
||||
.assertStatesChanges(
|
||||
|
|
|
@ -25,11 +25,11 @@ import org.matrix.android.sdk.api.auth.data.HomeServerConnectionConfig
|
|||
class FakeDirectLoginUseCase {
|
||||
val instance = mockk<DirectLoginUseCase>()
|
||||
|
||||
fun givenSuccessResult(action: OnboardingAction.LoginOrRegister, config: HomeServerConnectionConfig?, result: FakeSession) {
|
||||
fun givenSuccessResult(action: OnboardingAction.LoginDirect, config: HomeServerConnectionConfig?, result: FakeSession) {
|
||||
coEvery { instance.execute(action, config) } returns Result.success(result)
|
||||
}
|
||||
|
||||
fun givenFailureResult(action: OnboardingAction.LoginOrRegister, config: HomeServerConnectionConfig?, cause: Throwable) {
|
||||
fun givenFailureResult(action: OnboardingAction.LoginDirect, config: HomeServerConnectionConfig?, cause: Throwable) {
|
||||
coEvery { instance.execute(action, config) } returns Result.failure(cause)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue