简体   繁体   中英

How can I view or hide some data depending of user logged in or not?

I am testing Play framework 2.2.2. There is a helper for user authentication and seems to be simple to implement it. But if I need to hide some menus or other content from unregistered users - how can I do it?

I am thinking about if-blocks :

@if(...) {
  <h1>Content for registered users only</h1>
} else {
  <h1>Register to see this content</h1>
}

but what will be in the condition block? Have anybody an example?

Consider using Deadbolt-2 it's dedicated for this job, it allows to show (or hide) content in views depending on logging state but also by roles and permitions . Also incorporates access control for controller and/or actions.

Optionally you can also look at Play Authnticate it's full authorization/authentication stack - it also uses Deadbolt for mentioned reasons.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM