本文整理汇总了Python中accounts.models.User.get_by_username方法的典型用法代码示例。如果您正苦于以下问题:Python User.get_by_username方法的具体用法?Python User.get_by_username怎么用?Python User.get_by_username使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类accounts.models.User
的用法示例。
在下文中一共展示了User.get_by_username方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_create_delete_user
# 需要导入模块: from accounts.models import User [as 别名]
# 或者: from accounts.models.User import get_by_username [as 别名]
def test_create_delete_user(self):
username = self.test_user_username
email = self.test_user_email
password = self.test_user_password
self.assertTrue(create_user(username, email, password))
self.assertTrue(User.get_by_username(self.test_user_username))
self.assertTrue(delete_user(username))
示例2: delete_user
# 需要导入模块: from accounts.models import User [as 别名]
# 或者: from accounts.models.User import get_by_username [as 别名]
def delete_user(username=None):
u = User.get_by_username(username)
ret_val = False
if u:
u.remove()
ret_val = True
return ret_val
示例3: login
# 需要导入模块: from accounts.models import User [as 别名]
# 或者: from accounts.models.User import get_by_username [as 别名]
def login():
"""
User login
"""
form = request.form
if request.method == 'POST':
organization = Organization.get_by_name(form.get('organization').lower())
# validate
user = User.get_by_username(form.get('username'), organization.uuid)
if user:
if utils.hash_password(form.get('password')) == user.password:
login_user(user)
session['user'] = user
session['organization'] = organization
current_app.logger.info('User {0} ({1}) login from {2}'.format(user.username, organization.name, \
request.remote_addr))
return redirect(request.args.get("next") or url_for("index"))
current_app.logger.warn('Invalid login for {0} ({1}) from {2}'.format(form.get('username'), organization.name, \
request.remote_addr))
flash(messages.INVALID_USERNAME_OR_PASSWORD, 'error')
ctx = {
}
return render_template('accounts/login.html', **ctx)