diff options
author | Navan Chauhan <navanchauhan@gmail.com> | 2021-06-05 17:45:41 +0530 |
---|---|---|
committer | Navan Chauhan <navanchauhan@gmail.com> | 2021-06-05 17:45:41 +0530 |
commit | f8b29478f5481b39225d77b630049f759a572ce7 (patch) | |
tree | b48371e1474406aae821a16204f2d2eca2c7b390 /app | |
parent | e5f50733e63c2f5bef34e966aaa4c881d71a1688 (diff) |
added redirects if already logged in
Diffstat (limited to 'app')
-rw-r--r-- | app/tests/test_views.py | 8 | ||||
-rw-r--r-- | app/views/auth.py | 6 |
2 files changed, 13 insertions, 1 deletions
diff --git a/app/tests/test_views.py b/app/tests/test_views.py index f4ae4d8..dbf8cb5 100644 --- a/app/tests/test_views.py +++ b/app/tests/test_views.py @@ -59,6 +59,14 @@ def test_user_auth_flow(app, client): assert res.status_code == 200 assert b"Hi John" in res.data + res = client.get("/signin",follow_redirects=True) + assert res.status_code == 200 + assert b"Hi John" in res.data + + res = client.get("/signup",follow_redirects=True) + assert res.status_code == 200 + assert b"Hi John" in res.data + res = client.get("/admin/user/") assert res.status_code == 403 diff --git a/app/views/auth.py b/app/views/auth.py index 983380e..487ae9b 100644 --- a/app/views/auth.py +++ b/app/views/auth.py @@ -1,12 +1,14 @@ from app import app, db, models, login_manager, oauth from app.forms.app_forms import UserSignUp, UserLogIn -from flask import render_template, flash,url_for, redirect +from flask import render_template, flash,url_for, redirect, request from app.misc_func import flash_errors import flask_login from sqlalchemy.exc import IntegrityError @app.route("/signup", methods=['GET', 'POST']) def register_user(): + if request.method == "GET" and flask_login.current_user.is_authenticated: + return redirect(url_for("user_dashboard")) form = UserSignUp() if form.validate_on_submit(): user = models.User( @@ -29,6 +31,8 @@ def register_user(): @app.route("/signin", methods=['GET', 'POST']) def signin_user(): + if request.method == "GET" and flask_login.current_user.is_authenticated: + return redirect(url_for("user_dashboard")) form = UserLogIn() if form.validate_on_submit(): user = models.User.query.filter_by(email=form.email.data).first() |