gpt4 book ai didi

spring - 在不使用Spring Security的情况下忘记了密码功能

转载 作者:行者123 更新时间:2023-12-02 14:48:26 24 4
gpt4 key购买 nike

在我的grails(2.4.4版)应用程序中,我使用邮件插件发送确认邮件,现在我需要实现忘记密码的代码。

不使用Spring Security就可以实现它吗?

谢谢..

我在My UserController 中确实喜欢

def forgotPassword={
if (params.email) {
User user = User.findByEmail(params.email)
if (user) {
def password = randomService.generateRandomString(6)
user.password = authenticateService.encodePassword(password)
if (!user.save(flush:true)) {
user.errors.each {
log.error "err $it"
}
flash.message = message(code: "UserController.msg.forgot.error")
} else {
UserService.sendmail {
to user.email
subject message(code:"UserController.mail.forgot.subject" )
body(view:"forgotPasswordEmail", model: [person:user, password:password])
}
flash.message = message(code:"UserController.msg.forgot", args:[user.email] )
}
} else {
flash.message = message(code:"UserController.msg.forgot.unknown", args:[params.email])
}
}
}

它没有显示任何错误,但没有结果

最佳答案

您应该:

  • 有一个 View /[yourController]/forgotPassword.gsp来呈现您的flash.message
  • 将某些内容渲染到输出render 'email was sent'中,该代码仅在浏览器
  • 中显示此消息
  • 设置响应的状态码(用于REST调用)response.status = 200
  • 关于spring - 在不使用Spring Security的情况下忘记了密码功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53129205/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com