mirror of
https://github.com/bitwarden/android.git
synced 2026-05-11 02:15:43 -05:00
[PM-6702] Remove captcha from StartRegistration
This commit is contained in:
@@ -9,7 +9,6 @@ import kotlinx.serialization.Serializable
|
||||
* @param email the email to be registered.
|
||||
* @param name the name to be registered.
|
||||
* @param receiveMarketingEmails the answer to receive marketing emails.
|
||||
* @param captchaResponse the captcha bypass token.
|
||||
*/
|
||||
@Serializable
|
||||
data class SendVerificationEmailRequestJson(
|
||||
@@ -21,8 +20,5 @@ data class SendVerificationEmailRequestJson(
|
||||
|
||||
@SerialName("receiveMarketingEmails")
|
||||
val receiveMarketingEmails: Boolean,
|
||||
|
||||
@SerialName("captchaResponse")
|
||||
val captchaResponse: String?,
|
||||
)
|
||||
|
||||
|
||||
@@ -356,7 +356,6 @@ interface AuthRepository : AuthenticatorProvider, AuthRequestManager {
|
||||
suspend fun sendVerificationEmail(
|
||||
email: String,
|
||||
name: String,
|
||||
receiveMarketingEmails: Boolean,
|
||||
captchaToken: String?
|
||||
receiveMarketingEmails: Boolean
|
||||
): SendVerificationEmailResult
|
||||
}
|
||||
|
||||
@@ -1133,18 +1133,14 @@ class AuthRepositoryImpl(
|
||||
email: String,
|
||||
name: String,
|
||||
receiveMarketingEmails: Boolean,
|
||||
captchaToken: String?,
|
||||
): SendVerificationEmailResult {
|
||||
return accountsService.sendVerificationEmail(
|
||||
val result = identityService.sendVerificationEmail(
|
||||
SendVerificationEmailRequestJson(
|
||||
email = email,
|
||||
name = name,
|
||||
receiveMarketingEmails = receiveMarketingEmails,
|
||||
captchaResponse = captchaToken,
|
||||
)).fold(
|
||||
onSuccess = { SendVerificationEmailResult.Success(it) },
|
||||
onFailure = { SendVerificationEmailResult.Error(null) },
|
||||
)
|
||||
)).getOrNull()
|
||||
return SendVerificationEmailResult.Success(result)
|
||||
}
|
||||
|
||||
@Suppress("CyclomaticComplexMethod")
|
||||
|
||||
@@ -10,16 +10,9 @@ sealed class SendVerificationEmailResult {
|
||||
* @param emailVerificationToken the token to verify the email.
|
||||
*/
|
||||
data class Success(
|
||||
val emailVerificationToken: String?
|
||||
val emailVerificationToken: String? = null
|
||||
) : SendVerificationEmailResult()
|
||||
|
||||
/**
|
||||
* Captcha verification is required.
|
||||
*
|
||||
* @param captchaId the captcha id for performing the captcha verification.
|
||||
*/
|
||||
data class CaptchaRequired(val captchaId: String) : SendVerificationEmailResult()
|
||||
|
||||
/**
|
||||
* There was an error sending the email.
|
||||
*
|
||||
|
||||
@@ -107,10 +107,6 @@ fun StartRegistrationScreen(
|
||||
Toast.makeText(context, event.text, Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
|
||||
is StartRegistrationEvent.NavigateToCaptcha -> {
|
||||
intentManager.startCustomTabsActivity(uri = event.uri)
|
||||
}
|
||||
|
||||
is StartRegistrationEvent.NavigateToCompleteRegistration -> {
|
||||
onNavigateToCompleteRegistration(
|
||||
event.email,
|
||||
|
||||
@@ -61,16 +61,6 @@ class StartRegistrationViewModel @Inject constructor(
|
||||
stateFlow
|
||||
.onEach { savedStateHandle[KEY_STATE] = it }
|
||||
.launchIn(viewModelScope)
|
||||
authRepository
|
||||
.captchaTokenResultFlow
|
||||
.onEach {
|
||||
sendAction(
|
||||
StartRegistrationAction.Internal.ReceiveCaptchaToken(
|
||||
tokenResult = it,
|
||||
),
|
||||
)
|
||||
}
|
||||
.launchIn(viewModelScope)
|
||||
|
||||
// Listen for changes in environment triggered both by this VM and externally.
|
||||
environmentRepository
|
||||
@@ -97,9 +87,6 @@ class StartRegistrationViewModel @Inject constructor(
|
||||
is StartRegistrationAction.Internal.ReceiveSendVerificationEmailResult -> {
|
||||
handleReceiveSendVerificationEmailResult(action)
|
||||
}
|
||||
is StartRegistrationAction.Internal.ReceiveCaptchaToken -> {
|
||||
handleReceiveCaptchaToken(action)
|
||||
}
|
||||
|
||||
is StartRegistrationAction.EnvironmentTypeSelect -> handleEnvironmentTypeSelect(action)
|
||||
is StartRegistrationAction.Internal.UpdatedEnvironmentReceive -> {
|
||||
@@ -108,31 +95,6 @@ class StartRegistrationViewModel @Inject constructor(
|
||||
}
|
||||
}
|
||||
|
||||
private fun handleReceiveCaptchaToken(
|
||||
action: StartRegistrationAction.Internal.ReceiveCaptchaToken,
|
||||
) {
|
||||
when (val result = action.tokenResult) {
|
||||
is CaptchaCallbackTokenResult.MissingToken -> {
|
||||
mutableStateFlow.update {
|
||||
it.copy(
|
||||
dialog = StartRegistrationDialog.Error(
|
||||
BasicDialogState.Shown(
|
||||
title = R.string.an_error_has_occurred.asText(),
|
||||
message = R.string.captcha_failed.asText(),
|
||||
),
|
||||
),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
is CaptchaCallbackTokenResult.Success -> {
|
||||
submitSendVerificationEmailRequest(
|
||||
captchaToken = result.token,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun handleEnvironmentTypeSelect(action: StartRegistrationAction.EnvironmentTypeSelect) {
|
||||
val environment = when (action.environmentType) {
|
||||
Environment.Type.US -> Environment.Us
|
||||
@@ -185,7 +147,7 @@ class StartRegistrationViewModel @Inject constructor(
|
||||
mutableStateFlow.update {
|
||||
it.copy(
|
||||
emailInput = action.input,
|
||||
isContinueButtonEnabled = action.input.isNotBlank() && state.nameInput.isNotBlank()
|
||||
isContinueButtonEnabled = action.input.isNotBlank()
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -194,7 +156,7 @@ class StartRegistrationViewModel @Inject constructor(
|
||||
mutableStateFlow.update {
|
||||
it.copy(
|
||||
nameInput = action.input,
|
||||
isContinueButtonEnabled = action.input.isNotBlank() && state.emailInput.isNotBlank()
|
||||
isContinueButtonEnabled = state.emailInput.isNotBlank()
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -218,15 +180,11 @@ class StartRegistrationViewModel @Inject constructor(
|
||||
}
|
||||
|
||||
else -> {
|
||||
submitSendVerificationEmailRequest(
|
||||
captchaToken = null,
|
||||
)
|
||||
submitSendVerificationEmailRequest()
|
||||
}
|
||||
}
|
||||
|
||||
private fun submitSendVerificationEmailRequest(
|
||||
captchaToken: String?,
|
||||
) {
|
||||
private fun submitSendVerificationEmailRequest() {
|
||||
mutableStateFlow.update {
|
||||
it.copy(dialog = StartRegistrationDialog.Loading)
|
||||
}
|
||||
@@ -235,7 +193,6 @@ class StartRegistrationViewModel @Inject constructor(
|
||||
email = state.emailInput,
|
||||
name = state.nameInput,
|
||||
receiveMarketingEmails = state.isReceiveMarketingEmailsToggled,
|
||||
captchaToken = captchaToken,
|
||||
)
|
||||
sendAction(
|
||||
StartRegistrationAction.Internal.ReceiveSendVerificationEmailResult(
|
||||
@@ -247,14 +204,6 @@ class StartRegistrationViewModel @Inject constructor(
|
||||
|
||||
private fun handleReceiveSendVerificationEmailResult(result: StartRegistrationAction.Internal.ReceiveSendVerificationEmailResult) {
|
||||
when (val sendVerificationEmailResult = result.sendVerificationEmailResult) {
|
||||
is SendVerificationEmailResult.CaptchaRequired -> {
|
||||
mutableStateFlow.update { it.copy(dialog = null) }
|
||||
sendEvent(
|
||||
StartRegistrationEvent.NavigateToCaptcha(
|
||||
uri = generateUriForCaptcha(captchaId = sendVerificationEmailResult.captchaId),
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
is SendVerificationEmailResult.Error -> {
|
||||
mutableStateFlow.update {
|
||||
@@ -272,21 +221,10 @@ class StartRegistrationViewModel @Inject constructor(
|
||||
|
||||
is SendVerificationEmailResult.Success -> {
|
||||
mutableStateFlow.update { it.copy(dialog = null) }
|
||||
if (environmentRepository.environment.type == Environment.Type.US || environmentRepository.environment.type == Environment.Type.EU)
|
||||
if (sendVerificationEmailResult.emailVerificationToken == null)
|
||||
sendEvent(StartRegistrationEvent.NavigateToCheckEmail(
|
||||
email = state.emailInput
|
||||
))
|
||||
else if (sendVerificationEmailResult.emailVerificationToken == null)
|
||||
mutableStateFlow.update {
|
||||
it.copy(
|
||||
dialog = StartRegistrationDialog.Error(
|
||||
BasicDialogState.Shown(
|
||||
title = R.string.an_error_has_occurred.asText(),
|
||||
message = R.string.generic_error_message.asText(),
|
||||
),
|
||||
),
|
||||
)
|
||||
}
|
||||
else
|
||||
sendEvent(StartRegistrationEvent.NavigateToCompleteRegistration(
|
||||
email = state.emailInput,
|
||||
@@ -345,11 +283,6 @@ sealed class StartRegistrationEvent {
|
||||
*/
|
||||
data class ShowToast(val text: String) : StartRegistrationEvent()
|
||||
|
||||
/**
|
||||
* Navigates to the captcha verification screen.
|
||||
*/
|
||||
data class NavigateToCaptcha(val uri: Uri) : StartRegistrationEvent()
|
||||
|
||||
/**
|
||||
* Navigates to the complete registration screen.
|
||||
*/
|
||||
@@ -446,13 +379,6 @@ sealed class StartRegistrationAction {
|
||||
* Models actions that the [StartRegistrationViewModel] itself might send.
|
||||
*/
|
||||
sealed class Internal : StartRegistrationAction() {
|
||||
/**
|
||||
* Indicates a captcha callback token has been received.
|
||||
*/
|
||||
data class ReceiveCaptchaToken(
|
||||
val tokenResult: CaptchaCallbackTokenResult,
|
||||
) : Internal()
|
||||
|
||||
/**
|
||||
* Indicates a [RegisterResult] has been received.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user