Skip to content

Commit 89ee03d

Browse files
authored
Merge pull request #569 from jorgeblacio/recovery_code_email
Now showing a hint for the recovery email.
2 parents 602ca40 + 57b20a0 commit 89ee03d

File tree

7 files changed

+28
-22
lines changed

7 files changed

+28
-22
lines changed

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ android {
4747
defaultConfig {
4848
minSdkVersion 21
4949
targetSdkVersion 28
50-
versionCode 95
51-
versionName "0.21.18"
50+
versionCode 96
51+
versionName "0.21.19"
5252
applicationId "com.criptext.mail"
5353
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
5454
multiDexEnabled true

src/main/kotlin/com/criptext/mail/scenes/signin/SignInScene.kt

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ interface SignInScene {
4646
fun showDeviceCountRemaining(remaining: Int)
4747
fun showDeviceRemovalError()
4848
fun showToolbarCount(checked: Int)
49-
fun showRecoveryCode()
49+
fun showRecoveryCode(message: UIMessage)
5050
fun showRecoveryDialogError(message: UIMessage?)
5151
fun toggleLoadRecoveryCode(load: Boolean)
5252
fun dismissRecoveryCodeDialog()
@@ -76,13 +76,7 @@ interface SignInScene {
7676
)
7777
)
7878

79-
private val recoveryCodeDialog = GeneralDialogWithInput(view.context,
80-
DialogData.DialogDataForRecoveryCode(
81-
title = UIMessage(R.string.recovery_code_dialog_title),
82-
message = UIMessage(R.string.recovery_code_dialog_message),
83-
type = DialogType.RecoveryCode()
84-
)
85-
)
79+
private var recoveryCodeDialog: GeneralDialogWithInput? = null
8680

8781
override var signInUIObserver: SignInSceneController.SignInUIObserver? = null
8882
set(value) {
@@ -267,22 +261,29 @@ interface SignInScene {
267261
currentHolder.setToolbarCount(checked)
268262
}
269263

270-
override fun showRecoveryCode() {
271-
recoveryCodeDialog.showDialog(signInUIObserver)
272-
recoveryCodeDialog.editTextEmail.setHint(R.string.recovery_code_dialog_hint)
273-
recoveryCodeDialog.editTextEmailLayout.hint = view.context.getLocalizedUIMessage(UIMessage(R.string.recovery_code_dialog_hint))
264+
override fun showRecoveryCode(message: UIMessage) {
265+
recoveryCodeDialog = GeneralDialogWithInput(view.context,
266+
DialogData.DialogDataForRecoveryCode(
267+
title = UIMessage(R.string.recovery_code_dialog_title),
268+
message = message,
269+
type = DialogType.RecoveryCode()
270+
)
271+
)
272+
recoveryCodeDialog?.showDialog(signInUIObserver)
273+
recoveryCodeDialog?.editTextEmail?.setHint(R.string.recovery_code_dialog_hint)
274+
recoveryCodeDialog?.editTextEmailLayout?.hint = view.context.getLocalizedUIMessage(UIMessage(R.string.recovery_code_dialog_hint))
274275
}
275276

276277
override fun showRecoveryDialogError(message: UIMessage?) {
277-
recoveryCodeDialog.setEmailError(message)
278+
recoveryCodeDialog?.setEmailError(message)
278279
}
279280

280281
override fun toggleLoadRecoveryCode(load: Boolean) {
281-
recoveryCodeDialog.toggleLoad(load)
282+
recoveryCodeDialog?.toggleLoad(load)
282283
}
283284

284285
override fun dismissRecoveryCodeDialog() {
285-
recoveryCodeDialog.dismiss()
286+
recoveryCodeDialog?.dismiss()
286287
}
287288

288289
override fun showKeyGenerationHolder() {

src/main/kotlin/com/criptext/mail/scenes/signin/SignInSceneController.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,9 @@ class SignInSceneController(
402402
scene.dismissRecoveryCodeDialog()
403403
scene.showKeyGenerationHolder()
404404
} else {
405-
scene.showRecoveryCode()
405+
val message = if(result.emailAddress == null) UIMessage(R.string.recovery_code_dialog_message)
406+
else UIMessage(R.string.recovery_code_dialog_message_with_email, arrayOf(result.emailAddress))
407+
scene.showRecoveryCode(message)
406408
}
407409
}
408410
is SignInResult.RecoveryCode.Failure -> {

src/main/kotlin/com/criptext/mail/scenes/signin/data/SignInResult.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ sealed class SignInResult {
2929
}
3030

3131
sealed class RecoveryCode: SignInResult() {
32-
data class Success(val isValidate: Boolean): RecoveryCode()
32+
data class Success(val isValidate: Boolean, val emailAddress: String?): RecoveryCode()
3333
data class Failure(val isValidate: Boolean, val message: UIMessage,
3434
val exception: Exception): RecoveryCode()
3535
}

src/main/kotlin/com/criptext/mail/scenes/signin/workers/RecoveryCodeWorker.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ class RecoveryCodeWorker(val httpClient: HttpClient,
4343
private val apiClient = SignUpAPIClient(httpClient)
4444
private val isValidate = code != null
4545
private val storeAccountTransaction = StoreAccountTransaction(signUpDao, keyValueStorage, accountDao)
46+
private var emailAddress: String? = null
4647

4748
override val canBeParallelized = true
4849

@@ -55,15 +56,15 @@ class RecoveryCodeWorker(val httpClient: HttpClient,
5556
val message = createErrorMessage(ex)
5657
if(!isValidate) {
5758
if (ex is ServerErrorException && ex.errorCode == ServerCodes.BadRequest)
58-
return SignInResult.RecoveryCode.Success(isValidate)
59+
return SignInResult.RecoveryCode.Success(isValidate, emailAddress)
5960
}
6061
return SignInResult.RecoveryCode.Failure(isValidate, message, ex)
6162
}
6263

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

8081
return when (result) {
8182
is Result.Success ->{
82-
SignInResult.RecoveryCode.Success(isValidate)
83+
SignInResult.RecoveryCode.Success(isValidate, emailAddress)
8384
}
8485
is Result.Failure -> catchException(result.error)
8586
}

src/main/res/values-es/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -603,6 +603,7 @@
603603
</string>
604604
<string name="recovery_code_dialog_title">Código de Recuperación</string>
605605
<string name="recovery_code_dialog_message">Por favor revisa tu correo de recuperación e introduce el código que te hemos enviado.</string>
606+
<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>
606607
<string name="recovery_code_dialog_hint">Código</string>
607608
<string name="recovery_code_dialog_error">Código de Recuperación Incorrecto</string>
608609
<string name="recovery_code_validation_error">El código de recuperación no puede ser menor a 6 dígitos.</string>

src/main/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -605,6 +605,7 @@
605605
</string>
606606
<string name="recovery_code_dialog_title">Recovery Code</string>
607607
<string name="recovery_code_dialog_message">Please check your recovery email and enter the code that was sent to you.</string>
608+
<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>
608609
<string name="recovery_code_dialog_hint">Code</string>
609610
<string name="recovery_code_dialog_error">Incorrect Recovery Code</string>
610611
<string name="recovery_code_validation_error">Recovery Code is at least 6 characters long.</string>

0 commit comments

Comments
 (0)