def get(self, douban_id, template_name='templates/authdouban/delete_account.html'): user = users.get_current_user() account = DoubanAccount.get_authenticated_accounts(user, douban_id) context = { 'douban_id': douban_id, 'douban_account': account, } return render_to_response(self, template_name, context)
def get(self): service = douban_service() key, secret = service.client.get_request_token() user = users.get_current_user() new_account = DoubanAccount.create_unauthorized_account(user, key, secret) callback_url = 'http://%s/account/douban/authorize/complete/' % self.request.host auth_url = service.client.get_authorization_url(key, secret, callback_url) return self.redirect(auth_url)
def get(self, template_name='templates/authdouban/complete.html'): request_key = self.request.get('oauth_token') account = DoubanAccount.all().filter('request_key = ', request_key).get() if not account or account.request_key == 'ALREADY_AUTHENTICATED': reason = urllib.quote_plus('Request Key 不正确') return self.redirect('/account/douban/authorize/failure/?reason=%s' % reason) service = douban_service() key, secret, douban_id = service.client.get_access_token(account.request_key, account.request_secret) if key and secret and douban_id: account.set_access_key(key, secret, douban_id) account.remove_duplicate_accounts() account.remove_old_accounts() if settings.STORE_DOUBAN_PROFILE: entry = service.GetPeople('/people/%s' % douban_id) profile = DoubanProfile.insert_or_update(entry) return render_to_response(self, template_name, { 'douban_account': account }) else: reason = urllib.quote_plus('获取 Access Key 失败') return self.redirect('/account/douban/authorize/failure/?reason=%s' % reason)
def get(self, template_name='templates/authdouban/list_account.html'): user = users.get_current_user() accounts = DoubanAccount.get_authenticated_accounts(user=user) return render_to_response(self, template_name, { 'douban_accounts': accounts })
def post(self, douban_id): user = users.get_current_user() account = DoubanAccount.get_authenticated_accounts(user, douban_id) account.delete() return self.redirect('/account/douban/')