[PM-6702] Change send verification email response.

This commit is contained in:
André Bispo
2024-07-11 17:06:40 +01:00
parent fbbb3379ca
commit 6c78ecf297
7 changed files with 12 additions and 58 deletions

View File

@@ -24,5 +24,5 @@ interface AccountsApi {
@POST("/accounts/register/send-verification-email")
suspend fun sendVerificationEmail(
@Body body: SendVerificationEmailRequestJson,
): Result<SendVerificationEmailResponseJson>
): Result<String?>
}

View File

@@ -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.
*

View File

@@ -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.

View File

@@ -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(

View File

@@ -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) },
)
}

View File

@@ -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()
/**

View File

@@ -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,