[英]How can I view or hide some data depending of user logged in or not?
I am testing Play framework 2.2.2. 我正在测试Play框架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-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 . 考虑使用Deadbolt-2,它专用于此工作,它允许根据日志记录状态以及角色和权限在视图中显示(或隐藏)内容。 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. 您也可以选择查看Play Authnticate,它是完整的授权/身份验证堆栈-由于上述原因,它也使用Deadbolt。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.