Я настроил grails.plugin.springsecurity.userLookup.usernamePropertyName = "email"
, но поведение рендеринга по умолчанию для тела электронной почты завершится ошибкой:
No such property: username for class
Поэтому я настроил emailBody
в своем application.groovy
:
grails.plugin.springsecurity.ui.forgotPassword.emailBody = "Dear ${user.email} , Please follow <a href='${url}'>this link</a> to reset your password. This link will expire shortly."
потому что согласно документам:
Свойство emailBody должно быть GString и будет иметь экземпляр класса домена пользователя в области видимости в пользовательской переменной и сгенерированный URL-адрес, по которому нужно щелкнуть, чтобы сбросить пароль, в переменной url.
Однако карта параметров, содержащая свойства в моем MailStrategy
, пуста для значений user.email
и url
:
[to:[email protected],
from:[email protected], subject:Reset your password for your account,
html:Dear [:], Please follow <a href='[:']>this link</a> to reset your password. This link will expire shortly.]
Обратите внимание на [:]
и [:]
для значений user.email
и url
.
Плагин spring-security настроен с этими значениями в application.groovy
:
grails.plugin.springsecurity.userLookup.userDomainClassName = 'blah.Account'
grails.plugin.springsecurity.userLookup.authorityJoinClassName = 'blah.AccountRole'
grails.plugin.springsecurity.authority.className = 'blah.Role'
grails.plugin.springsecurity.requestMap.className = 'blah.Requestmap'
grails.plugin.springsecurity.securityConfigType = 'Annotation'
Класс Account
определяется как:
String email
String password
Date emailVerified = null
boolean enabled = true
boolean accountExpired
boolean accountLocked
boolean passwordExpired
Set<Role> getAuthorities() {
AccountRole.findAllByAccount(this)*.role
}
def beforeInsert() {
encodePassword()
}
def beforeUpdate() {
if (isDirty('password')) {
encodePassword()
}
}
protected void encodePassword() {
password = springSecurityService?.passwordEncoder ? springSecurityService.encodePassword(password) : password
}
static transients = ['springSecurityService']
static constraints = {
password blank: false, password: true
email blank: false, unique: true
emailVerified nullable: true
}
static mapping = {
password column: '`password`'
}
Как я могу получить имя пользователя и, что более важно, URL-адрес, отображаемый для меня, чтобы я мог отправить электронное письмо с забытым паролем?