diff --git a/flash_auth_app/project/auth.py b/flash_auth_app/project/auth.py index 94d602b..db5ff21 100644 --- a/flash_auth_app/project/auth.py +++ b/flash_auth_app/project/auth.py @@ -1,4 +1,4 @@ -from flask import Blueprint, render_template, redirect, url_for, request +from flask import Blueprint, render_template, redirect, url_for, request, flash from werkzeug.security import generate_password_hash, check_password_hash from .models import User from . import db @@ -18,6 +18,21 @@ def login(): # return render_template('login.html') return 'Login' # placeholder +@auth.route('/login', methods=['POST']) +def login_post(): + email = request.form.get('email') + password = request.form.get('password') + remember = True if request.form.get('remember') else False + + user = User.query.filter_by(email=email).first() + + # check if the user actually exists, and compare password given + if not user or not check_password_hash(user.password, password): + flash('Please check your login details and try again.') + return redirect(url_for('auth.login')) + + return redirect(url_for('main.profile')) + @auth.route('/signup') def signup(): @@ -34,6 +49,7 @@ def signup_post(): user = User.query.filter_by(email=email).first() # Check if the email exists if user: # redirect back to sign-up page + flash('Email address already exists') return(redirect(url_for('auth.signup'))) # Create new user with form data diff --git a/templates/base.html b/flash_auth_app/project/templates/base.html similarity index 100% rename from templates/base.html rename to flash_auth_app/project/templates/base.html diff --git a/templates/index.html b/flash_auth_app/project/templates/index.html similarity index 100% rename from templates/index.html rename to flash_auth_app/project/templates/index.html diff --git a/flash_auth_app/project/templates/login.html b/flash_auth_app/project/templates/login.html new file mode 100644 index 0000000..e69de29 diff --git a/flash_auth_app/project/templates/profile.html b/flash_auth_app/project/templates/profile.html new file mode 100644 index 0000000..e69de29 diff --git a/flash_auth_app/project/templates/signup.html b/flash_auth_app/project/templates/signup.html new file mode 100644 index 0000000..e69de29