예제 #1
0
파일: godutch.py 프로젝트: hirish/checkdown
def get_user():
    "Returns currently logged in user, registering a new user if necessary"
    user = get_logged_in_user()
    if not 'facebook_user_details' in g:
        abort(403)
    if not user:
        fb_code = g.facebook_user_details['code']
        fb_access_token = facebook.get_access_token_from_code(
            fb_code,
            '',
            app_id,
            app_key
        )['access_token']

        graph = facebook.GraphAPI(fb_access_token)
        fb_details = graph.get_object('me')

        username = fb_details['name']
        email = fb_details['email']
        facebook_id = g.facebook_user_details['user_id']

        user = User(username, email, facebook_id)
        db.session.add(user)
        db.session.commit()

    return jsonify(user = user.dictify())
예제 #2
0
파일: views.py 프로젝트: ko/sandbox-flask
def user_add():
    username = request.json.get('username')
    password = request.json.get('password')

    if username is None or password is None:
        abort(400)
    if User.query.filter_by(app_username = username).first() is not None:
        abort(400)

    user = User(app_username = username)
    user.hash_pass(password)

    db.session.add(user)
    db.session.commit()

    g.user = user

    return jsonify(user.dictify())
예제 #3
0
def login():
    args = request.json


    access_token = args['accessToken']
    fb_id = args['fbId']
    
    if not fb_user_is_valid(fb_id, access_token):
        return jsonify({'message': 'access_token invalid'}), 403
    
    user = get_user_by_fbid(fb_id)

    if not user:
        user = User(fb_id=fb_id, access_token=access_token,
                fullname=args['fullName'], image_link=args['imageLink'])

        db.session.add(user)
        db.session.commit()
    
    if login_user(user, remember=True):
        session.permanent = True
        return jsonify(user.dictify())
    
    return jsonify({'message': 'could not log in'}), 400