def GET(self,provider): if provider!="sina": return "todo" code=web.input().get("code") client = APIClient(app_key=APP_KEY, app_secret=APP_SECRET, redirect_uri=CALLBACK_URL) r = client.request_access_token(code) access_token = r.access_token expires_in = r.expires_in client.set_access_token(access_token, expires_in) uid =r.uid weibouser=client.get.users__show(uid=uid) sinaid=weibouser.get("id") authbind=Auth_bind.objects(opid="sina"+str(sinaid)).first() if authbind==None: avatar_large=weibouser.get("avatar_large") avatar=weibouser.get("profile_image_url") username=weibouser.get("screen_name") username=username+"21223" #?????? I ID=User.objects.count() + 101 u=User(username=username,email="!!sina2"+str(sinaid),password="",ID=ID) u.avatar=avatar u.avatar_big=avatar_large u.save() a=Auth_bind(ID=ID,opid="sina"+str(sinaid),access_token=access_token,expires_in=str(expires_in)) a.save() Auth.set_login(u.id,username.encode("utf-8")) return web.seeother("/") else: ID=authbind.ID user=User.objects(ID=ID).first() Auth.set_login(user.id,user.username.encode("utf-8")) return web.seeother("/")
def GET(self,provider): if provider!="sina": return u"todo" client = APIClient(app_key=APP_KEY, app_secret=APP_SECRET, redirect_uri=CALLBACK_URL) url = client.get_authorize_url() content=u'<h1>功能测试中</h1><p>请联系我们开通您的微博登录功能.</p><a href="%s">继续</a>'%url return render.info(content=content)