def get(self): """Send user to tweet voting""" (user_name, real_name, oauth_secret, oauth_token) = \ self.handle_callback(self.request) try: SQUser.all().filter("user_name = ", user_name)[0] except IndexError: return self.redirect('/register/not_registered') self.session = Session() self.session['user_name'] = user_name return self.redirect('/vote/1/')
def post(self, result): """POST request""" user_name = cgi.escape(self.request.get('user_name')) if user_name == '' or not len(user_name): self.redirect('/register/incomplete') else: # If user doesn't already exist, create basic account to be # completed in the callback if not len(SQUser.all().filter('user_name = ', user_name).fetch(1)): user = SQUser(oauth_secret='secret', oauth_token='token', user_name=user_name, real_name='real') user.put() # oauth dance, which ends up at the callback url client = oauth.TwitterClient(CONSUMER_KEY, CONSUMER_SECRET, REGISTER_CALLBACK_URL) return self.redirect(client.get_authorization_url())
def get_logged_in_user(self): """Get logged in user (SQUser)""" if self.debug_mode(): try: return SQUser.all().filter('user_name = ', 'durden20').fetch(1)[0] except IndexError: return None try: user_name = self.session['user_name'] except KeyError: return None try: return SQUser.all().filter('user_name = ', user_name).fetch(1)[0] except IndexError: return None
def get(self): """Complete oauth with Twitter and save users tokens for future use""" (user_name, real_name, oauth_secret, oauth_token) = \ self.handle_callback(self.request) try: user = SQUser.all().filter("user_name = ", user_name)[0] except IndexError: return self.redirect('/register/not_registered') user.real_name = real_name user.oauth_secret = oauth_secret user.oauth_token = oauth_token user.put() return self.redirect('/register/success')