如何自动注销选择删除其帐户的登录用户?

时间:2012-02-24 01:08:16

标签: grails groovy logged

我正在使用grails。我创建了一个删除特定用户帐户的服务。如果登录用户选择删除他的帐户,则会将验证链接发送到他的电子邮件地址,一旦他点击该链接,他的帐户将从数据库中删除,同时他将从该帐户自动注销系统,将被重定向到网站的主页。

这是我删除帐户的代码。有人可以给我关于如何自动注销当前登录用户的代码吗?

class AccountDeletionService {

    static transactional = true
    def auditLogService
    def springSecurityService

    def delete(Registrant registrant, String key) {
        if(key && registrant?.accountDeletionKey == key){

            def account = springSecurityService.getCurrentUser()
            def loggeduser = account.id

            RegistrantEligibilityInformation.executeUpdate(
                "delete RegistrantEligibilityInformation as rei where rei.registrant in (" + 
                "select reg from Registrant as reg where reg.account.id=:loggeduser)",[loggeduser:loggeduser])
            RegistrantEducationInformation.executeUpdate(
                "delete RegistrantEducationInformation as reduc where reduc.registrant in (" + 
                "select reg from Registrant as reg where reg.account.id=:loggeduser)",[loggeduser:loggeduser])
            Registrant.executeUpdate("delete Registrant as reg where reg.account.id=:loggeduser",[loggeduser:loggeduser])
            AccountRole.executeUpdate("delete AccountRole as actrole where actrole.account.id=:loggeduser)",[loggeduser:loggeduser])
            Account.executeUpdate("delete Account as act where  act.id=:loggeduser)",[loggeduser:loggeduser]) 


        } else return false
    }
}

1 个答案:

答案 0 :(得分:2)

在大多数情况下,只需拨打

即可
session.invalidate()

应该足够了。请参阅grails doc