Example #1
0
def user():
    # If the user isn't authenticated through Google, redirect to landing page
    user = users.get_current_user()
    if not user:
        return redirect("/")
    elif getProfile(user):
        return redirect(url_for('dashboard'))

    form = forms.CreateUserForm(UserName=user.nickname(), EmailAddress=user.email(), HomeTown=user.user_id())
    if request.method == 'POST' and form.validate():

        q = UserProfile.all()
        q.filter("UserName", form.UserName.data)
        existingProfile = q.get()
        # TODO: Make sure username doesn't exist!

        # Create the new profile for the user and save it
        newProfile = UserProfile(key_name = form.UserName.data, UserID = user.user_id())
        newProfile.UserName = form.UserName.data
        newProfile.EmailAddress = form.EmailAddress.data
        newProfile.FullName = form.FullName.data
        newProfile.HomeTown = form.HomeTown.data         
        newProfile.put()
               
        # Store the profile in the session and head to the dashboard
        session["userProfile"] = newProfile
        return redirect(url_for('dashboard'))

    return render_template('views/createUser.html', form = form)
Example #2
0
def getProfile(user):
    if user:
        if "userProfile" not in session:
            # See if user has a profile
            q = UserProfile.all()
            q.filter("UserID", user.user_id())
            session["userProfile"] = q.get()
        return session["userProfile"]
    return None
Example #3
0
def createInitialUser(user):
    profile = UserProfile(UserID = user.user_id())
    profile.UserName = user.nickname()
    profile.EmailAddress = user.email()
    return profile