如何使用安全模块检查用户是否从视图连接(How can I check if a user is connected from a view, using the Secure module)

系统教程 行业动态 更新时间:2024-06-14 17:04:03
如何使用安全模块检查用户是否从视图连接(How can I check if a user is connected from a view, using the Secure module)

我正在使用安全模块,如果我的标题不清楚: http : //www.playframework.org/documentation/1.2.4/secure

(安全控制器驻留在(标准)控制器包中)

我在main.html模板中有这个:

#{if Security.isConnected != true} <a href="#" id="loginSlider">Login</a> #{/if} #{else} <a href="/logout">Logout</a> #{/else}

它似乎不起作用,因为“安全”从这里是空的。 我发现在playframework.org上记录得相当糟糕。

[编辑]我尝试过的事情:在Controller前添加@:#{if @ Security.isConnected!= true}使用包名称进行前缀:#{if @ controllers.Security.isConnected!= true}

我已经通过导航到安全页面验证我确实登录了。

[EDIT2]找到了可行的解决方法,但我不喜欢它。 基本上,安全控制器方法isConnected执行此操作:return session.contains(“username”)。 所以我可以在我看来检查:

#{ifnot session.contains("username")}

但它不是最佳解决方案......

I'm using the Secure module if that wasn't clear from my title: http://www.playframework.org/documentation/1.2.4/secure

(The Security controller resides in the (standard) controllers package)

I have this in my main.html template:

#{if Security.isConnected != true} <a href="#" id="loginSlider">Login</a> #{/if} #{else} <a href="/logout">Logout</a> #{/else}

And it doesn't seem to work as "Security" is null from here. I've found it to be fairly poorly documented on playframework.org.

[EDIT] Things I've tried: Adding a @ in front of the Controller: #{if @Security.isConnected != true} Prefixing with package name: #{if @controllers.Security.isConnected != true}

I've verified that I am indeed logged in by navigating to a secure page.

[EDIT2] Found a workaround that works, but I dislike it. Basically, the Security controller method isConnected does this: return session.contains("username"). So I can do that check in my view:

#{ifnot session.contains("username")}

But its not the optimal solution...

最满意答案

#{ifnot controllers.Security.isConnected()} <a href="#" id="loginSlider">Login</a> #{/ifnot} #{else} <a href="/logout">Logout</a> #{/else} #{ifnot controllers.Security.isConnected()} <a href="#" id="loginSlider">Login</a> #{/ifnot} #{else} <a href="/logout">Logout</a> #{/else}

更多推荐

本文发布于:2023-04-24 21:17:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/dzcp/80da5309fb86fd58d63932a264817584.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:视图   如何使用   模块   用户   check

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!