def render_autopass_puzzle(puzzle): # get passphrase that was submitted with this request, if any: submitted = request.args.get('pass') # get current user's passphrase: profile = UserProfile.get_by_user(request.remote_addr) # see if they submitted the correct one: if submitted and (submitted == profile.current_passphrase): profile.solved_puzzles.append('autopass/' + puzzle) profile.put() value = 'correct! ' value += progress('autopass/' + puzzle) return value # fallthrough logic - incorrect or no passphrase submitted: # TODO: add extra output on pass submitted, but incorrect? # (but then it'd be outside of the manual HTML structure) # generate a new passphrase: passphrase = 'default' with app.open_resource('data/passphrases.json') as f: passphrases = json.load(f) passphrase = random.choice(passphrases) # store it in user's profile: profile.current_passphrase = passphrase profile.put() return render_template('autopass/' + puzzle, passphrase=passphrase)
def progress(curr): profile = UserProfile.get_by_user(request.remote_addr) nextp = nextPuzzle(curr) if nextp: profile.current_puzzle = nextp # this is probably fine. profile.put() return '<a href="/' + nextp + '">Next puzzle!</a>' else: # no next puzzle return 'All done!'
def nextStep(): print request.remote_addr profile = UserProfile.get_by_user(request.remote_addr) print profile return redirect(profile.current_puzzle)