diff options
author | Navan Chauhan <navanchauhan@gmail.com> | 2021-06-04 00:31:44 +0530 |
---|---|---|
committer | Navan Chauhan <navanchauhan@gmail.com> | 2021-06-04 00:31:44 +0530 |
commit | 1944f9d65dfe2fe566d669c265cf4cd0d03ccf8d (patch) | |
tree | bb83c823c38c26ce5d6636ec6616d8023c72fa45 /app/views | |
parent | 25fc36cd50392f998b779606895af7326b650a93 (diff) |
added error handling signin/signout
Diffstat (limited to 'app/views')
-rw-r--r-- | app/views/auth.py | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/app/views/auth.py b/app/views/auth.py index 6ae6ef9..a915cf4 100644 --- a/app/views/auth.py +++ b/app/views/auth.py @@ -3,6 +3,7 @@ from app.forms.app_forms import UserSignUp, UserLogIn from flask import render_template, flash,url_for, redirect from app.misc_func import flash_errors import flask_login +from sqlalchemy.exc import IntegrityError @app.route("/signup", methods=['GET', 'POST']) @@ -17,7 +18,10 @@ def register_user(): password=form.password.data, ) db.session.add(user) - db.session.commit() + try: + db.session.commit() + except IntegrityError: + flash("Oops! An account with that email already exists") flash_errors(form) return render_template("auth/signup.html",form=form) @@ -30,10 +34,20 @@ def signin_user(): if user.check_password(form.password.data): flask_login.login_user(user) return redirect(url_for("user_dashboard")) - flash_errors(form) + else: + flash("Incorrect Password") + else: + flash("Incorrect Email") + else: + flash_errors(form) return render_template("auth/signin.html",form=form) @flask_login.login_required @app.route("/dashboard") def user_dashboard(): return render_template("dashboard.html",user=flask_login.current_user) + +@app.route('/logout') +def logout(): + flask_login.logout_user() + return 'Logged out' |