Allows authentication by email

This commit is contained in:
ganfra 2018-11-03 11:49:18 +01:00
parent 2885b510ab
commit b3fe742ec4
3 changed files with 13 additions and 1 deletions

View File

@ -1,5 +1,6 @@
package im.vector.matrix.android.internal.auth package im.vector.matrix.android.internal.auth
import android.util.Patterns
import arrow.core.Either import arrow.core.Either
import arrow.core.leftIfNull import arrow.core.leftIfNull
import im.vector.matrix.android.api.MatrixCallback import im.vector.matrix.android.api.MatrixCallback
@ -11,6 +12,7 @@ import im.vector.matrix.android.api.util.Cancelable
import im.vector.matrix.android.internal.auth.data.Credentials import im.vector.matrix.android.internal.auth.data.Credentials
import im.vector.matrix.android.internal.auth.data.PasswordLoginParams import im.vector.matrix.android.internal.auth.data.PasswordLoginParams
import im.vector.matrix.android.internal.auth.data.SessionParams import im.vector.matrix.android.internal.auth.data.SessionParams
import im.vector.matrix.android.internal.auth.data.ThreePidMedium
import im.vector.matrix.android.internal.network.executeRequest import im.vector.matrix.android.internal.network.executeRequest
import im.vector.matrix.android.internal.session.DefaultSession import im.vector.matrix.android.internal.session.DefaultSession
import im.vector.matrix.android.internal.util.CancelableCoroutine import im.vector.matrix.android.internal.util.CancelableCoroutine
@ -53,7 +55,11 @@ class DefaultAuthenticator(private val retrofitBuilder: Retrofit.Builder,
password: String): Either<Failure, Session> = withContext(coroutineDispatchers.io) { password: String): Either<Failure, Session> = withContext(coroutineDispatchers.io) {
val authAPI = buildAuthAPI(homeServerConnectionConfig) val authAPI = buildAuthAPI(homeServerConnectionConfig)
val loginParams = PasswordLoginParams.userIdentifier(login, password, "Mobile") val loginParams = if (Patterns.EMAIL_ADDRESS.matcher(login).matches()) {
PasswordLoginParams.thirdPartyIdentifier(ThreePidMedium.EMAIL, login, password, "Mobile")
} else {
PasswordLoginParams.userIdentifier(login, password, "Mobile")
}
executeRequest<Credentials> { executeRequest<Credentials> {
apiCall = authAPI.login(loginParams) apiCall = authAPI.login(loginParams)
}.leftIfNull { }.leftIfNull {

View File

@ -0,0 +1,6 @@
package im.vector.matrix.android.internal.auth.data
object ThreePidMedium {
const val EMAIL = "email"
const val MSISDN = "msisdn"
}