简体   繁体   English

在 PlayFramework 中查看用户配置文件?

[英]Check user profile in view in PlayFramework?

In my Play application, I've added Secure module.在我的 Play 应用程序中,我添加了 Secure 模块。 But I haven't found a way to check user profile in views.但我还没有找到在视图中检查用户个人资料的方法。 For example, one of the possible roles is "admin".例如,可能的角色之一是“管理员”。 When viewing certain pages, a button should be visible to admin's only.查看某些页面时,按钮应该只对管理员可见。 How to do that?怎么做?

My first idea was to check session variable but I found nothing there.我的第一个想法是检查 session 变量,但我在那里什么也没找到。 Security object is not available in views.安全性 object 在视图中不可用。 Then I thought about putting data in there by overriding onAuthenticated method in my authentification controller, but I'm not sure that is the best way to proceed.然后我考虑通过在我的身份验证 controller 中覆盖onAuthenticated方法将数据放入其中,但我不确定这是最好的方法。

What do you think?你怎么看?

If you have your own security module that extends controller.secure.Security, then within your view you can do this:如果您有自己的扩展 controller.secure.Security 的安全模块,那么在您的视图中,您可以这样做:

#{if controllers.MySecurity.check("isAdmin") }
   ...template code...
#{/if}

Have you seen the deadbolt module for role checking?你见过用于角色检查的锁栓模块吗? http://www.playframework.org/modules/deadbolt-1.0/home http://www.playframework.org/modules/deadbolt-1.0/home

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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