简体   繁体   English

我如何查看或隐藏一些数据,取决于是否登录的用户?

[英]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.

相关问题 如何根据 JSF 中的用户角色隐藏一些内容? - How can I hide some content based on user role in JSF? 如何根据用户输入在Web视图前面隐藏和显示视图 - How to hide and display a view in front of a webview depending on user input 如何根据使用Spring Data Rest的登录用户返回自定义对象表示形式? - How to return a custom object representation depending on the logged in user with Spring Data Rest? 如何将已登录用户的会话数据传输到另一个Java应用程序 - How can i transfer session data of a logged in user to another Java application 用户登录后,如何在控制器中获取会话数据 - How can I get session data in my controller after user is logged in 如何在 Spring Boot Thymeleaf 中获取当前登录用户的数据? - How can I get the currently logged in user's data in Spring Boot Thymeleaf? Android / MySQL:如何根据与登录用户关联的部门显示数据? - Android/MySQL: how can I display data based on the department associated with the logged-in user? 如何使用 Firebase 在 Android Studio 项目中将记录的用户数据作为用户名检索到导航标头 - How can I retrieve Logged user data to nav header as Username in Android studio project with Firebase 用户登录后如何隐藏TextView - How to hide a TextView when the user is logged in 我想显示“ Gig posts”的元素,具体取决于登录的用户 - I want to display the elements of “Gig posts” depending on which user is logged in
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM