From f8b29478f5481b39225d77b630049f759a572ce7 Mon Sep 17 00:00:00 2001 From: Navan Chauhan Date: Sat, 5 Jun 2021 17:45:41 +0530 Subject: added redirects if already logged in --- app/tests/test_views.py | 8 ++++++++ app/views/auth.py | 6 +++++- 2 files changed, 13 insertions(+), 1 deletion(-) (limited to 'app') 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() -- cgit v1.2.3