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


Python User.get_by_id方法代码示例

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


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

示例1: post

# 需要导入模块: from www.models import User [as 别名]
# 或者: from www.models.User import get_by_id [as 别名]
    def post(self):
        parameters = self.request.POST
        parameters = utils.pythonize(dict(parameters))
        email = parameters.get("email")
        password = parameters.get("password_raw")
        data = {}
        data["errors"] = {}

        if email:
            if not re.match(r"[^@][email protected][^@]+\.[^@]+", email):
                data["errors"]["email"] = "This value must be a valid email address"
        else:
            data["errors"]["email"] = 'This value is required'

        if password:
            if len(password) < 8:
                data["errors"]["password"] = "This value must be at least 8 characters"
        else:
            data["errors"]["password"] = "This value is required"

        if data["errors"]:
            self.write_json(json.dumps(data))
            return

        user = None
        try:
            email = email.lower()
            user = self.auth.get_user_by_password(email, password)
        except InvalidAuthIdError:
            data["errors"]["email"]= "No user exists with this email."
            self.write_json(json.dumps(data))
            return

        except InvalidPasswordError:
            data["errors"]["password"]= "This password is incorrect."
            self.write_json(json.dumps(data))
            return

        user = User.get_by_id(user['user_id'])
        if not user:
            # this should never happen, but just to be safe
            data["redirect"] = self.uri_for('authenticate')
        elif user.has_roles(['ADMINISTRATOR', 'STAFF']):
            data["redirect"] = self.uri_for('admin_home')
        elif user.has_role('HACKER'):
            data["redirect"]= self.uri_for('register')
        else:
            data["errors"]["email"] = "Sorry, but you cannot authenticate here"
            self.auth.unset_session()

        self.write_json(json.dumps(data))
开发者ID:HackIllinois,项目名称:infrastructure-2016,代码行数:53,代码来源:auth.py


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