mirror of
https://github.com/bitwarden/android.git
synced 2026-05-11 02:15:43 -05:00
[PM-6702] Change send verification email response.
This commit is contained in:
@@ -24,5 +24,5 @@ interface AccountsApi {
|
||||
@POST("/accounts/register/send-verification-email")
|
||||
suspend fun sendVerificationEmail(
|
||||
@Body body: SendVerificationEmailRequestJson,
|
||||
): Result<SendVerificationEmailResponseJson>
|
||||
): Result<String?>
|
||||
}
|
||||
|
||||
@@ -9,40 +9,13 @@ sealed class SendVerificationEmailResponseJson {
|
||||
/**
|
||||
* Models a successful json response.
|
||||
*
|
||||
* @param captchaBypassToken the bypass token.
|
||||
* @param emailVerificationToken the token to verify the email.
|
||||
*/
|
||||
@Serializable
|
||||
data class Success(
|
||||
@SerialName("emailVerificationToken")
|
||||
val emailVerificationToken: String?,
|
||||
|
||||
@SerialName("captchaBypassToken")
|
||||
val captchaBypassToken: String,
|
||||
) : SendVerificationEmailResponseJson()
|
||||
|
||||
/**
|
||||
* Models a json body of a captcha error.
|
||||
*
|
||||
* @param validationErrors object containing error validations of the response.
|
||||
*/
|
||||
@Serializable
|
||||
data class CaptchaRequired(
|
||||
@SerialName("validationErrors")
|
||||
val validationErrors: ValidationErrors,
|
||||
) : SendVerificationEmailResponseJson() {
|
||||
|
||||
/**
|
||||
* Error validations containing a HCaptcha Site Key.
|
||||
*
|
||||
* @param captchaKeys keys for attempting captcha verification.
|
||||
*/
|
||||
@Serializable
|
||||
data class ValidationErrors(
|
||||
@SerialName("HCaptcha_SiteKey")
|
||||
val captchaKeys: List<String>,
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents the json body of an invalid request.
|
||||
*
|
||||
|
||||
@@ -54,7 +54,7 @@ interface AccountsService {
|
||||
/**
|
||||
* Send a verification email.
|
||||
*/
|
||||
suspend fun sendVerificationEmail(body: SendVerificationEmailRequestJson): Result<SendVerificationEmailResponseJson>
|
||||
suspend fun sendVerificationEmail(body: SendVerificationEmailRequestJson): Result<String?>
|
||||
|
||||
/**
|
||||
* Set the password.
|
||||
|
||||
@@ -97,8 +97,9 @@ class AccountsServiceImpl(
|
||||
|
||||
override suspend fun sendVerificationEmail(
|
||||
body: SendVerificationEmailRequestJson
|
||||
): Result<SendVerificationEmailResponseJson> =
|
||||
accountsApi.sendVerificationEmail(body = body)
|
||||
): Result<String?> {
|
||||
return accountsApi.sendVerificationEmail(body = body)
|
||||
}
|
||||
|
||||
|
||||
override suspend fun setPassword(
|
||||
|
||||
@@ -770,8 +770,8 @@ class AuthRepositoryImpl(
|
||||
masterPasswordHint = masterPasswordHint,
|
||||
emailVerificationToken = emailVerificationToken,
|
||||
captchaResponse = captchaToken,
|
||||
key = registerKeyResponse.encryptedUserKey,
|
||||
keys = RegisterFinishRequestJson.Keys(
|
||||
userSymmetricKey = registerKeyResponse.encryptedUserKey,
|
||||
userAsymmetricKeys = RegisterFinishRequestJson.Keys(
|
||||
publicKey = registerKeyResponse.keys.public,
|
||||
encryptedPrivateKey = registerKeyResponse.keys.private,
|
||||
),
|
||||
@@ -1142,22 +1142,7 @@ class AuthRepositoryImpl(
|
||||
receiveMarketingEmails = receiveMarketingEmails,
|
||||
captchaResponse = captchaToken,
|
||||
)).fold(
|
||||
onSuccess = {
|
||||
when (it) {
|
||||
is SendVerificationEmailResponseJson.Error -> SendVerificationEmailResult.Error(it.message)
|
||||
is SendVerificationEmailResponseJson.Success -> SendVerificationEmailResult.Success(
|
||||
emailVerificationToken = it.emailVerificationToken,
|
||||
captchaToken = it.captchaBypassToken
|
||||
)
|
||||
|
||||
is SendVerificationEmailResponseJson.CaptchaRequired ->
|
||||
it.validationErrors.captchaKeys.firstOrNull()
|
||||
?.let { key -> SendVerificationEmailResult.CaptchaRequired(captchaId = key) }
|
||||
?: SendVerificationEmailResult.Error(errorMessage = null)
|
||||
|
||||
is SendVerificationEmailResponseJson.Invalid -> TODO()
|
||||
}
|
||||
},
|
||||
onSuccess = { SendVerificationEmailResult.Success(it) },
|
||||
onFailure = { SendVerificationEmailResult.Error(null) },
|
||||
)
|
||||
}
|
||||
|
||||
@@ -8,11 +8,9 @@ sealed class SendVerificationEmailResult {
|
||||
* Email sent succeeded.
|
||||
*
|
||||
* @param emailVerificationToken the token to verify the email.
|
||||
* @param captchaToken the captcha bypass token to bypass future captcha verifications.
|
||||
*/
|
||||
data class Success(
|
||||
val emailVerificationToken: String?,
|
||||
val captchaToken: String
|
||||
val emailVerificationToken: String?
|
||||
) : SendVerificationEmailResult()
|
||||
|
||||
/**
|
||||
|
||||
@@ -142,8 +142,7 @@ class StartRegistrationViewModelTest : BaseViewModelTest() {
|
||||
captchaToken = null,
|
||||
)
|
||||
} returns SendVerificationEmailResult.Success(
|
||||
emailVerificationToken = "verification_token",
|
||||
captchaToken = "mock_token"
|
||||
emailVerificationToken = "verification_token"
|
||||
)
|
||||
}
|
||||
val viewModel = StartRegistrationViewModel(
|
||||
@@ -254,9 +253,7 @@ class StartRegistrationViewModelTest : BaseViewModelTest() {
|
||||
receiveMarketingEmails = true,
|
||||
captchaToken = null,
|
||||
)
|
||||
} returns SendVerificationEmailResult.Success(
|
||||
emailVerificationToken = "verification_token",
|
||||
captchaToken = "mock_captcha_token")
|
||||
} returns SendVerificationEmailResult.Success(emailVerificationToken = "verification_token",)
|
||||
}
|
||||
val viewModel = StartRegistrationViewModel(
|
||||
savedStateHandle = validInputHandle,
|
||||
|
||||
Reference in New Issue
Block a user