Exemplo n.º 1
0
def before_request():
    g.user = None
    if 'oauth_token' in session:
        if 'user_id' in session:
            g.user = User.query.filter(User.id == session['user_id']).first()
            g.user.facebook_info = facebook.get('/me')
        else:
            redirect(url_for('general.logout'))
Exemplo n.º 2
0
def authorized(resp):
    if resp is None:
        return 'Access denied: reason=%s error=%s' % (
            request.args['error_reason'], request.args['error_description'])

    session['oauth_token'] = (resp['access_token'], '')
    me = facebook.get('/me')
    if 'oauth_token' in session and me.data['id']:
        user = User.query.filter(User.facebook_id == me.data['id']).first()
        if not user:
            user = User(me.data['id'])
            user.create()
        session['user_id'] = user.id
        user.facebook_update(facebook)
        user.save()
    else:
        return 'Shit. oauth token dead or facebook.me didnt work'
    flash('You\'ve logged in!')
    return redirect(url_for('general.index'))
Exemplo n.º 3
0
def authorized(resp):
    if resp is None:
        return 'Access denied: reason=%s error=%s' % (
            request.args['error_reason'],
            request.args['error_description']
        )
    
    session['oauth_token'] = (resp['access_token'], '')
    me = facebook.get('/me')
    if 'oauth_token' in session and me.data['id']:
        user = User.query.filter(User.facebook_id == me.data['id']).first()
        if not user:
            user = User(me.data['id'])
            user.create()
        session['user_id'] = user.id
        user.facebook_update(facebook)
        user.save()
    else:
        return 'Shit. oauth token dead or facebook.me didnt work'
    flash('You\'ve logged in!')
    return redirect(url_for('general.index'))