Login screens: handle mandatory dummy stage automatically

This commit is contained in:
Benoit Marty 2019-11-25 16:47:17 +01:00
parent f84ec08847
commit 6cb3c222a9
5 changed files with 20 additions and 12 deletions

View file

@ -30,8 +30,9 @@ sealed class Stage(open val mandatory: Boolean) {
// m.login.token // m.login.token
// m.login.dummy, never mandatory by definition // m.login.dummy, can be mandatory if there is no other stages. In this case the account cannot be created by just sending a username
object Dummy : Stage(false) // and a password, the dummy stage has to be done
data class Dummy(override val mandatory: Boolean) : Stage(mandatory)
// Undocumented yet: m.login.terms // Undocumented yet: m.login.terms
data class Terms(override val mandatory: Boolean, val policies: TermPolicies) : Stage(mandatory) data class Terms(override val mandatory: Boolean, val policies: TermPolicies) : Stage(mandatory)

View file

@ -81,7 +81,7 @@ fun RegistrationFlowResponse.toFlowResult(): FlowResult {
val stage = when (type) { val stage = when (type) {
LoginFlowTypes.RECAPTCHA -> Stage.ReCaptcha(isMandatory, ((params?.get(type) as? Map<*, *>)?.get("public_key") as? String) LoginFlowTypes.RECAPTCHA -> Stage.ReCaptcha(isMandatory, ((params?.get(type) as? Map<*, *>)?.get("public_key") as? String)
?: "") ?: "")
LoginFlowTypes.DUMMY -> Stage.Dummy LoginFlowTypes.DUMMY -> Stage.Dummy(isMandatory)
LoginFlowTypes.TERMS -> Stage.Terms(isMandatory, params?.get(type) as? TermPolicies ?: emptyMap<String, String>()) LoginFlowTypes.TERMS -> Stage.Terms(isMandatory, params?.get(type) as? TermPolicies ?: emptyMap<String, String>())
LoginFlowTypes.EMAIL_IDENTITY -> Stage.Email(isMandatory) LoginFlowTypes.EMAIL_IDENTITY -> Stage.Email(isMandatory)
LoginFlowTypes.MSISDN -> Stage.Msisdn(isMandatory) LoginFlowTypes.MSISDN -> Stage.Msisdn(isMandatory)

View file

@ -128,14 +128,14 @@ class LoginActivity : VectorBaseActivity(), ToolbarConfigurable {
} }
is LoginNavigation.OnSendEmailSuccess -> is LoginNavigation.OnSendEmailSuccess ->
addFragmentToBackstack(R.id.loginFragmentContainer, addFragmentToBackstack(R.id.loginFragmentContainer,
LoginWaitForEmailFragment::class.java, LoginWaitForEmailFragment::class.java,
LoginWaitForEmailFragmentArgument(loginNavigation.email), LoginWaitForEmailFragmentArgument(loginNavigation.email),
tag = FRAGMENT_REGISTRATION_STAGE_TAG) tag = FRAGMENT_REGISTRATION_STAGE_TAG)
is LoginNavigation.OnSendMsisdnSuccess -> is LoginNavigation.OnSendMsisdnSuccess ->
addFragmentToBackstack(R.id.loginFragmentContainer, addFragmentToBackstack(R.id.loginFragmentContainer,
LoginGenericTextInputFormFragment::class.java, LoginGenericTextInputFormFragment::class.java,
LoginGenericTextInputFormFragmentArgument(TextInputFormFragmentMode.ConfirmMsisdn, true, loginNavigation.msisdn), LoginGenericTextInputFormFragmentArgument(TextInputFormFragmentMode.ConfirmMsisdn, true, loginNavigation.msisdn),
tag = FRAGMENT_REGISTRATION_STAGE_TAG) tag = FRAGMENT_REGISTRATION_STAGE_TAG)
} }
} }

View file

@ -27,6 +27,7 @@ import im.vector.matrix.android.api.auth.login.LoginWizard
import im.vector.matrix.android.api.auth.registration.FlowResult import im.vector.matrix.android.api.auth.registration.FlowResult
import im.vector.matrix.android.api.auth.registration.RegistrationResult import im.vector.matrix.android.api.auth.registration.RegistrationResult
import im.vector.matrix.android.api.auth.registration.RegistrationWizard import im.vector.matrix.android.api.auth.registration.RegistrationWizard
import im.vector.matrix.android.api.auth.registration.Stage
import im.vector.matrix.android.api.session.Session import im.vector.matrix.android.api.session.Session
import im.vector.matrix.android.api.util.Cancelable import im.vector.matrix.android.api.util.Cancelable
import im.vector.matrix.android.api.util.MatrixCallbackDelegate import im.vector.matrix.android.api.util.MatrixCallbackDelegate
@ -450,8 +451,14 @@ class LoginViewModel @AssistedInject constructor(@Assisted initialState: LoginVi
} }
private fun onFlowResponse(flowResult: FlowResult) { private fun onFlowResponse(flowResult: FlowResult) {
// Notify the user // If dummy stage is mandatory, and password is already sent, do the dummy stage now
_viewEvents.post(LoginViewEvents.RegistrationFlowResult(flowResult)) if (isRegistrationStarted
&& flowResult.missingStages.any { it is Stage.Dummy && it.mandatory }) {
handleRegisterDummy()
} else {
// Notify the user
_viewEvents.post(LoginViewEvents.RegistrationFlowResult(flowResult))
}
} }
private fun onSessionCreated(session: Session) { private fun onSessionCreated(session: Session) {

View file

@ -19,7 +19,7 @@ package im.vector.riotx.features.login
import im.vector.matrix.android.api.auth.registration.Stage import im.vector.matrix.android.api.auth.registration.Stage
/** /**
* Stage.Other is not supported, as well as any other new stage added to the SDK before it is added to the list below * Stage.Other is not supported, as well as any other new stages added to the SDK before it is added to the list below
*/ */
fun Stage.isSupported(): Boolean { fun Stage.isSupported(): Boolean {
return this is Stage.ReCaptcha return this is Stage.ReCaptcha