Пример #1
0
  def GET(self):
    
    form_input = get_input()
    action = form_input['button']
    svc, current_user, user_id = get_rdio_and_current_user()
    db = get_db()
    where_to_next = '/'
    
    if action == 'new_email':
      new_email = make_unique_email()
      db.update(USER_TABLE, where="rdio_user_id=%i" % user_id, address=new_email)
      where_to_next += 'config?saved=True'
    
    elif action == 'save':
      where_to_next += 'config?saved=True'
      preferences = get_db_prefs(user_id, db=db)
      new_preferences = get_preferences_from_input(form_input)
      preferences.update(new_preferences)
      db.update(USER_TABLE, where="rdio_user_id=%i" % user_id, prefs=BSONPostgresSerializer.from_dict(preferences))

      # circular import
      from discoversong.sources import SourceAppsManager
      for source_app in SourceAppsManager.ALL:
        for capability in source_app.capabilities:
          for configurable_thing in capability.config_options():
            if isinstance(configurable_thing, ConfigStoredValue):
              new_value = configurable_thing.read_from_input(form_input)
              if not configurable_thing.store_as_db_field:
                preferences = get_db_prefs(user_id, db=db)
                preferences[configurable_thing.name] = new_value
                db.update(USER_TABLE, where="rdio_user_id=%i" % user_id, prefs=BSONPostgresSerializer.from_dict(preferences))
              else:
                db.update(USER_TABLE, where="rdio_user_id=%i" % user_id, **{configurable_thing.name: new_value})

    raise web.seeother(where_to_next)
Пример #2
0
 def POST(self):
   db = get_db()
   
   form_input = get_input()
   
   envelope = json.loads(form_input['envelope'])
   to_addresses = envelope['to']
   
   for to_address in to_addresses:
     
     lookup = db.select(USER_TABLE, where="address='%s'" % to_address)
     
     if len(lookup) == 1:
       result = lookup[0]
       
       access_token = str(result['token'])
       access_token_secret = str(result['secret'])
       
       rdio, current_user, user_id = get_rdio_and_current_user(access_token=access_token, access_token_secret=access_token_secret)
       
       stats.got_email(user_id)
       
       subject = form_input['subject']
       body = form_input['text']
       
       try:
         title, artist = parse(subject, body)
       except Exception as e:
         logging.exception(e.message)
         return None
       
       search_results = well_formed_search(rdio, user_id, artist, title)
       return_results(rdio, user_id, search_results)
   
   return None
Пример #3
0
  def GET(self):
    
    rdio, current_user, user_id = get_rdio_and_current_user()
    
    if rdio and current_user:
      if user_id in config.ADMIN_USERS:
        form_input = get_input()
        
        if 'button' in form_input.keys():
          action = form_input['button']
          db = get_db()
          
          if action == 'doitnow_go_on_killme':
            if user_id in config.ADMIN_USERS:
              db.delete(USER_TABLE, where="rdio_user_id=%i" % user_id)
            raise web.seeother('/')

          elif action == 'clear_preferences':
            if user_id in config.ADMIN_USERS:
              db.update(USER_TABLE, where="rdio_user_id=%i" % user_id, prefs=BSONPostgresSerializer.from_dict({}))
          
            raise web.seeother('/admin')
        
        else:
          content=get_admin_content()
          db = get_db()
          users = db.select(USER_TABLE, what='rdio_user_id, last_use')
          users = dict([('s%s' % u['rdio_user_id'], u['last_use']) for u in users])
          rdio_users = rdio.call('get', {'keys': ','.join(users.keys()), 'extras': '-*,username,url'})['result']
          user_list = [(u['username'], u['url'], users[uid]) for uid, u in rdio_users.items()]
          user_list.sort(key=lambda x: x[2], reverse=True)
          return render.admin(env_message=get_environment_message(), admin=content, users=user_list)
      
    raise web.seeother('/')
Пример #4
0
  def GET(self):
    
    rdio, currentUser, user_id = get_rdio_and_current_user()
    
    if rdio and currentUser:
      if user_id in config.ADMIN_USERS:
        input = get_input()
        
        if 'button' in input.keys():
          action = input['button']
          db = get_db()
          
          if action == 'doitnow_go_on_killme':
            if user_id in config.ADMIN_USERS:
              db.delete(USER_TABLE, where="rdio_user_id=%i" % user_id)
            raise web.seeother('/')

          elif action == 'clear_preferences':
            if user_id in config.ADMIN_USERS:
              db.update(USER_TABLE, where="rdio_user_id=%i" % user_id, prefs=BSONPostgresSerializer.from_dict({}))
          
            raise web.seeother('/admin')
        
        else:
          admin=get_admin_content()
          return render.admin(env_message=get_environment_message(), admin=admin)
      
    raise web.seeother('/')
Пример #5
0
  def POST(self):
    form_input = get_input()
    username, password = get_credentials()
    nest = Nest(username, password)
    try:
      nest.login()
    except HTTPError:
      raise web.seeother(get_path('/logout'))
    for button_name, button_value in form_input.items():
      button_parts = button_name.split(':')
      action = button_parts[0]
      structure_id = button_parts[1]
      device_id = button_parts[2] if len(button_parts) > 2 else None
      if action == 'homeaway':
        nest.toggle_away(structure_id=structure_id)
      elif action == 'fan_toggle':
        nest.toggle_fan(structure_id=structure_id, device_id=device_id)
      elif 'target' in action:
        delta = 0.5
        if button_value == '-':
          delta *= -1

        nest.change_temperature(structure_id, device_id, delta=delta, target_type=action)

    raise web.seeother(get_path('/'))
Пример #6
0
  def POST(self):
    five_years = 60 * 60 * 24 * 365 * 5
    form_input = get_input()
    username = form_input["username"]
    password = form_input["password"]
    credentials = str({1: username, 2: password})
    key, iv = get_encryption_parts()
    cipher = AES.new(key, AES.MODE_CFB, iv)
    message = iv + cipher.encrypt(credentials)

    web.setcookie('credentials', message, expires=five_years)
    raise web.seeother(get_path('/'))
Пример #7
0
 def GET(self):
   # get the state from cookies and the query string
   request_token = web.cookies().get('rt')
   request_token_secret = web.cookies().get('rts')
   verifier = get_input()['oauth_verifier']
   # make sure we have everything we need
   if request_token and request_token_secret and verifier:
     # exchange the verifier and request token for an access token
     rdio = get_rdio_with_access(request_token, request_token_secret)
     rdio.complete_authentication(verifier)
     # save the access token in cookies (and discard the request token)
     web.setcookie('at', rdio.token[0], expires=60*60*24*14) # expires in two weeks
     web.setcookie('ats', rdio.token[1], expires=60*60*24*14) # expires in two weeks
     web.setcookie('rt', '', expires=-1)
     web.setcookie('rts', '', expires=-1)
     # go to the home page
     raise web.seeother('/')
   else:
     # we're missing something important
     raise web.seeother('/logout')