本文整理汇总了Python中User.gen_api_key方法的典型用法代码示例。如果您正苦于以下问题:Python User.gen_api_key方法的具体用法?Python User.gen_api_key怎么用?Python User.gen_api_key使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类User
的用法示例。
在下文中一共展示了User.gen_api_key方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: new_user
# 需要导入模块: import User [as 别名]
# 或者: from User import gen_api_key [as 别名]
def new_user(request):
"""Add a new user to the system manually."""
rdict = request.params
u = User()
u.username = unicode(rdict.get('username'))
u.email = unicode(rdict.get('email'))
passwd = get_random_word(8)
u.password = passwd
u.activated = True
u.is_admin = False
u.api_key = User.gen_api_key()
try:
DBSession.add(u)
DBSession.flush()
# We need to return the password since the admin added the user
# manually. This is only time we should have/give the original
# password.
ret = dict(u)
ret['random_pass'] = passwd
return _api_response(request, ret)
except IntegrityError, exc:
# We might try to add a user that already exists.
LOG.error(exc)
request.response.status_int = 400
return _api_response(request, {
'error': 'Bad Request: User exists.',
})
示例2: upgrade
# 需要导入模块: import User [as 别名]
# 或者: from User import gen_api_key [as 别名]
def upgrade():
"""Preseed data into the system."""
current_context = op.get_context()
meta = current_context.opts['target_metadata']
user = sa.Table('users', meta, autoload=True)
api_key = User.gen_api_key()
# Add the initial admin user account.
op.bulk_insert(user, [{
'username': u'admin',
'password': u'$2a$10$FK7DVvSYzXNqJRbYD8yAJ..eKosDzYH29ERuKCwlMLdozMWDkySl2',
'email': u'[email protected]',
'activated': True,
'is_admin': True,
'api_key': api_key,
}
])