Example #1
0
def user_login():
    """
    (PUT: user)
    Method to handle when a user authenticates (from Facebook), be it a new user, or recurring user
    """

    fb_code = request.form.get("fb_code", None)
    access_token = request.form.get("access_token", None)
    
    if access_token is None:
        access_token = get_user_access_token(fb_code, APP_ID, APP_SECRET)
    
    fb_user_info, user = save_user(access_token, fb_code)
    api_key = gen_api_key(access_token, user.id)
    
    friends = get_friends(user, exclude_self=True)

    return jsonify({"status": "ok",
                    "result": {
                        "user": {
                                 "id": user.id,
                                 "name": user.facebook_user.name, 
                                 },
                        "friends": sanify_friends(friends),
                        "facebook_user_id": fb_user_info["id"],
                        "facebook_portrait_url": "https://graph.facebook.com/%s/picture" % user.facebook_user.id,
                        "api_key": api_key,
                    }
                    })
Example #2
0
def get_friends():
    user_id = request.args.get("user_id")
    signature = request.args.get("signature")
    
    if not authorize("get", "friends", user_id, signature):
        return authorization_fail()
    
    #generated
    user_obj = get_user(user_id)
    
    update_social_graph(user_obj.access_token, user_obj.facebook_user)
    friends = get_friends_action(user_obj, exclude_self=True)
    
    return jsonify({"status": "ok",
                    "friends": sanify_friends(friends),
                    })