December 2013
Beginner to intermediate
222 pages
5h 13m
English
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 ...
Read now
Unlock full access