我已经自定义了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."
因为根据文档:
The emailBody property should be a GString and will have the User domain class instance in scope in the user variable, and the generated url to click to reset the password in the url variable.
但是,对于
MailStrategy
和user.email
值,包含在url
中的属性的参数映射为空:[to:blah@blah.com,
from:no-reply@blah.com, 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,以便可以发送被忘记的密码电子邮件?
最佳答案
GString应该从开始“” 而不是'
因此,而不是grails.plugin.springsecurity.ui.forgotPassword.emailBody = '...'
您应该使用:grails.plugin.springsecurity.ui.forgotPassword.emailBody = "..."
关于grails - Grails 3 Spring Security UI忘记密码空白URL和用户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38904123/