diff --git a/pom.xml b/pom.xml index f2b2c8f..358df73 100644 --- a/pom.xml +++ b/pom.xml @@ -15,7 +15,7 @@ ${java.version} 22.0.5 3.2.4 - 2.0.0 + 2.1.0 diff --git a/src/main/java/com/weare5stones/keycloak/authenticators/emailotp/EmailOTPAuthenticator.java b/src/main/java/com/weare5stones/keycloak/authenticators/emailotp/EmailOTPAuthenticator.java index e528bfd..51da926 100644 --- a/src/main/java/com/weare5stones/keycloak/authenticators/emailotp/EmailOTPAuthenticator.java +++ b/src/main/java/com/weare5stones/keycloak/authenticators/emailotp/EmailOTPAuthenticator.java @@ -115,23 +115,18 @@ public void action(AuthenticationFlowContext context) { context.success(); } } else { - // invalid - AuthenticationExecutionModel execution = context.getExecution(); - if (execution.isRequired()) { - context.failureChallenge(AuthenticationFlowError.INVALID_CREDENTIALS, - context.form().setAttribute("realm", context.getRealm()) - .setError("emailTOTPCodeInvalid").createForm(TOTP_FORM)); - } else if (execution.isConditional() || execution.isAlternative()) { - if (remainingAttempts > 0) { - // decrement the remaining attempts - authSession.setAuthNote(AUTH_NOTE_REMAINING_RETRIES, Integer.toString(remainingAttempts - 1)); - // display the error message + // Code is invalid + remainingAttempts--; + authSession.setAuthNote(AUTH_NOTE_REMAINING_RETRIES, Integer.toString(remainingAttempts)); + + if (remainingAttempts > 0) { + // Inform user of the remaining attempts context.failureChallenge(AuthenticationFlowError.INVALID_CREDENTIALS, - context.form().setAttribute("realm", context.getRealm()) - .setError("emailTOTPCodeInvalid", remainingAttemptsStr).createForm(TOTP_FORM)); - } else { - context.attempted(); - } + context.form().setAttribute("realm", context.getRealm()) + .setError("emailTOTPCodeInvalid", Integer.toString(remainingAttempts)).createForm(TOTP_FORM)); + } else { + // Reset login + context.resetFlow(); } } } diff --git a/src/main/resources/theme-resources/messages/messages_de.properties b/src/main/resources/theme-resources/messages/messages_de.properties index b133e82..13b83f7 100644 --- a/src/main/resources/theme-resources/messages/messages_de.properties +++ b/src/main/resources/theme-resources/messages/messages_de.properties @@ -3,6 +3,7 @@ emailTOTPBodyHtml=Ihr Email Code lautet:

{1}


Sie ist emailTOTPFormTitle=Email Code emailTOTPFormLabel=Code +resendEmail=E-Mail zur\u00Fcksenden emailTOTPFormInstruction=Geben Sie den Code ein, den wir an Ihr Ger\u00E4t gesendet haben. emailTOTPCodeExpired=Die G\u00FCltigkeit des Codes ist abgelaufen. diff --git a/src/main/resources/theme-resources/messages/messages_en.properties b/src/main/resources/theme-resources/messages/messages_en.properties index 64bb229..fdba00f 100644 --- a/src/main/resources/theme-resources/messages/messages_en.properties +++ b/src/main/resources/theme-resources/messages/messages_en.properties @@ -3,6 +3,7 @@ emailTOTPBodyHtml=Your temporary login code is:

{1}


T emailTOTPFormTitle=Temporary Login Code emailTOTPFormLabel=Code +resendEmail=Resend email emailTOTPFormInstruction=Enter the code we sent to your email address. emailTOTPCodeExpired=The code has expired. diff --git a/src/main/resources/theme-resources/templates/totp-form.ftl b/src/main/resources/theme-resources/templates/totp-form.ftl index 23cc5c2..072d807 100644 --- a/src/main/resources/theme-resources/templates/totp-form.ftl +++ b/src/main/resources/theme-resources/templates/totp-form.ftl @@ -13,15 +13,15 @@
+
+ +
+ - -
- -
<#elseif section = "info" >