I want to display the info about the user logged in like his details etc given during sign up ...how to do it ?? As iam new to grails plz help! iam using Spring security plu
Well you can use the springSecurityService to get some user information in a controller:
class MyController {
def springSecurityService
def myAction() {
def principal = springSecurityService.principal
String username = principal.username
...
}
}
Or in a gsp
<sec:loggedInUserInfo field="username" />
It is a pretty general question.
Define (in a controller, or service where you need user id):
SpringSecurityService springSecurityService
and try:
springSecurityService.currentUser.id //loads user from db, and returns its id
or:
springSecurityService.principal.id //if you need just id
add this @the top of your service or controller class
def securityService
this returns the cuureent user id.
securityService.currentUser.id