Logging Out
Since we have a method for logging in and because we like—er, because our customer is quite fond of symmetry, we should add a method for logging out. Don’t worry—it’ll take only a couple lines of code. Go back to TekDays/grails-app/controllers/com/tekdays/TekUserController, and add a logout action, like so:
security.2/TekDays/grails-app/controllers/com/tekdays/TekUserController.groovy | |
| def logout = { |
| session.user = null |
| redirect(uri:'/') |
| } |
Since the way that our filter determines whether a user is logged in is by the existence of a value in the user key, we set that key to null to “log them out.” We don’t need to check for a user key before we do this; if it doesn’t exist, it will be created and set to null. Then, to send ...
Get Grails 2: A Quick-Start Guide now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.