Пример #1
0
def oauth():
    code = request.args.get('code')
    s = Service(ServiceType.WEIBO)

    if not code:
        auth_url = s.get_authorize_url()
        return redirect(auth_url)

    auth, r = s.init_token(code)
    uid = auth.account__get_uid().uid
    session['userid'] = uid
    session['token'] = r.access_token
    session['expires_in'] = r.expires_in

    #oauth = OAuth.get_by_ser_uid(uid)

    #if oauth:
        #session['userid'] = oauth.id
    #else:
        #oauth = OAuth()
        #oauth.ser_uid = uid
        #oauth.service = 'weibo'
        #oauth.save()
        #session['userid'] = oauth.id
    return redirect('/')