Ejemplo n.º 1
0
def callback_facebook(resp):
    if resp is None:
        return 'Access denied: reason=%s error=%s' % (request.args['error_reason'],request.args['error_description'])
    me = auth.facebook.get('/me')

    user = Usuario.query.filter_by(nickname=me.data['name']).first()
    if user is None:
        user = Usuario(me.data['name'],'')
        user.nickname = me.data['name']
        db.session.add(user)
    user.oauth_token = resp['access_token']
    db.session.commit()

    session['user_id'] = user.id
    g.user = user
    #return 'Logged in as id=%s name=%s redirect=%s' % (me.data['id'], me.data['name'], request.args.get('next'))
    return redirect(url_for('home'))
Ejemplo n.º 2
0
def callback_facebook(resp):
    if resp is None:
        return error_login(
            "Access denied: reason=%s error=%s" % (request.args["error_reason"], request.args["error_description"])
        )

    user_tmp = Usuario()
    user_tmp.oauth_token = resp["access_token"]
    g.user = user_tmp

    me = auth.facebook.get("/me")
    user = Usuario.query.filter(Usuario.nickname == me.data["name"]).filter(Usuario.email == me.data["email"]).first()

    if user is None:
        user = Usuario()
        user.email = me.data["email"]
        user.oauth_provider = "facebook"
        user.nickname = me.data["name"]
        db.session.add(user)
    user.oauth_token = resp["access_token"]
    db.session.commit()

    session["user_id"] = user.id
    session["oauth_provider"] = user.oauth_provider
    g.user = user
    return redirect(url_for("home"))
Ejemplo n.º 3
0
def callback_facebook(resp):
    if resp is None:
        return 'Access denied: reason=%s error=%s' % (
            request.args['error_reason'], request.args['error_description'])
    me = auth.facebook.get('/me')

    user = Usuario.query.filter_by(nickname=me.data['name']).first()
    if user is None:
        user = Usuario(me.data['name'], '')
        user.nickname = me.data['name']
        db.session.add(user)
    user.oauth_token = resp['access_token']
    db.session.commit()

    session['user_id'] = user.id
    g.user = user
    #return 'Logged in as id=%s name=%s redirect=%s' % (me.data['id'], me.data['name'], request.args.get('next'))
    return redirect(url_for('home'))
Ejemplo n.º 4
0
def callback_twitter(resp):
    next_url = request.args.get('next') or url_for('home')
    if resp is None:
        flash(u'You denied the request to sign in.')
        return redirect(next_url)

    user = Usuario.query.filter_by(nickname=resp['screen_name']).first()

    if user is None:
        user = Usuario(resp['screen_name'],'')
        user.nickname = resp['screen_name']
        db.session.add(user)

    user.oauth_token = resp['oauth_token']
    user.oauth_token_secret = resp['oauth_token_secret']
    db.session.commit()

    session['user_id'] = user.id
    g.user = user
    flash('You were signed in')
    return redirect(next_url)
Ejemplo n.º 5
0
def callback_twitter(resp):
    next_url = request.args.get('next') or url_for('home')
    if resp is None:
        flash(u'You denied the request to sign in.')
        return redirect(next_url)

    user = Usuario.query.filter_by(nickname=resp['screen_name']).first()

    if user is None:
        user = Usuario(resp['screen_name'], '')
        user.nickname = resp['screen_name']
        db.session.add(user)

    user.oauth_token = resp['oauth_token']
    user.oauth_token_secret = resp['oauth_token_secret']
    db.session.commit()

    session['user_id'] = user.id
    g.user = user
    flash('You were signed in')
    return redirect(next_url)
Ejemplo n.º 6
0
def callback_twitter(resp):
    next_url = request.args.get("next") or url_for("home")
    if resp is None:
        error_login(u"You denied the request to sign in.")
        return redirect(next_url)

    user = Usuario.query.filter_by(nickname=resp["screen_name"]).first()

    if user is None:
        user = Usuario()
        user.nickname = resp["screen_name"]
        user.oauth_provider = "twitter"
        db.session.add(user)

    user.oauth_token = resp["oauth_token"]
    user.oauth_token_secret = resp["oauth_token_secret"]

    db.session.commit()

    session["user_id"] = user.id
    session["oauth_provider"] = user.oauth_provider
    g.user = user

    return redirect(url_for("home"))