Skip to content
Snippets Groups Projects
Commit 8ffd0b80 authored by Taras's avatar Taras
Browse files

Clean up password ds

parent 0ab5d594
No related branches found
No related tags found
Loading
......@@ -4,19 +4,18 @@ import android.content.Context
import dagger.hilt.android.qualifiers.ApplicationContext
import org.futo.circles.auth.R
import org.futo.circles.auth.feature.uia.UIADataSource.Companion.DIRECT_LOGIN_PASSWORD_TYPE
import org.futo.circles.auth.feature.uia.UIADataSource.Companion.LOGIN_BSSPEKE_OPRF_TYPE
import org.futo.circles.auth.feature.uia.UIADataSource.Companion.LOGIN_PASSWORD_TYPE
import org.futo.circles.auth.feature.uia.UIADataSource.Companion.ENROLL_BSSPEKE_OPRF_TYPE
import org.futo.circles.auth.feature.uia.UIADataSource.Companion.ENROLL_BSSPEKE_SAVE_TYPE
import org.futo.circles.auth.feature.uia.UIADataSource.Companion.ENROLL_PASSWORD_TYPE
import org.futo.circles.auth.feature.uia.UIADataSource.Companion.LOGIN_BSSPEKE_OPRF_TYPE
import org.futo.circles.auth.feature.uia.UIADataSource.Companion.LOGIN_BSSPEKE_VERIFY_TYPE
import org.futo.circles.auth.feature.uia.UIADataSource.Companion.LOGIN_PASSWORD_TYPE
import org.futo.circles.auth.feature.uia.UIADataSource.Companion.TYPE_PARAM_KEY
import org.futo.circles.auth.feature.uia.UIADataSourceProvider
import org.futo.circles.core.extensions.Response
import org.futo.circles.core.extensions.createResult
import org.futo.circles.core.provider.MatrixInstanceProvider
import org.matrix.android.sdk.api.auth.registration.RegistrationResult
import org.matrix.android.sdk.api.auth.registration.Stage
import javax.inject.Inject
class PasswordDataSource @Inject constructor(
......@@ -29,41 +28,34 @@ class PasswordDataSource @Inject constructor(
suspend fun processPasswordStage(password: String): Response<Unit> =
when (uiaDataSource.getCurrentStageKey()) {
LOGIN_BSSPEKE_OPRF_TYPE, ENROLL_BSSPEKE_OPRF_TYPE,
LOGIN_BSSPEKE_VERIFY_TYPE, ENROLL_BSSPEKE_SAVE_TYPE->
LOGIN_BSSPEKE_VERIFY_TYPE, ENROLL_BSSPEKE_SAVE_TYPE ->
bsSpekeStageDataSource.processPasswordStage(password)
ENROLL_PASSWORD_TYPE -> processRegistrationPasswordStage(password)
LOGIN_PASSWORD_TYPE -> processPasswordStageL(password)
ENROLL_PASSWORD_TYPE -> processCirclesPasswordStage(password, false)
LOGIN_PASSWORD_TYPE -> processCirclesPasswordStage(password, true)
DIRECT_LOGIN_PASSWORD_TYPE -> processDirectPasswordStage(password)
else -> throw IllegalArgumentException("Unsupported password stage")
}
private suspend fun processRegistrationPasswordStage(password: String): Response<Unit> =
when (val result = uiaDataSource.performUIAStage(
private suspend fun processCirclesPasswordStage(
password: String,
isLogin: Boolean
): Response<Unit> {
val type = if (isLogin) LOGIN_PASSWORD_TYPE else ENROLL_PASSWORD_TYPE
val passwordKey = if (isLogin) LOGIN_PASSWORD_PARAM_KEY else REGISTRATION_PASSWORD_PARAM_KEY
return when (val result = uiaDataSource.performUIAStage(
mapOf(
TYPE_PARAM_KEY to ENROLL_PASSWORD_TYPE,
REGISTRATION_PASSWORD_PARAM_KEY to password
TYPE_PARAM_KEY to type,
passwordKey to password
)
)) {
is Response.Success -> Response.Success(Unit)
is Response.Error -> result
}
private suspend fun processPasswordStageL(password: String): Response<Unit> {
val result = uiaDataSource.performUIAStage(
mapOf(
TYPE_PARAM_KEY to LOGIN_PASSWORD_TYPE,
LOGIN_PASSWORD_PARAM_KEY to password
), password
)
return when (result) {
is Response.Success -> Response.Success(Unit)
is Response.Error -> result
}
}
private suspend fun processDirectPasswordStage(password: String): Response<Unit> {
val result = createResult {
MatrixInstanceProvider.matrix.authenticationService().getLoginWizard().login(
......
......@@ -47,7 +47,7 @@ class PasswordFragment : ParentBackPressOwnerFragment(R.layout.fragment_password
setText(getString(if (isSignupMode()) R.string.set_password else R.string.log_in))
setOnClickListener {
startLoading(btnLogin)
viewModel.loginWithPassword(tilPassword.getText())
viewModel.processPasswordStage(tilPassword.getText())
}
}
tilPassword.editText?.apply {
......
......@@ -15,7 +15,7 @@ class PasswordViewModel @Inject constructor(
private var isPasswordWarningConfirmed: Boolean = false
val passwordResponseLiveData = SingleEventLiveData<Response<Unit>>()
fun loginWithPassword(password: String) {
fun processPasswordStage(password: String) {
launchBg {
passwordResponseLiveData.postValue(passwordDataSource.processPasswordStage(password))
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment