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"))
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"))
def make_new_user(): email = request.form.get("email") age = request.form.get("age") zipcode = request.form.get("zipcode") password = request.form.get("password") verify_password = request.form.get("password_verify") if password != verify_password: flash("Passwords do not match") return redirect(url_for("register")) if model.userExists(email): flash("Account already exists for user email") return redirect(url_for("register")) model.make_new_user(email, password, age, zipcode) flash("You've successfully made an account!") return redirect(url_for("index"))