Login screens: prepare email and msisdn

This commit is contained in:
Benoit Marty 2019-11-19 15:13:50 +01:00
parent 9aa270c7ad
commit 1c03163a33
4 changed files with 150 additions and 6 deletions

View File

@ -31,5 +31,10 @@ interface RegistrationWizard {
fun dummy(callback: MatrixCallback<RegistrationResult>): Cancelable fun dummy(callback: MatrixCallback<RegistrationResult>): Cancelable
// TODO Add other method here fun addEmail(email: String, callback: MatrixCallback<RegistrationResult>): Cancelable
fun addMsisdn(msisdn: String, callback: MatrixCallback<RegistrationResult>): Cancelable
fun confirmMsisdn(code: String, callback: MatrixCallback<RegistrationResult>): Cancelable
} }

View File

@ -42,7 +42,6 @@ internal class DefaultRegistrationWizard(private val homeServerConnectionConfig:
private val coroutineDispatchers: MatrixCoroutineDispatchers, private val coroutineDispatchers: MatrixCoroutineDispatchers,
private val sessionParamsStore: SessionParamsStore, private val sessionParamsStore: SessionParamsStore,
private val sessionManager: SessionManager) : RegistrationWizard { private val sessionManager: SessionManager) : RegistrationWizard {
private var currentSession: String? = null private var currentSession: String? = null
private val authAPI = buildAuthAPI() private val authAPI = buildAuthAPI()
@ -90,6 +89,48 @@ internal class DefaultRegistrationWizard(private val homeServerConnectionConfig:
), callback) ), callback)
} }
override fun addEmail(email: String, callback: MatrixCallback<RegistrationResult>): Cancelable {
val safeSession = currentSession ?: run {
callback.onFailure(IllegalStateException("developer error, call createAccount() method first"))
return NoOpCancellable
}
// TODO
return performRegistrationRequest(
RegistrationParams(
// TODO
auth = AuthParams.createForEmailIdentity(safeSession, ThreePidCredentials(email))
), callback)
}
override fun addMsisdn(msisdn: String, callback: MatrixCallback<RegistrationResult>): Cancelable {
val safeSession = currentSession ?: run {
callback.onFailure(IllegalStateException("developer error, call createAccount() method first"))
return NoOpCancellable
}
// TODO
return performRegistrationRequest(
RegistrationParams(
// TODO
auth = AuthParams.createForEmailIdentity(safeSession, ThreePidCredentials(msisdn))
), callback)
}
override fun confirmMsisdn(code: String, callback: MatrixCallback<RegistrationResult>): Cancelable {
val safeSession = currentSession ?: run {
callback.onFailure(IllegalStateException("developer error, call createAccount() method first"))
return NoOpCancellable
}
// TODO
return performRegistrationRequest(
RegistrationParams(
// TODO
auth = AuthParams.createForEmailIdentity(safeSession, ThreePidCredentials(code))
), callback)
}
override fun dummy(callback: MatrixCallback<RegistrationResult>): Cancelable { override fun dummy(callback: MatrixCallback<RegistrationResult>): Cancelable {
val safeSession = currentSession ?: run { val safeSession = currentSession ?: run {
callback.onFailure(IllegalStateException("developer error, call createAccount() method first")) callback.onFailure(IllegalStateException("developer error, call createAccount() method first"))

View File

@ -102,13 +102,13 @@ class LoginGenericTextInputFormFragment @Inject constructor() : AbstractLoginFra
} else { } else {
when (params.mode) { when (params.mode) {
TextInputFormFragmentMode.SetEmail -> { TextInputFormFragmentMode.SetEmail -> {
// TODO loginViewModel.handle(LoginAction.AddEmail(text))
} }
TextInputFormFragmentMode.SetMsisdn -> { TextInputFormFragmentMode.SetMsisdn -> {
// TODO loginViewModel.handle(LoginAction.AddMsisdn(text))
} }
TextInputFormFragmentMode.ConfirmMsisdn -> { TextInputFormFragmentMode.ConfirmMsisdn -> {
// TODO loginViewModel.handle(LoginAction.ConfirmMsisdn(text))
} }
} }
} }

View File

@ -105,10 +105,108 @@ class LoginViewModel @AssistedInject constructor(@Assisted initialState: LoginVi
is LoginAction.CaptchaDone -> handleCaptchaDone(action) is LoginAction.CaptchaDone -> handleCaptchaDone(action)
is LoginAction.AcceptTerms -> handleAcceptTerms() is LoginAction.AcceptTerms -> handleAcceptTerms()
is LoginAction.RegisterDummy -> handleRegisterDummy() is LoginAction.RegisterDummy -> handleRegisterDummy()
// TODO Add other actions here is LoginAction.AddEmail -> handleAddEmail(action)
is LoginAction.AddMsisdn -> handleAddMsisdn(action)
is LoginAction.ConfirmMsisdn -> handleConfirmMsisdn(action)
} }
} }
private fun handleConfirmMsisdn(action: LoginAction.ConfirmMsisdn) {
setState {
copy(
asyncRegistration = Loading()
)
}
currentTask = registrationWizard?.confirmMsisdn(action.code, object : MatrixCallback<RegistrationResult> {
override fun onSuccess(data: RegistrationResult) {
setState {
copy(
asyncRegistration = Success(data)
)
}
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)
)
}
}
})
}
private fun handleAddMsisdn(action: LoginAction.AddMsisdn) {
setState {
copy(
asyncRegistration = Loading()
)
}
currentTask = registrationWizard?.addMsisdn(action.msisdn, object : MatrixCallback<RegistrationResult> {
override fun onSuccess(data: RegistrationResult) {
setState {
copy(
asyncRegistration = Success(data)
)
}
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)
)
}
}
})
}
private fun handleAddEmail(action: LoginAction.AddEmail) {
setState {
copy(
asyncRegistration = Loading()
)
}
currentTask = registrationWizard?.addEmail(action.email, object : MatrixCallback<RegistrationResult> {
override fun onSuccess(data: RegistrationResult) {
setState {
copy(
asyncRegistration = Success(data)
)
}
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)
)
}
}
})
}
private fun handleAcceptTerms() { private fun handleAcceptTerms() {
setState { setState {
copy( copy(