Login screens: Add Msisdn - WIP

This commit is contained in:
Benoit Marty 2019-11-20 17:56:14 +01:00
parent b8a3ad0c43
commit 248a584e1a
3 changed files with 45 additions and 8 deletions

View file

@ -37,5 +37,18 @@ internal data class AddThreePidRegistrationResponse(
* the homeserver advertises this specification version in the /versions response (ie: r0.5.0).
*/
@Json(name = "submit_url")
val submitUrl: String? = null
val submitUrl: String? = null,
/* ==========================================================================================
* It seems that the homeserver is sending more data, we may need it
* ========================================================================================== */
@Json(name = "msisdn")
val msisdn: String? = null,
@Json(name = "intl_fmt")
val formattedMsisdn: String? = null,
@Json(name = "success")
val success: Boolean? = null
)

View file

@ -60,6 +60,14 @@ internal data class AuthParams(
threePidCredentials = threePidCredentials
)
}
fun createForMsisdnIdentity(session: String, threePidCredentials: ThreePidCredentials): AuthParams {
return AuthParams(
type = LoginFlowTypes.MSISDN,
session = session,
threePidCredentials = threePidCredentials
)
}
}
}

View file

@ -42,6 +42,7 @@ import java.util.*
// Container to store the data when a three pid is in validation step
internal data class ThreePidData(
val threePid: RegisterThreePid,
val addThreePidRegistrationResponse: AddThreePidRegistrationResponse,
val registrationParams: RegistrationParams
)
@ -69,7 +70,10 @@ internal class DefaultRegistrationWizard(private val homeServerConnectionConfig:
get() {
return when (val threePid = currentThreePidData?.threePid) {
is RegisterThreePid.Email -> threePid.email
is RegisterThreePid.Msisdn -> threePid.msisdn
is RegisterThreePid.Msisdn -> {
// Take formatted msisdn if provided by the server
currentThreePidData?.addThreePidRegistrationResponse?.formattedMsisdn?.takeIf { it.isNotBlank() } ?: threePid.msisdn
}
null -> null
}
}
@ -122,6 +126,8 @@ internal class DefaultRegistrationWizard(private val homeServerConnectionConfig:
return NoOpCancellable
}
currentThreePidData = null
val job = GlobalScope.launch(coroutineDispatchers.main) {
runCatching {
registerAddThreePidTask.execute(RegisterAddThreePidTask.Params(threePid, clientSecret, sendAttempt++))
@ -131,13 +137,23 @@ internal class DefaultRegistrationWizard(private val homeServerConnectionConfig:
// Store data
currentThreePidData = ThreePidData(
threePid,
it,
RegistrationParams(
auth = AuthParams.createForEmailIdentity(safeSession,
ThreePidCredentials(
clientSecret = clientSecret,
sid = it.sid
)
)
auth = if (threePid is RegisterThreePid.Email) {
AuthParams.createForEmailIdentity(safeSession,
ThreePidCredentials(
clientSecret = clientSecret,
sid = it.sid
)
)
} else {
AuthParams.createForMsisdnIdentity(safeSession,
ThreePidCredentials(
clientSecret = clientSecret,
sid = it.sid
)
)
}
))
.also { threePidData ->
// and send the sid a first time