Exemple #1
0
 def get(self, screen_name):
   if self.current_user in settings.get('staff'):
     user = userdb.get_user_by_screen_name(screen_name)
     if user:
       user['user']['is_blacklisted'] = False
       userdb.save_user(user)
   self.redirect('/')
Exemple #2
0
  def get(self):
    code = self.get_argument('code','')
    req_host = self.request.headers['host']
    api_key = settings.get('disqus_public_key')
    api_secret = settings.get('disqus_secret_key')

    link = 'https://disqus.com/api/oauth/2.0/access_token/'
    data = {
      'grant_type':'authorization_code',
      'client_id':api_key,
      'client_secret':api_secret,
      'redirect_uri': 'http://%s/disqus' % req_host,
      'code' : code
    }
    try:
      account = userdb.get_user_by_screen_name(self.current_user)
      if account:
        response = urllib2.urlopen(link, urllib.urlencode(data))
        #  access_token should look like access_token=111122828977539|98f28d8b5b8ed787b585e69b.1-537252399|1bKwe6ghzXyS9vPDyeB9b1fHLRc
        user_data = json.loads(response.read())
        # refresh the user token details
        account['disqus_username'] = user_data['username']
        account['disqus_user_id'] = user_data['user_id']
        account['disqus_access_token'] = user_data['access_token']
        account['disqus_expires_in'] = user_data['expires_in']
        account['disqus_refresh_token'] = user_data['refresh_token']
        account['disqus_token_type'] = user_data['token_type']
        userdb.save_user(account)
    except:
      # trouble logging in
      data = {}
    self.redirect('/your_account?section=social_accounts')
    def get(self):
        # remove twitter from this account
        account = userdb.get_user_by_screen_name(self.current_user)
        if account:
            del account['disqus']
            userdb.save_user(account)

        self.redirect('/user/%s/settings?msg=updated' % self.current_user)
 def post(self):
     user = userdb.get_user_by_id_str(self.get_argument('uid', ''))
     newRole = self.get_argument('role', '')
     if user:
         user['role'] = newRole
         userdb.save_user(user)
     self.set_secure_cookie('flash_success', "<strong>" + user['user']['username'] + "</strong> is now a <strong>" + newRole + "</strong>" )
     self.redirect('/admin/users')
 def get(self, username):
     if self.current_user_role() in settings.get('admin_roles'):
         user = userdb.get_user_by_screen_name(username)
         if user:
             user['user']['is_blacklisted'] = False
             userdb.save_user(user)
             self.set_secure_cookie('flash_success', "<strong>" + username + "</strong> was unbanned" )
     self.redirect('/admin/users')
    def get(self):
        # remove twitter from this account
        account = userdb.get_user_by_screen_name(self.current_user)
        if account:
            del account['disqus']
            userdb.save_user(account)

        self.redirect('/user/%s/settings?msg=updated' % self.current_user)
Exemple #7
0
  def post(self):
    next_page = self.get_argument('next', '')
    next_page += "&finished=true"
    close_popup = self.get_argument('close_popup', '')
    email = self.get_argument('email', '')
    subscribe_to = self.get_argument('subscribe_to', '')
    error = ''
    status = ''
    slug = ''
    if close_popup != '':
      status = 'close_popup'

    # get the current user's email value
    user = userdb.get_user_by_screen_name(self.current_user)
    if user:
      # Clear the existing email address
      if email == '':
        if subscribe_to == '':
          user['email_address'] = ''
          self.set_secure_cookie('email_address', '')
          userdb.save_user(user)
          error = 'Your email address has been cleared.'
      else:
        # make sure someone else isn't already using this email
        existing = userdb.get_user_by_email(email)
        if existing and existing['user']['id_str'] != user['user']['id_str']:
          error = 'This email address is already in use.'
        else:
          # OK to save as user's email
          user['email_address'] = email
          userdb.save_user(user)
          self.set_secure_cookie('email_address', email)

          if subscribe_to != '':
            post = postsdb.get_post_by_slug(subscribe_to)
            if post:
              slug = post['slug']
              
            # Attempt to create the post's thread
            thread_id = 0
            try:
              # Attempt to create the thread.
              thread_details = disqus.create_thread(post, user['disqus_access_token'])
              thread_id = thread_details['response']['id']
            except:
              try:
                # trouble creating the thread, try to just get the thread via the slug
                thread_details = disqus.get_thread_details(slug)
                thread_id = thread_details['response']['id']
              except:
                thread_id = 0

            if thread_id != 0:
              # Subscribe a user to the thread specified in response
              disqus.subscribe_to_thread(thread_id, user['disqus_access_token'])
    
    self.redirect("/user/%s/settings?msg=updated" % user['user']['screen_name'])
Exemple #8
0
  def get(self):
    # remove twitter from this account
    account = userdb.get_user_by_screen_name(self.current_user)
    if account:
      del account['disqus_username']
      del account['disqus_user_id']
      del account['disqus_access_token']
      del account['disqus_expires_in']
      del account['disqus_refresh_token']
      del account['disqus_token_type']
      userdb.save_user(account)

    self.redirect('/your_account?section=social_accounts')
Exemple #9
0
  def get(self):
    # remove twitter from this account
    account = userdb.get_user_by_screen_name(self.current_user)
    if account:
      del account['disqus_username']
      del account['disqus_user_id']
      del account['disqus_access_token']
      del account['disqus_expires_in']
      del account['disqus_refresh_token']
      del account['disqus_token_type']
      userdb.save_user(account)

    self.redirect('/user/%s/settings?msg=updated' % self.current_user)
    def get(self):
        code = self.get_argument('code', '')
        req_host = self.request.headers['host']
        api_key = settings.get('disqus_public_key')
        api_secret = settings.get('disqus_secret_key')

        link = 'https://disqus.com/api/oauth/2.0/access_token/'
        data = {
            'grant_type': 'authorization_code',
            'client_id': api_key,
            'client_secret': api_secret,
            'redirect_uri': 'http://%s/disqus' % req_host,
            'code': code
        }
        try:
            account = userdb.get_user_by_screen_name(self.current_user)
            if account:
                response = urllib2.urlopen(link, urllib.urlencode(data))
                #  access_token should look like access_token=111122828977539|98f28d8b5b8ed787b585e69b.1-537252399|1bKwe6ghzXyS9vPDyeB9b1fHLRc
                user_data = json.loads(response.read())
                # refresh the user token details
                disqus_obj = {}
                disqus_obj['username'] = user_data['username']
                disqus_obj['user_id'] = user_data['user_id']
                disqus_obj['access_token'] = user_data['access_token']
                disqus_obj['expires_in'] = user_data['expires_in']
                disqus_obj['refresh_token'] = user_data['refresh_token']
                disqus_obj['token_type'] = user_data['token_type']
                disqus_obj['token_startdate'] = datetime.now()
                account['disqus'] = disqus_obj
                if 'disqus_username' in account.keys():
                    del account['disqus_username']
                if 'disqus_user_id' in account.keys():
                    del account['disqus_user_id']
                if 'disqus_access_token' in account.keys():
                    del account['disqus_access_token']
                if 'disqus_expires_in' in account.keys():
                    del account['disqus_expires_in']
                if 'disqus_refresh_token' in account.keys():
                    del account['disqus_refresh_token']
                if 'disqus_token_type' in account.keys():
                    del account['disqus_token_type']
                userdb.save_user(account)

                # subscribe user to all previous threads they've written
                disqus.subscribe_to_all_your_threads(self.current_user)

        except Exception, e:
            logging.info(e)
            # trouble logging in
            data = {}
    def get(self):
        code = self.get_argument('code','')
        req_host = self.request.headers['host']
        api_key = settings.get('disqus_public_key')
        api_secret = settings.get('disqus_secret_key')

        link = 'https://disqus.com/api/oauth/2.0/access_token/'
        data = {
          'grant_type':'authorization_code',
          'client_id':api_key,
          'client_secret':api_secret,
          'redirect_uri': 'http://%s/disqus' % req_host,
          'code' : code
        }
        try:
            account = userdb.get_user_by_screen_name(self.current_user)
            if account:
                response = urllib2.urlopen(link, urllib.urlencode(data))
                #  access_token should look like access_token=111122828977539|98f28d8b5b8ed787b585e69b.1-537252399|1bKwe6ghzXyS9vPDyeB9b1fHLRc
                user_data = json.loads(response.read())
                # refresh the user token details
                disqus_obj = {}
                disqus_obj['username'] = user_data['username']
                disqus_obj['user_id'] = user_data['user_id']
                disqus_obj['access_token'] = user_data['access_token']
                disqus_obj['expires_in'] = user_data['expires_in']
                disqus_obj['refresh_token'] = user_data['refresh_token']
                disqus_obj['token_type'] = user_data['token_type']
                disqus_obj['token_startdate'] = datetime.now()
                account['disqus'] = disqus_obj
                if 'disqus_username' in account.keys(): del account['disqus_username']
                if 'disqus_user_id' in account.keys(): del account['disqus_user_id']
                if 'disqus_access_token' in account.keys(): del account['disqus_access_token']
                if 'disqus_expires_in' in account.keys(): del account['disqus_expires_in']
                if 'disqus_refresh_token' in account.keys(): del account['disqus_refresh_token']
                if 'disqus_token_type' in account.keys(): del account['disqus_token_type']
                userdb.save_user(account)

                # subscribe user to all previous threads they've written
                disqus.subscribe_to_all_your_threads(self.current_user)

        except Exception, e:
            logging.info(e)
            # trouble logging in
            data = {}
    def render(self, template, **kwargs):

        # add any variables we want available to all templates
        kwargs['user_obj'] = None
        kwargs['user_obj'] = userdb.get_user_by_screen_name(self.current_user)
        kwargs['current_user_can'] = self.current_user_can
        kwargs['settings'] = settings
        kwargs['body_location_class'] = ""
        kwargs['current_path'] = self.request.uri
        user_info = kwargs['user_obj']
        #kwargs['request_path'] = self.request
        if user_info and 'date_created' not in user_info.keys():
            user_info['date_created'] = datetime.now() - timedelta(days=180)
            userdb.save_user(user_info)
        if self.request.path == "/":
            kwargs['body_location_class'] = "home"

        super(BaseHandler, self).render(template, **kwargs)
    def render(self, template, **kwargs):

        # add any variables we want available to all templates
        kwargs['user_obj'] = None
        kwargs['user_obj'] = userdb.get_user_by_screen_name(self.current_user)
        kwargs['current_user_can'] = self.current_user_can
        kwargs['settings'] = settings
        kwargs['body_location_class'] = ""
        kwargs['current_path'] = self.request.uri
        user_info = kwargs['user_obj']
        #kwargs['request_path'] = self.request
        if user_info and 'date_created' not in user_info.keys():
            user_info['date_created'] = datetime.now() - timedelta(days=180)
            userdb.save_user(user_info)
        if self.request.path == "/":
            kwargs['body_location_class'] = "home"

        super(BaseHandler, self).render(template, **kwargs)
    def post(self):
        next_page = self.get_argument('next', '')
        next_page += "&finished=true"
        close_popup = self.get_argument('close_popup', '')
        email = self.get_argument('email', '')
        subscribe_to = self.get_argument('subscribe_to', '')
        error = ''
        status = ''
        slug = ''
        if close_popup != '':
            status = 'close_popup'

        # get the current user's email value
        user = userdb.get_user_by_screen_name(self.current_user)
        if user:
            # Clear the existing email address
            if email == '':
                if subscribe_to == '':
                    user['email_address'] = ''
                    self.set_secure_cookie('email_address', '')
                    userdb.save_user(user)
                    error = 'Your email address has been cleared.'
            else:
                # make sure someone else isn't already using this email
                existing = userdb.get_user_by_email(email)
                if existing and existing['user']['id_str'] != user['user'][
                        'id_str']:
                    error = 'This email address is already in use.'
                else:
                    # OK to save as user's email
                    user['email_address'] = email
                    userdb.save_user(user)
                    self.set_secure_cookie('email_address', email)

                    if subscribe_to != '':
                        post = postsdb.get_post_by_slug(subscribe_to)
                        if post:
                            slug = post['slug']

                        # Attempt to create the post's thread
                        thread_id = 0
                        try:
                            # Attempt to create the thread.
                            thread_details = disqus.create_thread(
                                post, user['disqus_access_token'])
                            thread_id = thread_details['response']['id']
                        except:
                            try:
                                # trouble creating the thread, try to just get the thread via the slug
                                thread_details = disqus.get_thread_details(
                                    post)
                                thread_id = thread_details['response']['id']
                            except:
                                thread_id = 0

                        if thread_id != 0:
                            # Subscribe a user to the thread specified in response
                            disqus.subscribe_to_thread(
                                thread_id, user['disqus_access_token'])

        #save email prefs
        user['wants_daily_email'] = self.get_argument('wants_daily_email',
                                                      False)
        if user['wants_daily_email'] == "on":
            user['wants_daily_email'] = True

        user['wants_email_alerts'] = self.get_argument('wants_email_alerts',
                                                       False)
        if user['wants_email_alerts'] == "on":
            user['wants_email_alerts'] = True

        userdb.save_user(user)

        self.redirect("/user/%s/settings?msg=updated" %
                      user['user']['screen_name'])
Exemple #15
0
import sys
try:
	sys.path.insert(0, '/Users/nick/dev/theconversation')
except:
	pass

from lib import userdb

users = userdb.get_all()

for user in users:
	user['email_address'] = ""
	user['disqus'] = {}
	user['access_token'] = {}
	userdb.save_user(user)
	print "saved user %s" % user['user']['username']
Exemple #16
0
import sys
try:
    sys.path.insert(0, '/Users/nick/dev/theconversation')
except:
    pass

from lib import userdb

users = userdb.get_all()

for user in users:
    user['email_address'] = ""
    user['disqus'] = {}
    user['access_token'] = {}
    userdb.save_user(user)
    print "saved user %s" % user['user']['username']