Beispiel #1
0
class TestUserProfile(unittest.TestCase):
    def setUp(self):
        self.userprofile = UserProfile('neha', '21', '01')

    def test_create_profile(self):
        self.userprofile.create_profile("hello this is neha")
        self.assertEqual(self.userprofile.info, "hello this is neha")
Beispiel #2
0
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)
Beispiel #3
0
def handle_signup():
    username = request.form.get("username")
    password = request.form.get("password")
    bio = request.form.get("bio")
    if username in userstore.list_existing_users():
        return render_template(
            "signup.html", auth=True, error="A user with that username already exists"
        )
    # TODO: make this transactional so that we don't have a user without a profile
    userstore.store_new_credentials(generate_creds(username, password))
    userstore.store_new_profile(UserProfile(username, bio, avatar_id=None))
    session["user"] = username
    return redirect("/")
Beispiel #4
0
def generate_avatar_url():
    """This endpoint expects 1. a filename and 2. a content type
    """
    user = get_user()
    if not user:
        abort(403)
    if not request.is_json:
        abort(404)
    filename = request.json["filename"]
    content_type = request.json["contentType"]
    bio = request.json["bio"]
    if not (filename and content_type):
        # One of the fields was missing in the JSON request
        abort(404)
    avatar_url = userstore.create_avatar_upload_url(filename, content_type)
    userstore.store_new_profile(UserProfile(user, bio=bio, avatar_id=filename))
    return jsonify({"signedUrl": avatar_url})
Beispiel #5
0
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
Beispiel #6
0
 def setUp(self):
     self.userprofile = UserProfile('neha', '21', '01')
Beispiel #7
0
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"
Beispiel #8
0
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")
Beispiel #9
0
def renderPage(page):
    return render_template('site-specific/' + page,
                           profile=UserProfile.get_by_user(
                               users.get_current_user()))
Beispiel #10
0
def select(gamename):
    return render_template('/selectGames/' + gamename + '.html',
                           profile=UserProfile.get_by_user(
                               users.get_current_user()))
Beispiel #11
0
def hello():
    return render_template('hello.html',
                           profile=UserProfile.get_by_user(
                               users.get_current_user()))
Beispiel #12
0
def nextStep():
    profile = UserProfile.get_by_user(users.get_current_user())
    return redirect(profile.current_puzzle)