本文整理汇总了Python中database.User.get_by_username方法的典型用法代码示例。如果您正苦于以下问题:Python User.get_by_username方法的具体用法?Python User.get_by_username怎么用?Python User.get_by_username使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类database.User
的用法示例。
在下文中一共展示了User.get_by_username方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: attempt_login
# 需要导入模块: from database import User [as 别名]
# 或者: from database.User import get_by_username [as 别名]
def attempt_login(self, entered_username, password):
"""Attempt to login given a username and password.
If the credentials are invalid, return False and do nothing.
If the credentials are valid, add a user cookie and return True.
Args:
entered_username (str): Username for the attempted login
password (str): plaintext password user enters
Returns:
bool: True if login was successful, False if not
"""
user_in_db = User.get_by_username(entered_username)
if (user_in_db is not None and
auth.password_is_valid(entered_username,
password,
user_in_db.password)):
# If we have a match, the credentials are good
self.force_login(entered_username)
return True
else:
return False
示例2: initialize
# 需要导入模块: from database import User [as 别名]
# 或者: from database.User import get_by_username [as 别名]
def initialize(self, *args, **kwargs):
# Check if the user is logged in and cookie is secure
webapp2.RequestHandler.initialize(self, *args, **kwargs)
username = self.get_secure_cookie('user')
self.user = User.get_by_username(username)