我正在使用 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
}
}