Exemple #1
0
def create_account():

    # get username, password and verify_password from form data
    username = request.form.get("username")
    password = request.form.get("password")
    verify_password = request.form.get("password_verify")

    # get user id from session, if it exists
    user_id = session.get("user_id")
    if user_id:
        # if the user is logged in, send them to their own wall
        username = model.get_name_by_user(user_id)
        return redirect(url_for("view_user",username=username)) 

    # if username is already in the database, flash error message and redirect to same page
    elif model.get_user_by_name(username) != None:
        flash("That username is taken, please try another")
        return redirect(url_for("register"))

    # if the passwords don't match, flash error message and redirect
    elif verify_password != password:
        flash("Your passwords didn't match")
        return redirect(url_for("register"))

    #check if password verify matches password
    else:
        # if they passed all those checks, create a new user in the database
        # and redirect to their own page
        model.make_new_user(username, password)

        # flashed messages are fetched using flask function in the jinja template
        # in HTML, call get_flashed_messages() to display
        flash("Your account has been created please login") 
        return redirect(url_for("index"))
Exemple #2
0
def create_account():

    # get username and password and verify_password from form data
    username= request.form.get("username")
    password= request.form.get("password")
    verify_password= request.form.get("password_verify")

    # get user id from session, if it exists
    user_id = session.get("user_id")
    if user_id:
        # if the user is logged in, send them to their own page
        username = model.get_name_by_user(user_id)
        return redirect(url_for("view_user",username=username )) 
    elif model.get_user_by_name(username) != None:
        # if username is already in the database, flash error message and redirect to same page
        flash("That username is taken, please try another")
        return redirect(url_for("register"))
    elif verify_password != password:
        # if the passwords don't match, flash error message and redirect
        flash("Your passwords didn't match")
        return redirect(url_for("register"))
    #check if password verify matches password
    else:
        # if they passed all those checks, create a new user in the database
        # and redirect to their own page
        model.make_new_user(username, password)
        # flashed messages are fetched using flask function in the jinja template
        # in HTML call get_flashed_messages() to display
        flash("Your account has been created please login") 
        return redirect(url_for("index"))
Exemple #3
0
def register():
    # if user is logged in, redirect to their wall
    # otherwise, else send to register.html
    user_id = session.get("user_id")
    if user_id:
        username = model.get_name_by_user(user_id)
        return redirect(url_for("view_user",username=username ))
    else:   
        return render_template("register.html")
Exemple #4
0
def index():
    """Handler for /. Redirects to login page if not logged in."""
    user_id = session.get("user_id")
    if session.get("user_id"):
        username = model.get_name_by_user(user_id)
        flash("Welcome %s" % username)
        return redirect(url_for("view_user",username=username ))
    else:
    #otherwise send user to login page    
        return render_template("index.html")
Exemple #5
0
def index():
    user_id = session.get("user_id")
    #check if the user is already logged in if so send them to their page
    if session.get("user_id"):
        username = model.get_name_by_user(user_id)
        flash("Welcome %s" % username)
        return redirect(url_for("view_user",username=username ))
    else:
    #otherwise send user to login page    
        return render_template("index.html")
Exemple #6
0
def register():
    #this get the user_id from session if it exists
    user_id = session.get("user_id")
    if user_id:
        #if you are logged in it redirects your to your own page
        username = model.get_name_by_user(user_id)
        return redirect(url_for("view_user",username=username ))
    else:   
    #if user is not logged it sends you to register page 
        return render_template("register.html")