Login screens: prepare email and msisdn
This commit is contained in:
parent
9aa270c7ad
commit
1c03163a33
|
@ -31,5 +31,10 @@ interface RegistrationWizard {
|
|||
|
||||
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
|
||||
|
||||
}
|
||||
|
|
|
@ -42,7 +42,6 @@ internal class DefaultRegistrationWizard(private val homeServerConnectionConfig:
|
|||
private val coroutineDispatchers: MatrixCoroutineDispatchers,
|
||||
private val sessionParamsStore: SessionParamsStore,
|
||||
private val sessionManager: SessionManager) : RegistrationWizard {
|
||||
|
||||
private var currentSession: String? = null
|
||||
|
||||
private val authAPI = buildAuthAPI()
|
||||
|
@ -90,6 +89,48 @@ internal class DefaultRegistrationWizard(private val homeServerConnectionConfig:
|
|||
), 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 {
|
||||
val safeSession = currentSession ?: run {
|
||||
callback.onFailure(IllegalStateException("developer error, call createAccount() method first"))
|
||||
|
|
|
@ -102,13 +102,13 @@ class LoginGenericTextInputFormFragment @Inject constructor() : AbstractLoginFra
|
|||
} else {
|
||||
when (params.mode) {
|
||||
TextInputFormFragmentMode.SetEmail -> {
|
||||
// TODO
|
||||
loginViewModel.handle(LoginAction.AddEmail(text))
|
||||
}
|
||||
TextInputFormFragmentMode.SetMsisdn -> {
|
||||
// TODO
|
||||
loginViewModel.handle(LoginAction.AddMsisdn(text))
|
||||
}
|
||||
TextInputFormFragmentMode.ConfirmMsisdn -> {
|
||||
// TODO
|
||||
loginViewModel.handle(LoginAction.ConfirmMsisdn(text))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -105,10 +105,108 @@ class LoginViewModel @AssistedInject constructor(@Assisted initialState: LoginVi
|
|||
is LoginAction.CaptchaDone -> handleCaptchaDone(action)
|
||||
is LoginAction.AcceptTerms -> handleAcceptTerms()
|
||||
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() {
|
||||
setState {
|
||||
copy(
|
||||
|
|
Loading…
Reference in New Issue