diff --git a/services/src/main/java/org/keycloak/forms/login/freemarker/model/RealmBean.java b/services/src/main/java/org/keycloak/forms/login/freemarker/model/RealmBean.java index 325cbc94a8..57832fbf8f 100755 --- a/services/src/main/java/org/keycloak/forms/login/freemarker/model/RealmBean.java +++ b/services/src/main/java/org/keycloak/forms/login/freemarker/model/RealmBean.java @@ -74,6 +74,10 @@ public class RealmBean { return realm.isLoginWithEmailAllowed(); } + public boolean isDuplicateEmailsAllowed() { + return realm.isDuplicateEmailsAllowed(); + } + public boolean isResetPasswordAllowed() { return realm.isResetPasswordAllowed(); } diff --git a/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/pages/LoginPasswordResetPage.java b/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/pages/LoginPasswordResetPage.java index ba02a7cf32..7919545e9e 100644 --- a/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/pages/LoginPasswordResetPage.java +++ b/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/pages/LoginPasswordResetPage.java @@ -44,6 +44,9 @@ public class LoginPasswordResetPage extends LanguageComboboxAwarePage { @FindBy(partialLinkText = "Back to Login") private WebElement backToLogin; + @FindBy(id = "kc-info-wrapper") + private WebElement infoWrapper; + public void changePassword() { submitButton.click(); } @@ -91,4 +94,11 @@ public class LoginPasswordResetPage extends LanguageComboboxAwarePage { backToLogin.click(); } + public String getInfoMessage() { + try { + return UIUtils.getTextFromElement(infoWrapper); + } catch (NoSuchElementException e) { + return null; + } + } } diff --git a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/forms/ResetPasswordTest.java b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/forms/ResetPasswordTest.java index 5a42dc0567..8515459d2a 100644 --- a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/forms/ResetPasswordTest.java +++ b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/forms/ResetPasswordTest.java @@ -1157,6 +1157,38 @@ public class ResetPasswordTest extends AbstractTestRealmKeycloakTest { } } + @Test + public void resetPasswordInfoMessageWithDuplicateEmailsAllowed() throws IOException { + RealmRepresentation realmRep = testRealm().toRepresentation(); + Boolean originalLoginWithEmailAllowed = realmRep.isLoginWithEmailAllowed(); + Boolean originalDuplicateEmailsAllowed = realmRep.isDuplicateEmailsAllowed(); + + try { + loginPage.open(); + loginPage.resetPassword(); + + resetPasswordPage.assertCurrent(); + + assertEquals("Enter your username or email address and we will send you instructions on how to create a new password.", resetPasswordPage.getInfoMessage()); + + realmRep.setLoginWithEmailAllowed(false); + realmRep.setDuplicateEmailsAllowed(true); + testRealm().update(realmRep); + + loginPage.open(); + loginPage.resetPassword(); + + resetPasswordPage.assertCurrent(); + + assertEquals("Enter your username and we will send you instructions on how to create a new password.", resetPasswordPage.getInfoMessage()); + } finally { + realmRep.setLoginWithEmailAllowed(originalLoginWithEmailAllowed); + realmRep.setDuplicateEmailsAllowed(originalDuplicateEmailsAllowed); + testRealm().update(realmRep); + } + + } + // KEYCLOAK-15170 @Test public void changeEmailAddressAfterSendingEmail() throws IOException { diff --git a/themes/src/main/resources/theme/base/login/login-reset-password.ftl b/themes/src/main/resources/theme/base/login/login-reset-password.ftl index efb1351230..800faea1f0 100755 --- a/themes/src/main/resources/theme/base/login/login-reset-password.ftl +++ b/themes/src/main/resources/theme/base/login/login-reset-password.ftl @@ -30,6 +30,10 @@ <#elseif section = "info" > - ${msg("emailInstruction")} + <#if realm.duplicateEmailsAllowed> + ${msg("emailInstructionUsername")} + <#else> + ${msg("emailInstruction")} + diff --git a/themes/src/main/resources/theme/base/login/messages/messages_en.properties b/themes/src/main/resources/theme/base/login/messages/messages_en.properties index 0bae12406e..99067632b3 100755 --- a/themes/src/main/resources/theme/base/login/messages/messages_en.properties +++ b/themes/src/main/resources/theme/base/login/messages/messages_en.properties @@ -149,6 +149,7 @@ emailLinkIdp5=to continue. backToLogin=« Back to Login emailInstruction=Enter your username or email address and we will send you instructions on how to create a new password. +emailInstructionUsername=Enter your username and we will send you instructions on how to create a new password. copyCodeInstruction=Please copy this code and paste it into your application: