本文整理汇总了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)
示例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)
})
示例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'])
示例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)
示例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()))
示例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))