Search in sources :

Example 1 with LinkExpirationFormatterMethod

use of org.keycloak.theme.beans.LinkExpirationFormatterMethod in project keycloak by keycloak.

the class FreeMarkerEmailTemplateProvider method addLinkInfoIntoAttributes.

/**
 * Add link info into template attributes.
 *
 * @param link to add
 * @param expirationInMinutes to add
 * @param attributes to add link info into
 */
protected void addLinkInfoIntoAttributes(String link, long expirationInMinutes, Map<String, Object> attributes) throws EmailException {
    attributes.put("link", link);
    attributes.put("linkExpiration", expirationInMinutes);
    KeycloakUriInfo uriInfo = session.getContext().getUri();
    URI baseUri = uriInfo.getBaseUri();
    try {
        Locale locale = session.getContext().resolveLocale(user);
        attributes.put("linkExpirationFormatter", new LinkExpirationFormatterMethod(getTheme().getMessages(locale), locale));
        attributes.put("url", new UrlBean(realm, getTheme(), baseUri, null));
    } catch (IOException e) {
        throw new EmailException("Failed to template email", e);
    }
}
Also used : Locale(java.util.Locale) KeycloakUriInfo(org.keycloak.models.KeycloakUriInfo) UrlBean(org.keycloak.forms.login.freemarker.model.UrlBean) EmailException(org.keycloak.email.EmailException) LinkExpirationFormatterMethod(org.keycloak.theme.beans.LinkExpirationFormatterMethod) IOException(java.io.IOException) URI(java.net.URI)

Aggregations

IOException (java.io.IOException)1 URI (java.net.URI)1 Locale (java.util.Locale)1 EmailException (org.keycloak.email.EmailException)1 UrlBean (org.keycloak.forms.login.freemarker.model.UrlBean)1 KeycloakUriInfo (org.keycloak.models.KeycloakUriInfo)1 LinkExpirationFormatterMethod (org.keycloak.theme.beans.LinkExpirationFormatterMethod)1