本文整理汇总了Python中user.User.get_user_from_token方法的典型用法代码示例。如果您正苦于以下问题:Python User.get_user_from_token方法的具体用法?Python User.get_user_from_token怎么用?Python User.get_user_from_token使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类user.User
的用法示例。
在下文中一共展示了User.get_user_from_token方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: fivee
# 需要导入模块: from user import User [as 别名]
# 或者: from user.User import get_user_from_token [as 别名]
def fivee():
if request.method == 'POST':
user = User.get_user_from_token(request.form['token'])
if not user:
abort(404)
user.load()
if user['status'] == "waiting":
return jsonify({})
user['lat'] = request.form['lat']
user['lng'] = request.form['lng']
if not user['lat'] or not user['lng']:
abort(400)
user.save()
log.info("User %s want to be a fivee", user['username'])
fiver_wait_list = User.get_wait_list('fiver')
fiver_match = None
fiver_distance = None
for str_fiver in fiver_wait_list:
fiver = json.loads(str_fiver)
distance = user.distance(fiver['lat'], fiver['lng'])
if fiver_distance is None or distance < fiver_distance:
fiver_distance = distance
fiver_match = str_fiver
if fiver_distance is None or fiver_distance > MAX_FYVE_DISTANCE:
# No matches
user['match'] = "..."
user['status'] = "waiting"
user.save()
User.insert_into_wait_list('fivee', json.dumps(user.wait_list_format))
return jsonify({})
# We found a match!
User.remove_from_wait_list('fiver', fiver_match)
fiver_match = User(json.loads(fiver_match)['username'])
fiver_match.load()
fiver_match['match'] = user['username']
fiver_match['status'] = "matched"
fiver_match.save()
user['match'] = fiver_match['username']
user['status'] = "matched"
user.save()
return jsonify(fiver_match.match_format)
else:
user = User.get_user_from_token(request.args['token'])
if not user:
abort(404)
user.load()
# Checking in for a match
if user['match'] == "...":
# Still waiting
assert user['status'] == "waiting"
return jsonify({})
# We have a match!
match_user = User(user['match'])
match_user.load()
return jsonify(match_user.match_format)
示例2: status
# 需要导入模块: from user import User [as 别名]
# 或者: from user.User import get_user_from_token [as 别名]
def status():
user = User.get_user_from_token(request.args['token'])
if not user:
abort(404)
user.load()
return jsonify(user.status_format)
示例3: rate
# 需要导入模块: from user import User [as 别名]
# 或者: from user.User import get_user_from_token [as 别名]
def rate():
user = User.get_user_from_token(request.form['token'])
if not user:
abort(404)
if not request.form['username'] or not request.form['rating']:
abort(400)
rated_user = User(request.form['username'])
five_rating = request.form['rating']
rated_user.rate(five_rating)
log.info("User %s rated user %s with a %s", user['username'], rated_user['username'], five_rating)
return jsonify({})
示例4: success
# 需要导入模块: from user import User [as 别名]
# 或者: from user.User import get_user_from_token [as 别名]
def success():
user = User.get_user_from_token(request.form['token'])
if not user:
abort(404)
log.info("User %s is reporting a successful high five!", user['username'])
user.load()
user_fyved = User(user['match'])
user_fyved.load()
# Fuck yeah!
user['status'] = "fyved"
user.save()
user_fyved['status'] = "fyved"
user_fyved.save()
return jsonify({})
示例5: bail
# 需要导入模块: from user import User [as 别名]
# 或者: from user.User import get_user_from_token [as 别名]
def bail():
user = User.get_user_from_token(request.form['token'])
if not user:
abort(404)
log.info("User %s is bailing", user['username'])
user.load()
user_left_hanging = User(user['match'])
user_left_hanging.load()
user_left_hanging['status'] = "cancelled"
user_left_hanging.save()
user['status'] = "cancelled"
user.save()
return jsonify({})