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


Python Role.by_email方法代码示例

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


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

示例1: create

# 需要导入模块: from aleph.model import Role [as 别名]
# 或者: from aleph.model.Role import by_email [as 别名]
def create():
    require(not request.authz.in_maintenance, settings.PASSWORD_LOGIN)
    data = parse_request(RoleCreateSchema)

    try:
        email = Role.SIGNATURE.loads(data.get('code'),
                                     max_age=Role.SIGNATURE_MAX_AGE)
    except BadSignature:
        return jsonify({
            'status': 'error',
            'message': gettext('Invalid code')
        }, status=400)

    role = Role.by_email(email)
    if role is not None:
        return jsonify({
            'status': 'error',
            'message': gettext('Email is already registered')
        }, status=409)

    role = Role.load_or_create(
        foreign_id='password:{}'.format(email),
        type=Role.USER,
        name=data.get('name') or email,
        email=email
    )
    role.set_password(data.get('password'))
    db.session.add(role)
    db.session.commit()
    update_role(role)
    # Let the serializer return more info about this user
    request.authz.id = role.id
    tag_request(role_id=role.id)
    return RoleSerializer.jsonify(role, status=201)
开发者ID:pudo,项目名称:aleph,代码行数:36,代码来源:roles_api.py

示例2: password_login

# 需要导入模块: from aleph.model import Role [as 别名]
# 或者: from aleph.model.Role import by_email [as 别名]
def password_login():
    """Provides email and password authentication."""
    data = parse_request(LoginSchema)
    role = Role.by_email(data.get('email'))
    if role is None or not role.has_password:
        return Unauthorized("Authentication has failed.")

    if not role.check_password(data.get('password')):
        return Unauthorized("Authentication has failed.")

    db.session.commit()
    update_role(role)
    authz = Authz.from_role(role)
    request.authz = authz
    record_audit(Audit.ACT_LOGIN)
    return jsonify({
        'status': 'ok',
        'token': authz.to_token(role=role)
    })
开发者ID:pudo,项目名称:aleph,代码行数:21,代码来源:sessions_api.py

示例3: test_create_success

# 需要导入模块: from aleph.model import Role [as 别名]
# 或者: from aleph.model.Role import by_email [as 别名]
    def test_create_success(self):
        settings.PASSWORD_LOGIN = True
        email = self.fake.email()
        name = self.fake.name()
        password = self.fake.password()
        payload = dict(
            name=name,
            password=password,
            code=Role.SIGNATURE.dumps(email)
        )
        res = self.client.post('/api/2/roles', data=payload)
        db.session.close()

        self.assertEqual(res.status_code, 201)
        self.assertEqual(res.json['email'], email)

        role = Role.by_email(email)
        self.assertIsNotNone(role)
        self.assertTrue(role.check_password(password))
        self.assertEqual(role.name, payload['name'])
开发者ID:pudo,项目名称:aleph,代码行数:22,代码来源:test_roles_api.py

示例4: test_by_email_matches

# 需要导入模块: from aleph.model import Role [as 别名]
# 或者: from aleph.model.Role import by_email [as 别名]
 def test_by_email_matches(self):
     self.assertEqual(Role.by_email(self.role.email), self.role)
开发者ID:pudo,项目名称:aleph,代码行数:4,代码来源:test_role_model.py

示例5: test_by_email_does_not_match

# 需要导入模块: from aleph.model import Role [as 别名]
# 或者: from aleph.model.Role import by_email [as 别名]
 def test_by_email_does_not_match(self):
     self.assertIsNone(Role.by_email(self.fake.email()))
开发者ID:pudo,项目名称:aleph,代码行数:4,代码来源:test_role_model.py

示例6: test_by_email_when_blank_email

# 需要导入模块: from aleph.model import Role [as 别名]
# 或者: from aleph.model.Role import by_email [as 别名]
 def test_by_email_when_blank_email(self):
     self.assertIsNone(Role.by_email(None))
开发者ID:pudo,项目名称:aleph,代码行数:4,代码来源:test_role_model.py


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