Reputation: 8671
I wonder what's the best practise for passing user 'model' around. I take http request and convert it to user model in my controller. I don't want to explicitly add an argument to all the templates for this model, and neither to main. What are the best practises for doing this?
THanks.
Upvotes: 2
Views: 113
Reputation: 1193
Use the Session scope.
Here is documentation for Play 2.0
http://www.playframework.com/documentation/2.0.2/ScalaSessionFlash
So for example, on the login, add the user to the Session
And on logout remove the user from the Session
Cheers!
Upvotes: 0
Reputation: 4396
If you are logging in, and the user is your authenticated user, then you should put the user in a WrappedRequest and make your request implicit in your templates. If you use something like SecureSocial, then UserAwareAction will provide you with a RequestWithUser (see http://securesocial.ws/guide/user-service.html) and you can do things like
@()(implicit req:RequestWithUser)
Email = @{req.user.map(_.email)}
in your template.
Upvotes: 2