Exemple #1
0
 def get(self):
     self.response.out.write("00242beb80964cb2c1ed6bd3b7593944")
     u=UserAccessToken()
     u.qqSecret = '5846415b2c341c23e9154008025393f7'
     u.qqToken = '151df8254b824f0fb3bc48ed8f7d03c3'
     u.qqisright = True
     u.sinaExpires = '1522066881'
     u.sinaSecret = '2.00HGNhqCdb1iQBb8eed27af80MRd2r'
     u.sinaToken = '7860a0f91f4ddf79f4c0f019c7a5d866'
     u.sinaisright = True
     u.sinauserid = '2610933591'
     u.wyisright = True
     u.wySecret = '2d213529803ab28090f822b896b9b29e'
     u.wyToken = '1c63afb34efb5d7a424c9c9b44b335fe'
     u.put()
Exemple #2
0
  def get(self):
    website=self.request.get('website')
    userAccessToken=UserAccessToken().all().fetch(1)
    if userAccessToken:
        userAccessToken=userAccessToken[0]
    else:
        userAccessToken=UserAccessToken()
    if 'sina'==website:
        """用户成功登录授权后,会回调此方法,获取access_token,完成授权"""
        # http://mk2.com/?oauth_token=c30fa6d693ae9c23dd0982dae6a1c5f9&oauth_verifier=603896
#        verifier = self.request.get('oauth_verifier', None)
#        auth_client = _oauth()
#        # 设置之前保存在session的request_token
#    #    request_token = request.session['oauth_request_token']
#        request_token=memcache.Client().get(website+"_request_token1")
#        if not request_token:
#            return
#        memcache.Client().delete(website+"_request_token1")
#    #    del request.session['oauth_request_token']
#
#        auth_client.set_request_token(request_token.key, request_token.secret)
#        access_token = auth_client.get_access_token(verifier)
        code=self.request.get('code')
        logging.info('code:'+code)
        client = weibo.APIClient(webSetting.xlconsumer_key, webSetting.xlconsumer_secret,webSetting.WEIBOURL+'/Admin/login_check?website=sina')
        r = client.request_access_token(code)

        access_token, expires_in, uid = r.access_token, r.expires_in, r.uid
        client.set_access_token(access_token, expires_in)
        logging.info('access token: %s' % sysjson.dumps(access_token))
        u = client.users.show.get(uid=uid)
        # 保存access_token,以后访问只需使用access_token即可
        userAccessToken.sinaSecret=access_token
#        userAccessToken.sinaToken=access_token.key
        userAccessToken.sinaExpires=str(expires_in)
        userAccessToken.sinauserid=uid
        userAccessToken.sinaisright=True
        userAccessToken.put()
    elif 'wy'==website:
#        t = TBlog(weboSetting.wyconsumer_key, weboSetting.wyconsumer_secret)
        request_token=memcache.Client().get(website+"_request_token3")
        if not request_token:
            return
        memcache.Client().delete(website+"_request_token3")
#        t._request_handler.request_token=request_token
#        request_token.get_auth_url()
#        pin=self.request.get('pin', None)
        pin=self.request.get('oauth_token', None)
        s=request_token.get_access_token(pin)
        userAccessToken.wySecret=s.secret
        userAccessToken.wyToken=s.key
        userAccessToken.wyisright=True
        userAccessToken.put()
    elif 'teng'==website:
        request_token=memcache.Client().get(website+"_request_token4")
        if not request_token:
            return
        memcache.Client().delete(website+"_request_token4")
        verifier = self.request.get('oauth_verifier', None)
        access_token = request_token.get_access_token(verifier)
        userAccessToken.qqSecret=access_token.secret
        userAccessToken.qqToken=access_token.key
        #userAccessToken.qquserid=auth_client.user_id
        userAccessToken.qqisright=True
        userAccessToken.put()

    return self.redirect('/Admin')