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


Python User.from_contact方法代码示例

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


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

示例1: login_required

# 需要导入模块: from user import User [as 别名]
# 或者: from user.User import from_contact [as 别名]
def login_required():
    # :COMMENT:maethor:150718: This hack is crazy, but I don't know how to do it properly
    app = bottle.BaseTemplate.defaults['app']

    logger.debug("[WebUI] login_required, requested URL: %s", request.urlparts.path)
    if request.urlparts.path == "/user/login" or request.urlparts.path == app.get_url("GetLogin"):
        return
    if request.urlparts.path == "/user/auth" or request.urlparts.path == app.get_url("SetLogin"):
        return
    if request.urlparts.path.startswith('/static'):
        return

    logger.debug("[WebUI] login_required, getting user cookie ...")
    username = bottle.request.get_cookie("user", secret=app.auth_secret)
    if not username and not app.allow_anonymous:
        # bottle.redirect(app.get_url("GetLogin"))
        bottle.redirect("/user/login")
    contact = app.datamgr.get_contact(username or 'anonymous')
    if not contact:
        # bottle.redirect(app.get_url("GetLogin"))
        bottle.redirect("/user/login")

    user = User.from_contact(contact, app.user_picture, app.gravatar)
    app.user_picture = user.picture
    request.environ['USER'] = user
    bottle.BaseTemplate.defaults['user'] = user
    logger.debug("[WebUI] login_required: user: %s", user)
开发者ID:rednach,项目名称:mod-webui,代码行数:29,代码来源:module.py

示例2: can_action

# 需要导入模块: from user import User [as 别名]
# 或者: from user.User import from_contact [as 别名]
    def can_action(self, username=None):
        if username:
            user = User.from_contact(self.datamgr.get_contact(username), self.gravatar)
        else:
            user = request.environ.get('USER', None)

        try:
            retval = user and ((not self.manage_acl) or user.is_admin or user.can_submit_commands)
        except:
            retval = False
        return retval
开发者ID:rednach,项目名称:mod-webui,代码行数:13,代码来源:module.py

示例3: get_user_auth

# 需要导入模块: from user import User [as 别名]
# 或者: from user.User import from_contact [as 别名]
    def get_user_auth(self):
        logger.warning("[WebUI] Deprecated - Getting authenticated user ...")
        self.user_picture = None

        username = webui_app.request.get_cookie("user", secret=self.auth_secret)
        if not username and not self.allow_anonymous:
            return None
        contact = self.datamgr.get_contact(username or 'anonymous')
        if not contact:
            return None

        user = User.from_contact(contact, self.user_picture, self.gravatar)
        self.user_picture = user.picture
        return user
开发者ID:rednach,项目名称:mod-webui,代码行数:16,代码来源:module.py

示例4: check_authentication

# 需要导入模块: from user import User [as 别名]
# 或者: from user.User import from_contact [as 别名]
    def check_authentication(self, username, password):
        logger.info("[WebUI] Checking authentication for user: %s", username)
        self.user_picture = None

        c = self.datamgr.get_contact(username)
        if not c:
            logger.error("[WebUI] You need to have a contact having the same name as your user: %s", username)
            return False

        logger.info("[WebUI] Requesting authentication for user: %s", username)
        r = self.auth_module.check_auth(username, password)
        if r:
            user = User.from_contact(c, picture=self.user_picture, use_gravatar=self.gravatar)
            self.user_picture = user.picture
            logger.info("[WebUI] User picture: %s", self.user_picture)
            return True

        logger.warning("[WebUI] The user '%s' has not been authenticated.", username)
        return False
开发者ID:rednach,项目名称:mod-webui,代码行数:21,代码来源:module.py

示例5: login_required

# 需要导入模块: from user import User [as 别名]
# 或者: from user.User import from_contact [as 别名]
def login_required():
    # :COMMENT:maethor:150718: This hack is crazy, but I don't know how to do it properly
    app = bottle.BaseTemplate.defaults['app']
    request.environ['APP'] = app

    if request.urlparts.path == '/user/login':
        return
    if request.urlparts.path == '/user/auth':
        return
    if request.urlparts.path.startswith('/static'):
        return

    username = bottle.request.get_cookie("user", secret=app.auth_secret)
    if not username and not app.allow_anonymous:
        app.bottle.redirect("/user/login")
    contact = app.datamgr.get_contact(username or 'anonymous')
    if not contact:
        app.bottle.redirect("/user/login")

    request.environ['USER'] = User.from_contact(contact, app.gravatar)
    bottle.BaseTemplate.defaults['user'] = request.environ['USER']
开发者ID:vizvayu,项目名称:mod-webui,代码行数:23,代码来源:module.py


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