''' Created on Nov 19, 2011 @author: zhuhua ''' import app import oauth import tornado from common import flash from oauth.funcs import check_login @app.route('^/oauth/sina') class SinaOAuthHandler(app.BaseHandler, oauth.SinaMixin): @tornado.web.asynchronous def get(self): if self.get_argument("oauth_token", None): self.get_authenticated_user(self.async_callback(self._on_auth)) return self.authorize_redirect(callback_uri='/oauth/sina') def _on_auth(self, user): if not user: raise tornado.web.HTTPError(500, "Sina auth failed") check_login(self, user, 'sina') @app.route('^/oauth/qq') class QQOAuthHandler(app.BaseHandler, oauth.QQMixin): @tornado.web.asynchronous def get(self): if self.get_argument("oauth_token", None): self.get_authenticated_user(self.async_callback(self._on_auth)) return self.authorize_redirect(callback_uri='/oauth/qq') def _on_auth(self, user): if not user: raise tornado.web.HTTPError(500, "QQ auth failed") check_login(self, user, 'qq') @app.route('^/oauth/163') class NeteaseOAuthHandler(app.BaseHandler, oauth.NeteaseMixin): @tornado.web.asynchronous def get(self): if self.get_argument("oauth_token", None): self.get_authenticated_user(self.async_callback(self._on_auth)) return self.authorize_redirect(callback_uri='/oauth/163') def _on_auth(self, user): if not user: raise tornado.web.HTTPError(500, "163 auth failed") check_login(self, user, '163') @app.route('^/oauth/sohu') class SohuOAuthHandler(app.BaseHandler, oauth.SohuMixin): @tornado.web.asynchronous def get(self): if self.get_argument("oauth_token", None): self.get_authenticated_user(self.async_callback(self._on_auth)) return self.authorize_redirect(callback_uri='/oauth/sohu') def _on_auth(self, user): if not user: raise tornado.web.HTTPError(500, "Sohu auth failed") check_login(self, user, 'sohu')