diff options
author | deepsource-autofix[bot] <62050782+deepsource-autofix[bot]@users.noreply.github.com> | 2021-06-06 10:11:00 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-06-06 10:11:00 +0000 |
commit | 6595d53212eaa4b9319da7196f5e2286d30eb462 (patch) | |
tree | 6fb829110658369321bab897707132f76f9b1b2c /app/views | |
parent | 57207efe38174666d40964b74856537c6f5314ab (diff) |
Format code with black
This commit fixes the style issues introduced in 57207ef according to the output
from black.
Details: https://deepsource.io/gh/navanchauhan/SaaS-in-a-Flask/transform/fb582430-1f1f-45bb-8c05-5f5bec16f981/
Diffstat (limited to 'app/views')
-rw-r--r-- | app/views/admin.py | 6 | ||||
-rw-r--r-- | app/views/auth.py | 77 | ||||
-rw-r--r-- | app/views/error_pages.py | 25 | ||||
-rw-r--r-- | app/views/main.py | 17 |
4 files changed, 86 insertions, 39 deletions
diff --git a/app/views/admin.py b/app/views/admin.py index b971a1a..7891e50 100644 --- a/app/views/admin.py +++ b/app/views/admin.py @@ -1,5 +1,5 @@ from app import app, login_manager, db -from flask import render_template, flash,url_for, redirect +from flask import render_template, flash, url_for, redirect import flask_login from app.models import User @@ -8,6 +8,7 @@ from flask_admin.contrib.sqla import ModelView admin = Admin(app, name="Admin", template_mode="bootstrap4") + class ModelView(ModelView): def is_accessible(self): try: @@ -17,4 +18,5 @@ class ModelView(ModelView): except AttributeError: return False -admin.add_view(ModelView(User, db.session))
\ No newline at end of file + +admin.add_view(ModelView(User, db.session)) diff --git a/app/views/auth.py b/app/views/auth.py index d6f02b8..2833479 100644 --- a/app/views/auth.py +++ b/app/views/auth.py @@ -1,6 +1,6 @@ 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, request +from app.forms.app_forms import UserSignUp, UserLogIn +from flask import render_template, flash, url_for, redirect, request from app.misc_func import flash_errors, send, send_async import flask_login from sqlalchemy.exc import IntegrityError @@ -9,10 +9,11 @@ from itsdangerous.exc import BadSignature ts = URLSafeSerializer(app.config["SECRET_KEY"]) -@app.route("/signup", methods=['GET', 'POST']) + +@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")) + return redirect(url_for("user_dashboard")) form = UserSignUp() if form.validate_on_submit(): form.email.data = form.email.data.lower() @@ -22,31 +23,38 @@ def register_user(): email=form.email.data, confirmation=False, password=form.password.data, - ) + ) db.session.add(user) try: db.session.commit() except IntegrityError: flash("Oops! An account with that email already exists") - return render_template("auth/signup.html",form=form) - + return render_template("auth/signup.html", form=form) + subject = "Confirm Your Email" - confirmation_token = ts.dumps(user.email,salt="email-confirm-key") - confirmation_url = url_for("confirm_email",confirmation_token=confirmation_token,_external=True) - body_html = render_template("misc/email_confirm.html",confirmation_url=confirmation_url) - body = render_template("misc/email_confirm.txt",confirmation_url=confirmation_url) + confirmation_token = ts.dumps(user.email, salt="email-confirm-key") + confirmation_url = url_for( + "confirm_email", confirmation_token=confirmation_token, _external=True + ) + body_html = render_template( + "misc/email_confirm.html", confirmation_url=confirmation_url + ) + body = render_template( + "misc/email_confirm.txt", confirmation_url=confirmation_url + ) send(user.email, subject, body, body_html) - + flash("Please confirm your email before signing in..") return redirect(url_for("signin_user")) flash_errors(form) - return render_template("auth/signup.html",form=form) + return render_template("auth/signup.html", form=form) -@app.route("/signin", methods=['GET', 'POST']) + +@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")) + return redirect(url_for("user_dashboard")) form = UserLogIn() if form.validate_on_submit(): form.email.data = form.email.data.lower() @@ -66,7 +74,8 @@ def signin_user(): flash("Incorrect Email") else: flash_errors(form) - return render_template("auth/signin.html",form=form) + return render_template("auth/signin.html", form=form) + @app.route("/login/with/google") def login_with_google(): @@ -85,7 +94,8 @@ def login_with_google_auth(): last_name=g_user["family_name"], email=g_user["email"].lower(), confirmation=True, - login_type="google") + login_type="google", + ) db.session.add(user) try: db.session.commit() @@ -98,7 +108,9 @@ def login_with_google_auth(): flask_login.login_user(user) return redirect(url_for("user_dashboard")) else: - flash("An account already exists for this email. Please use your password to log in.") + flash( + "An account already exists for this email. Please use your password to log in." + ) return redirect(url_for("signin_user")) else: return render_template( @@ -106,15 +118,18 @@ def login_with_google_auth(): message="To use sign-in with Google, you need a verified e-mail.", ) -@app.route("/confirm", methods=["GET","POST"]) + +@app.route("/confirm", methods=["GET", "POST"]) def confirm_email(): confirmation_token = request.args.get("confirmation_token") try: - email = ts.loads(confirmation_token, salt="email-confirm-key",max_age=86400) + email = ts.loads(confirmation_token, salt="email-confirm-key", max_age=86400) except TypeError: - return render_template("message.html",message="Token not provided in URL Parameter") + return render_template( + "message.html", message="Token not provided in URL Parameter" + ) except BadSignature: - return render_template("message.html",message="Bad Token Provided") + return render_template("message.html", message="Bad Token Provided") user = models.User.query.filter_by(email=email).first() print(email) user.confirmation = True @@ -122,16 +137,26 @@ def confirm_email(): flash("Email Has Been Succesfully Verified, You May Log In") return redirect(url_for("signin_user")) + @app.route("/dashboard") @flask_login.login_required def user_dashboard(): - return render_template("dashboard.html",user=flask_login.current_user) + return render_template("dashboard.html", user=flask_login.current_user) + -@app.route('/logout') +@app.route("/logout") def logout(): flask_login.logout_user() - return render_template("message.html",message="You have been logged out.") + return render_template("message.html", message="You have been logged out.") + @login_manager.unauthorized_handler def unauthorized(): - return render_template("message.html",message="You need to be logged in to access this resource", code=401), 401 + return ( + render_template( + "message.html", + message="You need to be logged in to access this resource", + code=401, + ), + 401, + ) diff --git a/app/views/error_pages.py b/app/views/error_pages.py index 5d995fc..1f066cc 100644 --- a/app/views/error_pages.py +++ b/app/views/error_pages.py @@ -1,18 +1,35 @@ from app import app from flask import render_template + @app.route("/Simulate500") def simulate_500(): - return 500 + return 500 + @app.errorhandler(403) def page_forbidden(e): - return render_template("message.html",code=403,message="Forbidden. You shall not pass"), 403 + return ( + render_template( + "message.html", code=403, message="Forbidden. You shall not pass" + ), + 403, + ) + @app.errorhandler(404) def page_not_found(e): - return render_template('message.html',code=404,message="Whoops! Page Not Found"), 404 + return ( + render_template("message.html", code=404, message="Whoops! Page Not Found"), + 404, + ) + @app.errorhandler(500) def page_server_error(e): - return render_template("message.html",code=500,message="Server Could Not Process This."), 500
\ No newline at end of file + return ( + render_template( + "message.html", code=500, message="Server Could Not Process This." + ), + 500, + ) diff --git a/app/views/main.py b/app/views/main.py index 003a46f..85df723 100644 --- a/app/views/main.py +++ b/app/views/main.py @@ -3,17 +3,20 @@ from app.forms.app_forms import MyForm from flask import render_template, flash from app.views import auth, error_pages, admin from app.misc_func import flash_errors + theme = "original" + @app.route("/") @app.route("/index") def index(): - return render_template("index.html") + return render_template("index.html") + -@app.route("/ContactUs", methods=['GET', 'POST']) +@app.route("/ContactUs", methods=["GET", "POST"]) def contact_us(): - form = MyForm() - if form.validate_on_submit(): - return "Wuhu" - flash_errors(form) - return render_template("contact.html",form=form)
\ No newline at end of file + form = MyForm() + if form.validate_on_submit(): + return "Wuhu" + flash_errors(form) + return render_template("contact.html", form=form) |