def render_autopass_puzzle(puzzle): # get current user's profile: profile = UserProfile.get_by_user(users.get_current_user()) # get passphrase that was submitted with this request, if any: submitted = request.args.get('pass') # if they submitted the correct passphrase: if submitted and (submitted == profile.current_passphrase): # use the current puzzle's path to record the puzzle completion, and return the generated message: return userCompletedPuzzle(request.path) # The following will only happen when the previous "if" was false, and so we did not return "correct" # In other words, from here, we can assume that the correct password was NOT submitted. # generate a new passphrase: passphrase = 'default' # temporary default passphrase, just in case loading one from file fails. 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 userCompletedPuzzle(puzzle): # get the user's profile, and record that they've solved this puzzle: profile = UserProfile.get_by_user(users.get_current_user()) profile.solved_puzzles.append(puzzle) message = 'correct! ' # start composing the message displayed to the user. nextPuzzle = getNextPuzzle( puzzle ) # use the current puzzle's path to get the puzzle that should be next. if nextPuzzle: # if there is a next puzzle, then link to it message += '<a href=' + nextPuzzle + '>Next puzzle!</a>' # also, change the user's current puzzle to nextPuzzle: profile.current_puzzle = nextPuzzle else: # if there is not a next puzzle, tell the user they are all done message += 'All done!' profile.put() # commit all the changes we've made to the user profile return message
def logEvent(): profile = UserProfile.get_by_user(users.get_current_user()) profile.log_action(url=request.form["path"], action=request.form["action"], data=request.form["data"]) return "logged"
def log_request(): # get the user's profile entry from the database (or create one if this user is new to our database) profile = UserProfile.get_by_user(users.get_current_user()) # log the visited URL (request.full_path) in the user's profile. profile.log_action(url=request.path, action="pageload")
def renderPage(page): return render_template('site-specific/' + page, profile=UserProfile.get_by_user( users.get_current_user()))
def select(gamename): return render_template('/selectGames/' + gamename + '.html', profile=UserProfile.get_by_user( users.get_current_user()))
def hello(): return render_template('hello.html', profile=UserProfile.get_by_user( users.get_current_user()))
def nextStep(): profile = UserProfile.get_by_user(users.get_current_user()) return redirect(profile.current_puzzle)