Skip to content

Commit

Permalink
Merge pull request #569 from jorgeblacio/recovery_code_email
Browse files Browse the repository at this point in the history
Now showing a hint for the recovery email.
  • Loading branch information
danieltigse authored Oct 28, 2019
2 parents 602ca40 + 57b20a0 commit 89ee03d
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 22 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ android {
defaultConfig {
minSdkVersion 21
targetSdkVersion 28
versionCode 95
versionName "0.21.18"
versionCode 96
versionName "0.21.19"
applicationId "com.criptext.mail"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
multiDexEnabled true
Expand Down
31 changes: 16 additions & 15 deletions src/main/kotlin/com/criptext/mail/scenes/signin/SignInScene.kt
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ interface SignInScene {
fun showDeviceCountRemaining(remaining: Int)
fun showDeviceRemovalError()
fun showToolbarCount(checked: Int)
fun showRecoveryCode()
fun showRecoveryCode(message: UIMessage)
fun showRecoveryDialogError(message: UIMessage?)
fun toggleLoadRecoveryCode(load: Boolean)
fun dismissRecoveryCodeDialog()
Expand Down Expand Up @@ -76,13 +76,7 @@ interface SignInScene {
)
)

private val recoveryCodeDialog = GeneralDialogWithInput(view.context,
DialogData.DialogDataForRecoveryCode(
title = UIMessage(R.string.recovery_code_dialog_title),
message = UIMessage(R.string.recovery_code_dialog_message),
type = DialogType.RecoveryCode()
)
)
private var recoveryCodeDialog: GeneralDialogWithInput? = null

override var signInUIObserver: SignInSceneController.SignInUIObserver? = null
set(value) {
Expand Down Expand Up @@ -267,22 +261,29 @@ interface SignInScene {
currentHolder.setToolbarCount(checked)
}

override fun showRecoveryCode() {
recoveryCodeDialog.showDialog(signInUIObserver)
recoveryCodeDialog.editTextEmail.setHint(R.string.recovery_code_dialog_hint)
recoveryCodeDialog.editTextEmailLayout.hint = view.context.getLocalizedUIMessage(UIMessage(R.string.recovery_code_dialog_hint))
override fun showRecoveryCode(message: UIMessage) {
recoveryCodeDialog = GeneralDialogWithInput(view.context,
DialogData.DialogDataForRecoveryCode(
title = UIMessage(R.string.recovery_code_dialog_title),
message = message,
type = DialogType.RecoveryCode()
)
)
recoveryCodeDialog?.showDialog(signInUIObserver)
recoveryCodeDialog?.editTextEmail?.setHint(R.string.recovery_code_dialog_hint)
recoveryCodeDialog?.editTextEmailLayout?.hint = view.context.getLocalizedUIMessage(UIMessage(R.string.recovery_code_dialog_hint))
}

override fun showRecoveryDialogError(message: UIMessage?) {
recoveryCodeDialog.setEmailError(message)
recoveryCodeDialog?.setEmailError(message)
}

override fun toggleLoadRecoveryCode(load: Boolean) {
recoveryCodeDialog.toggleLoad(load)
recoveryCodeDialog?.toggleLoad(load)
}

override fun dismissRecoveryCodeDialog() {
recoveryCodeDialog.dismiss()
recoveryCodeDialog?.dismiss()
}

override fun showKeyGenerationHolder() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,9 @@ class SignInSceneController(
scene.dismissRecoveryCodeDialog()
scene.showKeyGenerationHolder()
} else {
scene.showRecoveryCode()
val message = if(result.emailAddress == null) UIMessage(R.string.recovery_code_dialog_message)
else UIMessage(R.string.recovery_code_dialog_message_with_email, arrayOf(result.emailAddress))
scene.showRecoveryCode(message)
}
}
is SignInResult.RecoveryCode.Failure -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ sealed class SignInResult {
}

sealed class RecoveryCode: SignInResult() {
data class Success(val isValidate: Boolean): RecoveryCode()
data class Success(val isValidate: Boolean, val emailAddress: String?): RecoveryCode()
data class Failure(val isValidate: Boolean, val message: UIMessage,
val exception: Exception): RecoveryCode()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class RecoveryCodeWorker(val httpClient: HttpClient,
private val apiClient = SignUpAPIClient(httpClient)
private val isValidate = code != null
private val storeAccountTransaction = StoreAccountTransaction(signUpDao, keyValueStorage, accountDao)
private var emailAddress: String? = null

override val canBeParallelized = true

Expand All @@ -55,15 +56,15 @@ class RecoveryCodeWorker(val httpClient: HttpClient,
val message = createErrorMessage(ex)
if(!isValidate) {
if (ex is ServerErrorException && ex.errorCode == ServerCodes.BadRequest)
return SignInResult.RecoveryCode.Success(isValidate)
return SignInResult.RecoveryCode.Success(isValidate, emailAddress)
}
return SignInResult.RecoveryCode.Failure(isValidate, message, ex)
}

override fun work(reporter: ProgressReporter<SignInResult.RecoveryCode>): SignInResult.RecoveryCode? {
val result = Result.of {
if(!isValidate) {
apiClient.postTwoFAGenerateCode(recipientId, domain, jwt)
emailAddress = JSONObject(apiClient.postTwoFAGenerateCode(recipientId, domain, jwt).body).getString("address")
} else {
val json = JSONObject(apiClient.postValidateTwoFACode(recipientId, domain, jwt, code!!).body)
val deviceId = json.getInt("deviceId")
Expand All @@ -79,7 +80,7 @@ class RecoveryCodeWorker(val httpClient: HttpClient,

return when (result) {
is Result.Success ->{
SignInResult.RecoveryCode.Success(isValidate)
SignInResult.RecoveryCode.Success(isValidate, emailAddress)
}
is Result.Failure -> catchException(result.error)
}
Expand Down
1 change: 1 addition & 0 deletions src/main/res/values-es/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,7 @@
</string>
<string name="recovery_code_dialog_title">Código de Recuperación</string>
<string name="recovery_code_dialog_message">Por favor revisa tu correo de recuperación e introduce el código que te hemos enviado.</string>
<string name="recovery_code_dialog_message_with_email">Por favor revisa tu correo de recuperación, %1$s, e introduce el código que te hemos enviado.</string>
<string name="recovery_code_dialog_hint">Código</string>
<string name="recovery_code_dialog_error">Código de Recuperación Incorrecto</string>
<string name="recovery_code_validation_error">El código de recuperación no puede ser menor a 6 dígitos.</string>
Expand Down
1 change: 1 addition & 0 deletions src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,7 @@
</string>
<string name="recovery_code_dialog_title">Recovery Code</string>
<string name="recovery_code_dialog_message">Please check your recovery email and enter the code that was sent to you.</string>
<string name="recovery_code_dialog_message_with_email">Please check your recovery email, %1$s, and enter the code that was sent to you.</string>
<string name="recovery_code_dialog_hint">Code</string>
<string name="recovery_code_dialog_error">Incorrect Recovery Code</string>
<string name="recovery_code_validation_error">Recovery Code is at least 6 characters long.</string>
Expand Down

0 comments on commit 89ee03d

Please sign in to comment.