本文整理汇总了Python中models.UserInfo.get_with_token方法的典型用法代码示例。如果您正苦于以下问题:Python UserInfo.get_with_token方法的具体用法?Python UserInfo.get_with_token怎么用?Python UserInfo.get_with_token使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.UserInfo
的用法示例。
在下文中一共展示了UserInfo.get_with_token方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: login
# 需要导入模块: from models import UserInfo [as 别名]
# 或者: from models.UserInfo import get_with_token [as 别名]
def login():
if 'Authorization' in request.headers:
user = UserInfo.get_with_token(request.headers['Authorization'])
if user is not None:
login_user(user)
response = {}
response['code'] = 0
response['cell'] = user.cell
response['token'] = user.token
return json.dumps(response)
# return "User: "+user.cell+" successfully logged in by token"
try:
cell = request.json['cell']
pwd = request.json['password']
user = UserInfo.get_with_cell(cell=cell)
if (user is not None) and (user.password == pwd):
login_user(user, remember=True)
response = {}
response['code'] = 0
response['cell'] = cell
response['token'] = user.token
return json.dumps(response)
else:
response = {'code': 1}
return json.dumps(response)
except (KeyError, TypeError, ValueError):
response = {'code': -2}
return json.dumps(response)