【问题标题】:Using beaker sessions for checking if user is authenticated in Pyramid使用烧杯会话检查用户是否在 Pyramid 中经过身份验证
【发布时间】:2011-11-09 01:26:56
【问题描述】:

我正在使用 Pyramid 和 Beaker 会话创建一个 web 应用程序。
我想在成功登录后将用户 ID 存储在 request.session['user_id'] 和其他一些信息中,然后用它来检查用户是否已经登录:

if 'user_id' in request.session:
    # user signed in
else:
    # user not signed in or session is expired

问题是:依赖会话是否安全,或者将 Pyramid 的 authenticated_userid()remember() 和来自 pyramid.securityforget() 一起使用会更好和/或更安全?

【问题讨论】:

    标签: python session authentication pyramid


    【解决方案1】:

    使用 pyramid_beaker 和 SessionAuthenticationPolicy,然后使用 pyramid.authentication.authenticated_userid() 检查他们是否已登录。如果它返回None,则不是。

    【讨论】:

    • 我应该怎么做才能得到authenticated_userid()的实际用户ID?我应该传递从remember() 获得的标题吗?
    • 喜欢这里的“登录”视图:docs.pylonsproject.org/projects/pyramid/1.2/tutorials/wiki2/… .. 将记住的结果设置到响应头中。
    • 我只是打电话给remember(),然后一切都完全按照需要工作。无论如何,非常感谢您的回答
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-06-24
    • 2012-04-16
    • 1970-01-01
    • 2020-11-29
    • 1970-01-01
    • 1970-01-01
    • 2015-08-09
    相关资源
    最近更新 更多