当前位置: 首页>>代码示例>>Python>>正文


Python Session.data["auth_user_fullname"]方法代码示例

本文整理汇总了Python中framework.sessions.model.Session.data["auth_user_fullname"]方法的典型用法代码示例。如果您正苦于以下问题:Python Session.data["auth_user_fullname"]方法的具体用法?Python Session.data["auth_user_fullname"]怎么用?Python Session.data["auth_user_fullname"]使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在framework.sessions.model.Session的用法示例。


在下文中一共展示了Session.data["auth_user_fullname"]方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: before_request

# 需要导入模块: from framework.sessions.model import Session [as 别名]
# 或者: from framework.sessions.model.Session import data["auth_user_fullname"] [as 别名]
def before_request():
    # TODO: Fix circular import
    from framework.auth.core import get_user
    from framework.auth import cas
    from website.util import time as util_time

    # Central Authentication Server Ticket Validation and Authentication
    ticket = request.args.get("ticket")
    if ticket:
        service_url = furl.furl(request.url)
        service_url.args.pop("ticket")
        # Attempt to authenticate wih CAS, and return a proper redirect response
        return cas.make_response_from_ticket(ticket=ticket, service_url=service_url.url)

    if request.authorization:
        user = get_user(email=request.authorization.username, password=request.authorization.password)
        # Create an empty session
        # TODO: Shoudn't need to create a session for Basic Auth
        user_session = Session()
        set_session(user_session)

        if user:
            user_addon = user.get_addon("twofactor")
            if user_addon and user_addon.is_confirmed:
                otp = request.headers.get("X-OSF-OTP")
                if otp is None or not user_addon.verify_code(otp):
                    # Must specify two-factor authentication OTP code or invalid two-factor authentication OTP code.
                    user_session.data["auth_error_code"] = http.UNAUTHORIZED
                    return
            user_session.data["auth_user_username"] = user.username
            user_session.data["auth_user_id"] = user._primary_key
            user_session.data["auth_user_fullname"] = user.fullname
        else:
            # Invalid key: Not found in database
            user_session.data["auth_error_code"] = http.UNAUTHORIZED
        return

    cookie = request.cookies.get(settings.COOKIE_NAME)
    if cookie:
        try:
            session_id = itsdangerous.Signer(settings.SECRET_KEY).unsign(cookie)
            user_session = Session.load(session_id) or Session(_id=session_id)
        except itsdangerous.BadData:
            return
        if not util_time.throttle_period_expired(user_session.date_created, settings.OSF_SESSION_TIMEOUT):
            if user_session.data.get("auth_user_id") and "api" not in request.url:
                database["user"].update(
                    {"_id": user_session.data.get("auth_user_id")},
                    {"$set": {"date_last_login": datetime.utcnow()}},
                    w=0,
                )
            set_session(user_session)
        else:
            remove_session(user_session)
开发者ID:,项目名称:,代码行数:56,代码来源:


注:本文中的framework.sessions.model.Session.data["auth_user_fullname"]方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。