# Path: lib/userdb.py
# def get_all():
# def get_user_by_id_str(id_str):
# def get_user_by_screen_name(screen_name):
# def get_user_by_email(email_address):
# def get_disqus_users():
# def get_newsletter_recipients():
# def create_new_user(user, access_token):
# def save_user(user):
# def get_user_count():
# def add_tags_to_user(screen_name, tags=[]):
# def update_twitter(id_str=None, api=None):
# def update_twitter_profile_images():


import tweepy
import app.basic
import settings
from lib import userdb
        redirect = self.get_argument('next', '/')
        self.set_secure_cookie("twitter_auth_redirect", redirect)
        self.redirect(auth_url)

##############################
### RESPONSE FROM TWITTER AUTH
### /twitter
##############################
class Twitter(app.basic.BaseHandler):
    def get(self):
        oauth_verifier = self.get_argument('oauth_verifier', '')
        consumer_key = settings.get('twitter_consumer_key')
        consumer_secret = settings.get('twitter_consumer_secret')
        auth = tweepy.OAuthHandler(consumer_key, consumer_secret, secure=True)
        auth.set_request_token(self.get_secure_cookie('request_token_key'), self.get_secure_cookie('request_token_secret'))
        auth.get_access_token(oauth_verifier)
        screen_name = auth.get_username()
        bounce_to = self.get_secure_cookie('twitter_auth_redirect') or '/'

        access_token = {
          'secret': auth.access_token.secret,
          'user_id': '',
          'screen_name': '',
          'key': auth.access_token.key
        }

        # check if we have this user already or not in the system
        user = userdb.get_user_by_screen_name(screen_name)
        if user:
            # set the cookies based on account details

# Path: lib/userdb.py
# def get_all():
# def get_user_by_id_str(id_str):
# def get_user_by_screen_name(screen_name):
# def get_user_by_email(email_address):
# def get_disqus_users():
# def get_newsletter_recipients():
# def create_new_user(user, access_token):
# def save_user(user):
# def get_user_count():
# def add_tags_to_user(screen_name, tags=[]):
# def update_twitter(id_str=None, api=None):
# def update_twitter_profile_images():


# Path: app/twitter.py
import tweepy
import app.basic
import settings
from lib import userdb

        redirect = self.get_argument('next', '/')
        self.set_secure_cookie("twitter_auth_redirect", redirect)
        self.redirect(auth_url)

##############################
### RESPONSE FROM TWITTER AUTH
### /twitter
##############################
class Twitter(app.basic.BaseHandler):
    def get(self):
        oauth_verifier = self.get_argument('oauth_verifier', '')
        consumer_key = settings.get('twitter_consumer_key')
        consumer_secret = settings.get('twitter_consumer_secret')
        auth = tweepy.OAuthHandler(consumer_key, consumer_secret, secure=True)
        auth.set_request_token(self.get_secure_cookie('request_token_key'), self.get_secure_cookie('request_token_secret'))
        auth.get_access_token(oauth_verifier)
        screen_name = auth.get_username()
        bounce_to = self.get_secure_cookie('twitter_auth_redirect') or '/'

        access_token = {
          'secret': auth.access_token.secret,
          'user_id': '',
          'screen_name': '',
          'key': auth.access_token.key
        }

        # check if we have this user already or not in the system
        user = userdb.get_user_by_screen_name(screen_name)
        if user:
            # set the cookies based on account details

            self.set_secure_cookie("user_id_str", user['user']['id_str'])