コード例 #1
0
ファイル: routes.py プロジェクト: kaushikdivya/list_app
def users():
    if 'access_token' in session:
        access_token = session.get('access_token', None)
        db = connect_db ()
        try:
            user_info = auth.authenticate_using_access_token(access_token, db)
            user_id = user_info['id']
            list_of_lists = dm.list_of_list(user_id, db)
        except AccessTokenExpiredError:
            flash("Access Token Expired. Login again")
            return render_template(url_for('login'))
        except InvalidAccessTokenError:
            flash("In Valid Access Token. Login again")
            return render_template(url_for('login'))
        except NoListFoundError:
            flash("No List Created yet.")
            return render_template(url_for('users', user_id = user_id )) #need to check this. as it seems it go in infinite iteration when no list is added by user.


        print type(user_info)
        if request.method == 'GET':
            print  user_info
            response = make_response(render_template('user_home.html', user_info = user_info, lists = list_of_lists, access_token = access_token))
            return no_cache(response)
    else:

        return redirect(url_for('login'))
コード例 #2
0
ファイル: api.py プロジェクト: kaushikdivya/list_app
def lists():

    query_access_token = request.args.get('access_token')
    db = connect_db ()
    try:
        user_info = auth.authenticate_using_access_token(query_access_token, db)
        user_id = user_info['id']
    except AccessTokenExpiredError:
        response_data = {
            "meta" : {},
            "data" : {
                "users" : [{
                    "authentication" : 'Expired',
                    "message" : "Access token Expired"
                }]
            }
        }
        status = 401
        body = json.dumps(response_data)
        headers = {
            'Content-Type' : 'application/json'
        }
        return (body, status, headers)
    except InvalidAccessTokenError:
        response_data = {
            "meta" : {},
            "data" : {
                "users" : [
                    {
                        "message" : "Invalid access token : %s" % (query_access_token)
                    }
                ]
            }
        }
        status = 400
        body = json.dumps(response_data)
        headers = {
            'Content-Type' : 'application/json'
        }
        return (body, status, headers)
    #All list under that user
    if request.method == 'GET':
        try:
            list_of_lists = dm.list_of_list(user_id, db)
            print list_of_lists
        except NoListFoundError:
            response_data = {
                "meta" : {},
                "data" : {
                    "lists" : [{
                        "message" : "No List found of this user"
                    }]
                }
            }
            body = json.dumps(response_data)
            status = 200
            headers = {
                "Content-Type" : 'application/json'
            }
            return (body,status,headers)
        response_data = {
            "meta" : {},
            "data" : {
                "users" : user_info,
                "lists" : list_of_lists
            }
        }
        body = json.dumps(response_data)
        status = 200
        headers = {
            "Content-Type" : 'application/json'
        }
        return (body,status,headers)
    else:
        # Add new list(how to handle request data)
        data = request.json['data']
        list_name = data['lists'][0]['name']
        list_info = list(dm.create_new_list(list_name, user_id, db))
        response_data = {
            "meta" : {},
            "data" : {
                "lists" : list_info
            }
        }
        body = json.dumps(response_data)
        status = 200
        headers = {
            "Content-Type" : 'application/json'
        }
        return (body,status,headers)