Skip to content
Snippets Groups Projects
Commit 708431ef authored by Taras's avatar Taras
Browse files

Add isVerifyStages for bsspeke

parent d9712560
No related branches found
No related tags found
No related merge requests found
...@@ -9,6 +9,7 @@ import org.futo.circles.auth.model.UIANavigationEvent ...@@ -9,6 +9,7 @@ import org.futo.circles.auth.model.UIANavigationEvent
import org.futo.circles.core.base.SingleEventLiveData import org.futo.circles.core.base.SingleEventLiveData
import org.futo.circles.core.extensions.Response import org.futo.circles.core.extensions.Response
import org.matrix.android.sdk.api.auth.UIABaseAuth 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.RegistrationFlowResponse
import org.matrix.android.sdk.api.auth.registration.RegistrationResult import org.matrix.android.sdk.api.auth.registration.RegistrationResult
import org.matrix.android.sdk.api.auth.registration.Stage import org.matrix.android.sdk.api.auth.registration.Stage
...@@ -89,6 +90,11 @@ abstract class UIADataSource { ...@@ -89,6 +90,11 @@ abstract class UIADataSource {
} ?: navigateToNextStage() } ?: navigateToNextStage()
} }
fun getCurrentStageKey() = when (currentStage) {
is Stage.Other -> (currentStage as Stage.Other).type
else -> LoginFlowTypes.TERMS
}
private fun isStageRetry(result: RegistrationResult?): Boolean { private fun isStageRetry(result: RegistrationResult?): Boolean {
val nextStageType = val nextStageType =
((result as? RegistrationResult.FlowResponse)?.flowResult?.missingStages?.firstOrNull() as? Stage.Other)?.type ((result as? RegistrationResult.FlowResponse)?.flowResult?.missingStages?.firstOrNull() as? Stage.Other)?.type
......
...@@ -6,13 +6,12 @@ import dagger.hilt.android.qualifiers.ApplicationContext ...@@ -6,13 +6,12 @@ import dagger.hilt.android.qualifiers.ApplicationContext
import org.futo.circles.auth.R import org.futo.circles.auth.R
import org.futo.circles.auth.bsspeke.BSSpekeClient import org.futo.circles.auth.bsspeke.BSSpekeClient
import org.futo.circles.auth.bsspeke.BSSpekeClientProvider 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_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_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.UIADataSource.Companion.TYPE_PARAM_KEY
import org.futo.circles.auth.feature.uia.UIADataSourceProvider import org.futo.circles.auth.feature.uia.UIADataSourceProvider
import org.futo.circles.auth.model.UIAFlowType
import org.futo.circles.core.extensions.Response import org.futo.circles.core.extensions.Response
import org.matrix.android.sdk.api.auth.registration.RegistrationResult import org.matrix.android.sdk.api.auth.registration.RegistrationResult
import org.matrix.android.sdk.api.auth.registration.Stage import org.matrix.android.sdk.api.auth.registration.Stage
...@@ -24,7 +23,11 @@ class BsSpekeStageDataSource @Inject constructor( ...@@ -24,7 +23,11 @@ class BsSpekeStageDataSource @Inject constructor(
private val uiaDataSource = UIADataSourceProvider.getDataSourceOrThrow() private val uiaDataSource = UIADataSourceProvider.getDataSourceOrThrow()
private var isVerifyStages = true
suspend fun processPasswordStage(password: String): Response<Unit> { 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) BSSpekeClientProvider.initClient(uiaDataSource.userName, uiaDataSource.domain, password)
val bsSpekeClient = BSSpekeClientProvider.getClientOrThrow() val bsSpekeClient = BSSpekeClientProvider.getClientOrThrow()
return when (val oprfResult = performOprfStage(bsSpekeClient)) { return when (val oprfResult = performOprfStage(bsSpekeClient)) {
...@@ -36,10 +39,8 @@ class BsSpekeStageDataSource @Inject constructor( ...@@ -36,10 +39,8 @@ class BsSpekeStageDataSource @Inject constructor(
} }
} }
private fun isLoginMode() = UIADataSourceProvider.activeFlowType == UIAFlowType.Login private fun getOprfTypeKey() = if (isVerifyStages) LOGIN_BSSPEKE_OPRF_TYPE
else ENROLL_BSSPEKE_OPRF_TYPE
private fun getOprfTypeKey() =
if (isLoginMode()) LOGIN_BSSPEKE_OPRF_TYPE else ENROLL_BSSPEKE_OPRF_TYPE
private suspend fun performOprfStage( private suspend fun performOprfStage(
bsSpekeClient: BSSpekeClient bsSpekeClient: BSSpekeClient
...@@ -66,7 +67,7 @@ class BsSpekeStageDataSource @Inject constructor( ...@@ -66,7 +67,7 @@ class BsSpekeStageDataSource @Inject constructor(
return Response.Error(e.message ?: "") return Response.Error(e.message ?: "")
} }
return when (val result = return when (val result =
if (isLoginMode()) performVerifyStage( if (isVerifyStages) performVerifyStage(
oprfResult, bsSpekeClient, password, blocks, iterations oprfResult, bsSpekeClient, password, blocks, iterations
) )
else performSaveStage( else performSaveStage(
......
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