I am working with grails. I have created a service that will delete the account of a particular user. If a logged in user opts to delete his account, a verification link will be sent to his email address, once he click on that link, his account will be removed from the database, and at the same he will be auto logged out from the system, and will be redirected to the home page of the website.
This is my code in deleting the account. Anybody can give me the code on how to auto logged out the currently logged in user?
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
}
}
In most cases, simply calling
should be enough. see the grails doc