diff --git a/auth/src/main/java/org/futo/circles/auth/feature/uia/UIADataSource.kt b/auth/src/main/java/org/futo/circles/auth/feature/uia/UIADataSource.kt index 741c1161ae33085cef7db8ee2008c131e1518ac9..83bf5a80c6ed524c9cbbe6415877ae60806e1485 100644 --- a/auth/src/main/java/org/futo/circles/auth/feature/uia/UIADataSource.kt +++ b/auth/src/main/java/org/futo/circles/auth/feature/uia/UIADataSource.kt @@ -9,6 +9,7 @@ import org.futo.circles.auth.model.UIANavigationEvent import org.futo.circles.core.base.SingleEventLiveData import org.futo.circles.core.extensions.Response import org.matrix.android.sdk.api.auth.UIABaseAuth +import org.matrix.android.sdk.api.auth.data.LoginFlowTypes import org.matrix.android.sdk.api.auth.registration.RegistrationFlowResponse import org.matrix.android.sdk.api.auth.registration.RegistrationResult import org.matrix.android.sdk.api.auth.registration.Stage @@ -89,6 +90,11 @@ abstract class UIADataSource { } ?: navigateToNextStage() } + fun getCurrentStageKey() = when (currentStage) { + is Stage.Other -> (currentStage as Stage.Other).type + else -> LoginFlowTypes.TERMS + } + private fun isStageRetry(result: RegistrationResult?): Boolean { val nextStageType = ((result as? RegistrationResult.FlowResponse)?.flowResult?.missingStages?.firstOrNull() as? Stage.Other)?.type diff --git a/auth/src/main/java/org/futo/circles/auth/feature/uia/stages/password/BsSpekeStageDataSource.kt b/auth/src/main/java/org/futo/circles/auth/feature/uia/stages/password/BsSpekeStageDataSource.kt index 1c710998ac95dd18348fc2032888a0adddb2a1c5..fb2a8b92813fdbcb858298e6775c518c8152755d 100644 --- a/auth/src/main/java/org/futo/circles/auth/feature/uia/stages/password/BsSpekeStageDataSource.kt +++ b/auth/src/main/java/org/futo/circles/auth/feature/uia/stages/password/BsSpekeStageDataSource.kt @@ -6,13 +6,12 @@ import dagger.hilt.android.qualifiers.ApplicationContext import org.futo.circles.auth.R import org.futo.circles.auth.bsspeke.BSSpekeClient import org.futo.circles.auth.bsspeke.BSSpekeClientProvider -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.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.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.TYPE_PARAM_KEY import org.futo.circles.auth.feature.uia.UIADataSourceProvider -import org.futo.circles.auth.model.UIAFlowType import org.futo.circles.core.extensions.Response import org.matrix.android.sdk.api.auth.registration.RegistrationResult import org.matrix.android.sdk.api.auth.registration.Stage @@ -24,7 +23,11 @@ class BsSpekeStageDataSource @Inject constructor( private val uiaDataSource = UIADataSourceProvider.getDataSourceOrThrow() + private var isVerifyStages = true + suspend fun processPasswordStage(password: String): Response<Unit> { + val currentStageKey = uiaDataSource.getCurrentStageKey() + isVerifyStages = currentStageKey == LOGIN_BSSPEKE_OPRF_TYPE || currentStageKey== LOGIN_BSSPEKE_VERIFY_TYPE BSSpekeClientProvider.initClient(uiaDataSource.userName, uiaDataSource.domain, password) val bsSpekeClient = BSSpekeClientProvider.getClientOrThrow() return when (val oprfResult = performOprfStage(bsSpekeClient)) { @@ -36,10 +39,8 @@ class BsSpekeStageDataSource @Inject constructor( } } - private fun isLoginMode() = UIADataSourceProvider.activeFlowType == UIAFlowType.Login - - private fun getOprfTypeKey() = - if (isLoginMode()) LOGIN_BSSPEKE_OPRF_TYPE else ENROLL_BSSPEKE_OPRF_TYPE + private fun getOprfTypeKey() = if (isVerifyStages) LOGIN_BSSPEKE_OPRF_TYPE + else ENROLL_BSSPEKE_OPRF_TYPE private suspend fun performOprfStage( bsSpekeClient: BSSpekeClient @@ -66,7 +67,7 @@ class BsSpekeStageDataSource @Inject constructor( return Response.Error(e.message ?: "") } return when (val result = - if (isLoginMode()) performVerifyStage( + if (isVerifyStages) performVerifyStage( oprfResult, bsSpekeClient, password, blocks, iterations ) else performSaveStage(