Password Reset Email Template

Does anyone know how to modify or override the default template that is used when you reset a password through the user interface?

I can’t find any documentation on it.

Cheers!

Hello,
The password for your CUBA Application account has been reset by administrator.
Please login with the following temporary password:
wkQr3A1k
and immediately create a new one for the further work.
Thank you,
CUBA Team

Hi,

By default we use the following template files in the classpath of the core module:

  • /com/haulmont/cuba/security/app/email/reset-password-subject.gsp
  • /com/haulmont/cuba/security/app/email/reset-password-body.gsp

You can set your custom template location using application properties (use app.properties file of the core module):

  • cuba.security.resetPasswordTemplateSubject
  • cuba.security.resetPasswordTemplateBody

These email templates are based on Groovy SimpleTemplateEngine syntax, thus you can use Groovy blocks inside of the template content. For instance:

Hello, ${user.name}.

The password for your CUBA Application account has been reset by administrator.

Please login with the following temporary password:
${password}
and immediately create a new one for the further work.

Thank you,
CUBA Team 

Data binding for these templates contains the following variables: user, password, persistence. In fact, you can use any Spring beans of the middleware if you import AppBeans class and get them using AppBeans.get() method.

See also: SimpleTemplateEngine (Groovy 2.4.6)

Awesome! Thanks Yuriy.

Another question. Do you know how to hide values if they are null?

I was looking at some of the freemarker documentation but none of them seem to work.

e.g.

    ${(object.attribute)!}
    <#if object.attribute??></#if>

Hi
that templates are not freemarker based, despite the official emailer APIs in CUBA (the ones you use in your code), are in fact based on freemarker.

You must use the SimpleTemplateEngine (Groovy based) syntax to perform special computations in the template.

for example this line prints the name of a User entity if not null, otherwise a generic user string:

Hello <% print user.name == null ? "user" : user.name %>,

Bye
Paolo

1 Like