当前位置: 首页>>代码示例>>Python>>正文


Python User.get_user_from_token方法代码示例

本文整理汇总了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)
开发者ID:Spearl,项目名称:highfyve-api,代码行数:61,代码来源:fyve.py

示例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)
开发者ID:Spearl,项目名称:highfyve-api,代码行数:9,代码来源:fyve.py

示例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({})
开发者ID:Spearl,项目名称:highfyve-api,代码行数:14,代码来源:fyve.py

示例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({})
开发者ID:Spearl,项目名称:highfyve-api,代码行数:18,代码来源:fyve.py

示例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({})
开发者ID:Spearl,项目名称:highfyve-api,代码行数:18,代码来源:fyve.py


注:本文中的user.User.get_user_from_token方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。