diff --git a/forms/common-freemarker/src/main/java/org/keycloak/freemarker/LocaleHelper.java b/forms/common-freemarker/src/main/java/org/keycloak/freemarker/LocaleHelper.java index 1c4265663c6..a114de32701 100644 --- a/forms/common-freemarker/src/main/java/org/keycloak/freemarker/LocaleHelper.java +++ b/forms/common-freemarker/src/main/java/org/keycloak/freemarker/LocaleHelper.java @@ -19,6 +19,10 @@ public class LocaleHelper { private final static Logger LOGGER = Logger.getLogger(LocaleHelper.class); + public static Locale getLocale(RealmModel realm, UserModel user) { + return getLocale(realm, user, null, null); + } + public static Locale getLocale(RealmModel realm, UserModel user, UriInfo uriInfo, HttpHeaders httpHeaders) { if(!realm.isInternationalizationEnabled()){ return null; diff --git a/forms/common-themes/src/main/resources/theme/email/keycloak/email-verification_de.ftl b/forms/common-themes/src/main/resources/theme/email/keycloak/email-verification_de.ftl new file mode 100644 index 00000000000..38d150fd5d5 --- /dev/null +++ b/forms/common-themes/src/main/resources/theme/email/keycloak/email-verification_de.ftl @@ -0,0 +1,5 @@ +Someone has created a Keycloak account with this email address. If this was you, click the link below to verify your email address: +${link} +This link will expire within ${linkExpiration} minutes. + +If you didn't create this account, just ignore this message. \ No newline at end of file diff --git a/forms/common-themes/src/main/resources/theme/email/keycloak/email-verification_en.ftl b/forms/common-themes/src/main/resources/theme/email/keycloak/email-verification_en.ftl new file mode 100644 index 00000000000..38d150fd5d5 --- /dev/null +++ b/forms/common-themes/src/main/resources/theme/email/keycloak/email-verification_en.ftl @@ -0,0 +1,5 @@ +Someone has created a Keycloak account with this email address. If this was you, click the link below to verify your email address: +${link} +This link will expire within ${linkExpiration} minutes. + +If you didn't create this account, just ignore this message. \ No newline at end of file diff --git a/forms/common-themes/src/main/resources/theme/email/keycloak/event-login_error_de.ftl b/forms/common-themes/src/main/resources/theme/email/keycloak/event-login_error_de.ftl new file mode 100644 index 00000000000..c1227aa8827 --- /dev/null +++ b/forms/common-themes/src/main/resources/theme/email/keycloak/event-login_error_de.ftl @@ -0,0 +1 @@ +A failed login attempt was dettected to your account on ${event.date?datetime} from ${event.ipAddress}. If this was not you, please contact an admin. \ No newline at end of file diff --git a/forms/common-themes/src/main/resources/theme/email/keycloak/event-login_error_en.ftl b/forms/common-themes/src/main/resources/theme/email/keycloak/event-login_error_en.ftl new file mode 100644 index 00000000000..c1227aa8827 --- /dev/null +++ b/forms/common-themes/src/main/resources/theme/email/keycloak/event-login_error_en.ftl @@ -0,0 +1 @@ +A failed login attempt was dettected to your account on ${event.date?datetime} from ${event.ipAddress}. If this was not you, please contact an admin. \ No newline at end of file diff --git a/forms/common-themes/src/main/resources/theme/email/keycloak/event-remove_totp_de.ftl b/forms/common-themes/src/main/resources/theme/email/keycloak/event-remove_totp_de.ftl new file mode 100644 index 00000000000..c62e1740539 --- /dev/null +++ b/forms/common-themes/src/main/resources/theme/email/keycloak/event-remove_totp_de.ftl @@ -0,0 +1 @@ +TOTP was removed from your account on ${event.date?datetime} from ${event.ipAddress}. If this was not you, please contact an admin. \ No newline at end of file diff --git a/forms/common-themes/src/main/resources/theme/email/keycloak/event-remove_totp_en.ftl b/forms/common-themes/src/main/resources/theme/email/keycloak/event-remove_totp_en.ftl new file mode 100644 index 00000000000..c62e1740539 --- /dev/null +++ b/forms/common-themes/src/main/resources/theme/email/keycloak/event-remove_totp_en.ftl @@ -0,0 +1 @@ +TOTP was removed from your account on ${event.date?datetime} from ${event.ipAddress}. If this was not you, please contact an admin. \ No newline at end of file diff --git a/forms/common-themes/src/main/resources/theme/email/keycloak/event-update_password_de.ftl b/forms/common-themes/src/main/resources/theme/email/keycloak/event-update_password_de.ftl new file mode 100644 index 00000000000..696a6e61816 --- /dev/null +++ b/forms/common-themes/src/main/resources/theme/email/keycloak/event-update_password_de.ftl @@ -0,0 +1 @@ +Your password was changed on ${event.date?datetime} from ${event.ipAddress}. If this was not you, please contact an admin. \ No newline at end of file diff --git a/forms/common-themes/src/main/resources/theme/email/keycloak/event-update_password_en.ftl b/forms/common-themes/src/main/resources/theme/email/keycloak/event-update_password_en.ftl new file mode 100644 index 00000000000..696a6e61816 --- /dev/null +++ b/forms/common-themes/src/main/resources/theme/email/keycloak/event-update_password_en.ftl @@ -0,0 +1 @@ +Your password was changed on ${event.date?datetime} from ${event.ipAddress}. If this was not you, please contact an admin. \ No newline at end of file diff --git a/forms/common-themes/src/main/resources/theme/email/keycloak/event-update_totp_de.ftl b/forms/common-themes/src/main/resources/theme/email/keycloak/event-update_totp_de.ftl new file mode 100644 index 00000000000..531ae662be7 --- /dev/null +++ b/forms/common-themes/src/main/resources/theme/email/keycloak/event-update_totp_de.ftl @@ -0,0 +1 @@ +TOTP was updated for your account on ${event.date?datetime} from ${event.ipAddress}. If this was not you, please contact an admin. \ No newline at end of file diff --git a/forms/common-themes/src/main/resources/theme/email/keycloak/event-update_totp_en.ftl b/forms/common-themes/src/main/resources/theme/email/keycloak/event-update_totp_en.ftl new file mode 100644 index 00000000000..531ae662be7 --- /dev/null +++ b/forms/common-themes/src/main/resources/theme/email/keycloak/event-update_totp_en.ftl @@ -0,0 +1 @@ +TOTP was updated for your account on ${event.date?datetime} from ${event.ipAddress}. If this was not you, please contact an admin. \ No newline at end of file diff --git a/forms/common-themes/src/main/resources/theme/email/keycloak/messages/messages_de.properties b/forms/common-themes/src/main/resources/theme/email/keycloak/messages/messages_de.properties new file mode 100755 index 00000000000..c78934202c6 --- /dev/null +++ b/forms/common-themes/src/main/resources/theme/email/keycloak/messages/messages_de.properties @@ -0,0 +1,2 @@ +emailVerificationSubject=Verify email +passwordResetSubject=Passwort zurücksetzen \ No newline at end of file diff --git a/forms/common-themes/src/main/resources/theme/email/keycloak/messages/messages_en.properties b/forms/common-themes/src/main/resources/theme/email/keycloak/messages/messages_en.properties new file mode 100755 index 00000000000..3139aca3402 --- /dev/null +++ b/forms/common-themes/src/main/resources/theme/email/keycloak/messages/messages_en.properties @@ -0,0 +1,2 @@ +emailVerificationSubject=Verify email +passwordResetSubject=Reset password \ No newline at end of file diff --git a/forms/common-themes/src/main/resources/theme/email/keycloak/password-reset_de.ftl b/forms/common-themes/src/main/resources/theme/email/keycloak/password-reset_de.ftl new file mode 100644 index 00000000000..e1bc30d2424 --- /dev/null +++ b/forms/common-themes/src/main/resources/theme/email/keycloak/password-reset_de.ftl @@ -0,0 +1,5 @@ +Jemand hat angeforder ihr Passwort zurück zu setzen: +${link} +This link will expire within ${linkExpiration} minutes. + +If you don't want to reset your password, just ignore this message and nothing will be changed. \ No newline at end of file diff --git a/forms/common-themes/src/main/resources/theme/email/keycloak/password-reset_en.ftl b/forms/common-themes/src/main/resources/theme/email/keycloak/password-reset_en.ftl new file mode 100644 index 00000000000..5d277e5e2bc --- /dev/null +++ b/forms/common-themes/src/main/resources/theme/email/keycloak/password-reset_en.ftl @@ -0,0 +1,5 @@ +Someone just requested to change your Keycloak account's password. If this was you, click on the link below to set a new password: +${link} +This link will expire within ${linkExpiration} minutes. + +If you don't want to reset your password, just ignore this message and nothing will be changed. \ No newline at end of file diff --git a/forms/email-freemarker/src/main/java/org/keycloak/email/freemarker/FreeMarkerEmailProvider.java b/forms/email-freemarker/src/main/java/org/keycloak/email/freemarker/FreeMarkerEmailProvider.java index 2526adbd9a2..2078e95b765 100755 --- a/forms/email-freemarker/src/main/java/org/keycloak/email/freemarker/FreeMarkerEmailProvider.java +++ b/forms/email-freemarker/src/main/java/org/keycloak/email/freemarker/FreeMarkerEmailProvider.java @@ -6,6 +6,7 @@ import org.keycloak.email.EmailProvider; import org.keycloak.email.freemarker.beans.EventBean; import org.keycloak.events.Event; import org.keycloak.freemarker.FreeMarkerUtil; +import org.keycloak.freemarker.LocaleHelper; import org.keycloak.freemarker.Theme; import org.keycloak.freemarker.ThemeProvider; import org.keycloak.models.KeycloakSession; @@ -53,7 +54,7 @@ public class FreeMarkerEmailProvider implements EmailProvider { Map attributes = new HashMap(); attributes.put("event", new EventBean(event)); - send("passwordResetSubject", "event-" + event.getType().toString().toLowerCase() + ".ftl", attributes); + send("passwordResetSubject", getTemplate("event-" + event.getType().toString().toLowerCase()), attributes); } @Override @@ -62,7 +63,7 @@ public class FreeMarkerEmailProvider implements EmailProvider { attributes.put("link", link); attributes.put("linkExpiration", expirationInMinutes); - send("passwordResetSubject", "password-reset.ftl", attributes); + send("passwordResetSubject", getTemplate("password-reset"), attributes); } @Override @@ -71,7 +72,7 @@ public class FreeMarkerEmailProvider implements EmailProvider { attributes.put("link", link); attributes.put("linkExpiration", expirationInMinutes); - send("emailVerificationSubject", "email-verification.ftl", attributes); + send("emailVerificationSubject", getTemplate("email-verification"), attributes); } private void send(String subjectKey, String template, Map attributes) throws EmailException { @@ -79,7 +80,7 @@ public class FreeMarkerEmailProvider implements EmailProvider { ThemeProvider themeProvider = session.getProvider(ThemeProvider.class, "extending"); Theme theme = themeProvider.getTheme(realm.getEmailTheme(), Theme.Type.EMAIL); - String subject = theme.getMessages(Locale.GERMAN).getProperty(subjectKey); + String subject = theme.getMessages(LocaleHelper.getLocale(realm,user)).getProperty(subjectKey); String body = freeMarker.processTemplate(attributes, template, theme); send(subject, body); @@ -147,4 +148,14 @@ public class FreeMarkerEmailProvider implements EmailProvider { public void close() { } + private String getTemplate(String name){ + StringBuilder sb = new StringBuilder(name); + Locale locale = LocaleHelper.getLocale(realm, user); + if(locale!=null){ + sb.append("_").append(locale.toString()); + } + sb.append(".ftl"); + + return sb.toString(); + } }