def post(self, *a): with locks.global_lock: session = auth.load_session(self.get_cookie('session_id')) path = self.request.path path_parts = list(filter(lambda s: s != '', path.split('/'))) if len(path_parts) != 2: self.write( json.dumps({ 'success': False, 'error_message': lc.get('invalid_api_call') })) return api_function = path_parts[-1] try: api.handle(api_function, session=session, args={'http_handler': self}) except ApiKeyError: self.write( json.dumps({ 'success': False, 'error_message': lc.get('no_such_api_function') })) return except BaseException as e: self.write( json.dumps({ 'success': False, 'error_message': lc.get(str(e)) })) logger.error('Exception occured while serving an API call: {}', repr(e)) print_exc() return
def get(self): with locks.global_lock: session_id = self.get_cookie('session_id') session = auth.load_session(session_id) if session is None: self.redirect('/login') return target_team_name = self.get_argument('team', None) if target_team_name is None: self.clear() self.set_status(404) self.finish( render_template('team_profile_404.html', session=session)) return try: target_team = team.read_team(target_team_name) except BaseException: self.clear() self.set_status(404) self.finish( render_template('team_profile_404.html', session=session)) return self.write( render_template('team_profile.html', session=session, team=target_team, tasks_module=tasks))
def main(): parser = argparse.ArgumentParser(description="Updates the posts in the dest Tumblr blog using the posts from the src. Assumes that posts in the src and dest blog have the same slug.") parser.add_argument("--keyfile", required=True, help="The JSON file which contains the Tumblr OAuth app key and secret key") parser.add_argument("--src", required=True, help="The name of the blog to get posts from") parser.add_argument("--dest", required=True, help="The name of the blog to update") parser.add_argument("--session", default=DEFAULT_SESSION_FILE, help="The file used to cache the session information") options = parser.parse_args() api_keys = {} with open(options.keyfile) as keyfile: api_keys = json.load(keyfile) if not api_keys: print "Error: No API keys found..." print "Exiting..." return api_key = api_keys.get("key") api_secret_key = api_keys.get("secret_key") if api_key is None: print "Error: API key not found in file: %s" % options.keyfile print "Exiting..." return if api_secret_key is None: print "Error: API secret key not found in file: %s" % options.keyfile print "Exiting..." return session = load_session(session_filename=options.session, key=api_key, secret_key=api_secret_key) src_posts = export_posts(session=session, api_key=api_key, blog_name=options.src) dest_posts = export_posts(session=session, api_key=api_key, blog_name=options.dest) edit_posts(session=session, dest_blog_name=options.dest, src_posts=src_posts, dest_posts=dest_posts)
def get(self): with locks.global_lock: session_id = self.get_cookie('session_id') if auth.load_session(session_id) is not None: self.redirect('/') return self.write(render_template('login.html'))
def main(): parser = argparse.ArgumentParser(description="Copies posts from one Tumblr blog to another") parser.add_argument("--keyfile", required=True, help="The JSON file which contains the Tumblr OAuth app key and secret key") parser.add_argument("--src", required=True, help="The name of the blog to copy data from") parser.add_argument("--dest", required=True, help="The name of the blog to copy data to") parser.add_argument("--session", default=DEFAULT_SESSION_FILE, help="The file used to cache the session information") options = parser.parse_args() api_keys = {} with open(options.keyfile) as keyfile: api_keys = json.load(keyfile) if not api_keys: print "Error: No API keys found..." print "Exiting..." return api_key = api_keys.get("key") api_secret_key = api_keys.get("secret_key") if api_key is None: print "Error: API key not found in file: %s" % options.keyfile print "Exiting..." return if api_secret_key is None: print "Error: API secret key not found in file: %s" % options.keyfile print "Exiting..." return session = load_session(session_filename=options.session, key=api_key, secret_key=api_secret_key) posts = export_posts(session=session, api_key=api_key, blog_name=options.src) import_posts(session=session, blog_name=options.dest, posts=posts)
def get(self): with locks.global_lock: session_id = self.get_cookie('session_id') session = auth.load_session(session_id) if session is None: self.redirect('/login') return self.write(render_template('change_password.html', session=session))
def get(self): with locks.global_lock: session_id = self.get_cookie('session_id') if auth.load_session(session_id) is None: self.write( render_template('auth_error.html', error=lc.get('logout_no_session'))) return auth.logout(session_id) self.clear_cookie('session_id') self.redirect('/')
def get(self): with locks.global_lock: session_id = self.get_cookie('session_id') session = auth.load_session(session_id) if session is None or not session.is_admin: self.write( render_template('admin_error.html', error=lc.get('not_admin'))) return self.write(render_template('admin_new_team.html', session=session))
def get(self): with locks.global_lock: session_id = self.get_cookie('session_id') if auth.load_session(session_id) is not None: self.redirect('/') return if not competition.allow_team_self_registration: self.write( render_template('reg_error.html', error=lc.get('registration_disabled'))) return self.write(render_template('register.html'))
def equipLoadout(): id = request.form.get("loadoutid") oauth_session = auth.load_session(session['access_token']) loadout = models.Loadout.query.filter_by(id=id).first() try: destiny.equipLoadout(oauth_session, session['membershipType'], session['destinyMembershipId'], loadout) except destiny.DestinyException as e: #TODO trace this error Finding process can Transfer or NotFound or a Equip (locked) may not catch inners flash(str(e), 'danger') #finally: # flash('Loadout Equipped', 'message') return redirect(url_for('dashboard'))
def get(self): with locks.global_lock: session_id = self.get_cookie('session_id') session = auth.load_session(session_id) current_team = team.read_team(session.username) if session is None: self.redirect('/login') return self.write( render_template('edit_team_info.html', session=session, team=current_team))
def get(self): with locks.global_lock: session_id = self.get_cookie('session_id') session = auth.load_session(session_id) if session is None: self.redirect('/login') return team_list = list(team.get_all_teams()) task_list = list(tasks.get_task_list()) self.write( render_template('scoreboard.html', session=session, team_list=team_list, task_list=task_list))
def builder(): charid = request.form.get("charid") classname = request.form.get("classname") oauth_session = auth.load_session(session['access_token']) # Same session Storage as character WAY faster if stored, but lacks new items if 'inventory' not in session: inventory = destiny.buildInventory(oauth_session, session['membershipType'], session['destinyMembershipId']) session['inventory'] = inventory.toJSON() else: x = json.loads(session['inventory'].strip('\'')) inventory = destiny.Inventory(**x) flash('Inventory Loaded', 'info') if classname == "Hunter": return render_template( 'builder.html', characterId=charid, primaryWeapons=inventory.kinetic, secondaryWeapons=inventory.energy, heavyWeapons=inventory.power, helmetArmor=inventory.hunterArmor['HelmetArmor'], armsArmor=inventory.hunterArmor["ArmsArmor"], chestArmor=inventory.hunterArmor["ChestArmor"], legArmor=inventory.hunterArmor["LegArmor"], classArmor=inventory.hunterArmor["ClassArmor"]) if classname == "Warlock": return render_template( 'builder.html', characterId=charid, primaryWeapons=inventory.kinetic, secondaryWeapons=inventory.energy, heavyWeapons=inventory.power, helmetArmor=inventory.warlockArmor['HelmetArmor'], armsArmor=inventory.warlockArmor["ArmsArmor"], chestArmor=inventory.warlockArmor["ChestArmor"], legArmor=inventory.warlockArmor["LegArmor"], classArmor=inventory.warlockArmor["ClassArmor"]) if classname == "Titan": return render_template('builder.html', characterId=charid, primaryWeapons=inventory.kinetic, secondaryWeapons=inventory.energy, heavyWeapons=inventory.power, helmetArmor=inventory.titanArmor['HelmetArmor'], armsArmor=inventory.titanArmor["ArmsArmor"], chestArmor=inventory.titanArmor["ChestArmor"], legArmor=inventory.titanArmor["LegArmor"], classArmor=inventory.titanArmor["ClassArmor"])
def post(self): with locks.global_lock: session_id = self.get_cookie('session_id') session = auth.load_session(session_id) if session is None: self.redirect('/login') return old_password = self.get_argument('old_password', None) password = self.get_argument('password', None) password_c = self.get_argument('password_c', None) if old_password is None or old_password == '': self.write( render_template( 'change_password_error.html', error_message=lc.get('no_old_password'), session=session, )) return if not auth.verify_password(session.username, old_password): self.write( render_template( 'change_password_error.html', error_message=lc.get('invalid_old_password'), session=session, )) return if password is None or password == '': self.write( render_template( 'change_password_error.html', error_message=lc.get('no_password'), session=session, )) return if password != password_c: self.write( render_template( 'change_password_error.html', error_message=lc.get('password_c_failed'), session=session, )) return auth.update_password(session.username, password) self.write( render_template('change_password_ok.html', session=session))
def charselect(): oauth_session = auth.load_session(session['access_token']) chars = [] # Storing data in Session helps with subsequent load times. if "characterIds" not in session: res = destiny.getProfile(oauth_session, session['membershipType'], session['destinyMembershipId'], destiny.COMPONENTS['Profiles']) session["characterIds"] = res['profile']['data']['characterIds'] if "characters" not in session: chars = destiny.getCharacterInfo(oauth_session, session['membershipType'], session['destinyMembershipId'], session['characterIds']) session["characters"] = chars.toJSON() if not isinstance(chars, destiny.CharacterList): chars = destiny.CharacterList( json.loads(session["characters"])["chars"]) return render_template('charselect.html', characters=chars.chars)
def get(self): with locks.global_lock: session_id = self.get_cookie('session_id') session = auth.load_session(session_id) if session is None: self.redirect('/login') return task_list = list( task_gen.get_generated_task_list(team_name=session.username)) current_team = team.read_team(session.username) hint_purchases = tasks.get_hint_puchases_for_team(session.username) self.write( render_template( 'tasks.html', session=session, tasks=task_list, team=current_team, hint_purchases=hint_purchases, get_token=task_gen.get_token.__get__(session.username), ))
def get(self): with locks.global_lock: session = auth.load_session(self.get_cookie('session_id')) submissions = team.get_all_submissions() if session is None or not session.is_admin: self.write( render_template('admin_error.html', error=lc.get('not_admin'))) return self.write( render_template( 'admin.html', session=session, tasks=list(tasks.get_task_list()), submissions=list(submissions), teams=list(team.get_all_teams()), groups=dict(tasks.get_group_dict()), read_task=tasks.read_task, build_group_path=tasks.build_group_path, task_gen=task_gen, ))
def get(self, _): with locks.global_lock: session_id = self.get_cookie('session_id') session = auth.load_session(session_id) if session is None: raise tornado.web.HTTPError(403) task_id = self.get_argument('task', None) if task_id is None: raise tornado.web.HTTPError(418) try: task_id = int(task_id) except (ValueError, TypeError) as e: raise tornado.web.HTTPError(404) try: tasks.read_task(task_id) except tasks.TaskNotFoundError: raise tornado.web.HTTPError(404) filename = self.get_argument('file', None) if filename is None: raise tornado.web.HTTPError(404) try: filepath = tasks.get_attachment(task_id=task_id, team_name=session.username, filename=filename) except tasks.AttachmentNotFoundError: raise tornado.web.HTTPError(404) # End lock with open(filepath, 'rb') as f: self.set_header('Content-Type', 'application/octet-stream') while True: data = f.read(64 * 1024) if len(data) == 0: break self.write(data) self.finish()
def main(): parser = argparse.ArgumentParser(description="Deletes all of the posts for the given Tumblr account") parser.add_argument("--keyfile", required=True, help="The JSON file which contains the Tumblr OAuth app key and secret key") parser.add_argument("--blog", required=True, help="The name of the blog delete posts for") parser.add_argument("--session", default=DEFAULT_SESSION_FILE, help="The file used to cache the session information") options = parser.parse_args() api_keys = {} with open(options.keyfile) as keyfile: api_keys = json.load(keyfile) if not api_keys: print "Error: No API keys found..." print "Exiting..." return api_key = api_keys.get("key") api_secret_key = api_keys.get("secret_key") if api_key is None: print "Error: API key not found in file: %s" % options.keyfile print "Exiting..." return if api_secret_key is None: print "Error: API secret key not found in file: %s" % options.keyfile print "Exiting..." return print "About to delete all posts for: %s" % options.blog response = raw_input("Are you sure you want to continue? [y/n]") if response[0].lower() != "y": print "Exiting..." return session = load_session(session_filename=options.session, key=api_key, secret_key=api_secret_key) delete_posts(session=session, api_key=api_key, blog_name=options.blog)
def post(self): with locks.global_lock: session_id = self.get_cookie('session_id') session = auth.load_session(session_id) if session is None: self.redirect('/login') return disp_name = self.get_argument('disp_name', None) email = self.get_argument('email', None) if disp_name is None or disp_name == '': self.write( render_template( 'edit_team_info_error.html', error_message=lc.get('no_disp_name'), session=session, )) return tm = team.read_team(session.username) tm.full_name = disp_name tm.email = email if email != '' else None team.write_team(tm) self.write( render_template('edit_team_info_ok.html', session=session))
def post(self): with locks.global_lock: session_id = self.get_cookie('session_id') session = auth.load_session(session_id) if session is None or not session.is_admin: self.write( render_template('admin_error.html', error=lc.get('not_admin'))) return username = self.get_argument('username', None) password = self.get_argument('password', None) password_c = self.get_argument('password-c', None) disp_name = self.get_argument('disp-name', None) email = self.get_argument('email', None) is_admin = self.get_argument('is_admin', None) if is_admin is not None and is_admin not in ['on', 'off']: self.write( render_template( 'reg_error.html', error=lc.get('api_invalid_data_type').format( param='is_admin', expected=lc.get('bool'), ))) return if is_admin == 'on': is_admin = True else: is_admin = False if username is None or username == '': self.write( render_template('reg_error.html', error=lc.get('no_username'))) return if password is None or password == '': self.write( render_template('reg_error.html', error=lc.get('no_password'))) return if disp_name is None or disp_name == '': self.write( render_template('reg_error.html', error=lc.get('no_disp_name'))) return if password != password_c: self.write( render_template('reg_error.html', error=lc.get('password_c_failed'))) return if username in auth.get_user_list(): self.write( render_template('reg_error.html', error=lc.get('user_already_exists'))) return try: auth.register_user( username=username, password=password, disp_name=disp_name, email=email, is_admin=is_admin, ) except auth.BaseRegistrationError as e: self.write( render_template('reg_error.html', error=lc.get(e.text))) return self.redirect('/admin')
def get(self): with locks.global_lock: self.write( render_template('index.html', session=auth.load_session( self.get_cookie('session_id'))))