本文整理汇总了Python中user.User.find_by_username方法的典型用法代码示例。如果您正苦于以下问题:Python User.find_by_username方法的具体用法?Python User.find_by_username怎么用?Python User.find_by_username使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类user.User
的用法示例。
在下文中一共展示了User.find_by_username方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: post
# 需要导入模块: from user import User [as 别名]
# 或者: from user.User import find_by_username [as 别名]
def post(self):
username = self.request.get('username').strip().lower()
password = self.request.get('password')
# If user/password matches redirect to homepage,
# otherwise re-render the form with errors
if not (username and password):
self.render(
'login.html', error='Enter both username and password!')
else:
user = User.find_by_username(username)
if user and Cryptographer().valid_password(
username, password, user.password):
self.login(user.key().id())
self.redirect('/')
else:
self.render(
'login.html', error='Wrong username and/or password!')
示例2: authenticate
# 需要导入模块: from user import User [as 别名]
# 或者: from user.User import find_by_username [as 别名]
def authenticate(username, password):
user = User.find_by_username(username)
if user and safe_str_cmp(user.password, password):
return user
示例3: authenticate
# 需要导入模块: from user import User [as 别名]
# 或者: from user.User import find_by_username [as 别名]
def authenticate(username, password):
user = User.find_by_username(username)
if user and safe_str_cmp(user.password, password): #this is equivalent of user.password == password, it just works on all python versions and different systems
return user