def GET(self, oauth_type): code = self.argument('code') if oauth_type in OAUTH_TYPE.keys(): CALLBACK_URL = 'http://ldev.cn/callback/%s' % oauth_type key, secret = OAUTH2_CONFIG[oauth_type] APIClient = globals()['%s_client' % oauth_type] client = APIClient(app_key=key, app_secret=secret, redirect_uri=CALLBACK_URL) r = client.request_access_token(code) if oauth_type == 'weibo': r = JsDict(r) access_token = r.access_token # 新浪返回的token expires_in = r.expires_in # token过期的UNIX时间: oauth_uid = r.uid if oauth_type == 'weibo' else r.user.id uid = oauth2_new(oauth_type=oauth_type, oauth_id=oauth_uid,\ token=r.access_token, expires_in=r.expires_in, refresh_token=r.refresh_token) client.set_access_token(access_token, expires_in) if oauth_type == 'weibo': info = client.users.show.get(uid=r.uid) profile_new(uid, name = info['screen_name'], motto = info['description'], avatar = info['avatar_large'], gender = GENDER_DICT.get(info['gender'], 0)) else: info = r#client.api_call('users.getInfo') profile_new(uid, name = info['name'], avatar = r.user.avatar[-1]['url']) self.login(uid) self.redirect('/me')
def account_new(email, passwd, name): email = email.lower() if uid_by_email(email): return uid = uid_new() email_save(uid, email) passwd_save(uid, passwd) profile_new(uid, name=name) return uid