Changing last login date in Grails with Spring Security
程序员文章站
2022-05-19 22:14:05
...
在使用grails spring security core plugin时,实现用户登录的时候更新上次登录时间
在Config.groovy添加如下代码:
Reference: http://*.com/questions/5868311/changing-last-login-date-in-grails-with-spring-security
在Config.groovy添加如下代码:
import com.myapp.User grails.plugins.springsecurity.useSecurityEventListener = true grails.plugins.springsecurity.onInteractiveAuthenticationSuccessEvent = { e, appCtx -> User.withTransaction { def user = User.findById(appCtx.springSecurityService.principal.id) if(!user.isAttached()) user.attach() user.lastLoginDate = new Date() user.save(flush: true, failOnError: true) } }
Reference: http://*.com/questions/5868311/changing-last-login-date-in-grails-with-spring-security
上一篇: 学习收获:结构体