diff --git a/controllers/web/endpoints.py b/controllers/web/endpoints.py index f30035f..ff3f740 100644 --- a/controllers/web/endpoints.py +++ b/controllers/web/endpoints.py @@ -1,5 +1,5 @@ from . import blueprint -from flask import render_template, redirect, request, session +from flask import render_template, redirect, request, session, flash from controllers.database.user import UserController from models.users.customer import Customer from hashlib import sha512 @@ -15,8 +15,8 @@ def welcome_page(): ### LOGIN FUNCTIONALITY # Function responsible for delivering the Login page for the site @blueprint.route('/login') -def display_login(error: str = None): - return render_template('index.html', content="login.html", user = session.get('user'), error = error) +def display_login(): + return render_template('index.html', content="login.html", user = session.get('user')) # Function responsible for handling logins to the site @blueprint.post('/login') @@ -28,12 +28,14 @@ def login(): # No user found if user == None: error = "No user found with the username " + request.form['username'] - return display_login(error) + flash(error) + return redirect("/login") # Incorrect Password if sha512(request.form['password'].encode()).hexdigest() != user.password: error = "Incorrect Password" - return display_login(error) + flash(error) + return redirect("/login") session['user'] = user.username return redirect("/") @@ -42,8 +44,8 @@ def login(): ### SIGNUP FUNCTIONALITY # Function responsible for delivering the Signup page for the site @blueprint.route('/signup') -def display_signup(error: str = None): - return render_template('index.html', content="signup.html", user = session.get('user'), error = error) +def display_signup(): + return render_template('index.html', content="signup.html", user = session.get('user')) # Function responsible for handling signups to the site @blueprint.post('/signup') @@ -53,7 +55,8 @@ def signup(): # User already exists if database.read(request.form['username']) != None: error = "User, " + request.form['username'] + " already exists" - return display_signup(error) + flash(error) + return redirect("/signup") database.create(Customer( 0, diff --git a/templates/login.html b/templates/login.html index 53c398f..0ccfd74 100644 --- a/templates/login.html +++ b/templates/login.html @@ -5,16 +5,20 @@ - {% if error != None %} - - {% endif %} + {% with messages = get_flashed_messages()%} + {% if messages %} + {% for message in messages %} + + {% endfor%} + {% endif %} + {% endwith %}

Not a member? Create Account

diff --git a/templates/signup.html b/templates/signup.html index 425252f..93109f5 100644 --- a/templates/signup.html +++ b/templates/signup.html @@ -8,16 +8,20 @@ - {% if error != None %} - - {% endif %} + {% with messages = get_flashed_messages()%} + {% if messages %} + {% for message in messages %} + + {% endfor%} + {% endif %} + {% endwith %}

Already have an account? Login