diff --git a/app.py b/app.py index 89ab1c5..32c493b 100644 --- a/app.py +++ b/app.py @@ -1,11 +1,9 @@ from application import app from flask import redirect, url_for -from flask_login import login_required # type: ignore -# home route +# home route, place holder in case we want a home page @app.route("/") -@login_required def index(): return redirect(url_for("dash.index")) diff --git a/application/__init__.py b/application/__init__.py index d4cd08f..67c3339 100644 --- a/application/__init__.py +++ b/application/__init__.py @@ -20,9 +20,6 @@ db.init_app(app) migrate = Migrate(app, db) -# bp import -from application.auth.views import auth_blueprint -from application.dash.views import dash_blueprint # Login manager from application.auth.models import User @@ -32,6 +29,7 @@ login_manager.init_app(app) # type: ignore login_manager.login_view = "auth.login" # type: ignore +# Gets all the user data @login_manager.user_loader # type: ignore def load_user(user_id): # type: ignore return User.query.get(int(user_id)) # type: ignore @@ -39,5 +37,14 @@ def load_user(user_id): # type: ignore # Blueprint magic +# bp import +# Would like to do this at the top of the file, +# but can't easily figure out how to do this. +# I think everything that the views depend on have to be moved +# into a seperate .py and imported. +from application.auth.views import auth_blueprint +from application.dash.views import dash_blueprint + +# Register blueprints app.register_blueprint(dash_blueprint, url_prefix="/dash") app.register_blueprint(auth_blueprint, url_prefix="/auth") diff --git a/application/decorators.py b/application/decorators.py index 285930e..a56be7c 100644 --- a/application/decorators.py +++ b/application/decorators.py @@ -4,6 +4,9 @@ from functools import wraps from flask import redirect, url_for +# Decorator that checks if the current user is logged in and an admin +# Could be shortened by adding the login_required decorator +# and removing the logic here def admin_required(f: Callable[..., Any]) -> Callable[..., Any]: @wraps(f) def decorated_function(*args: ..., **kwargs: ...): diff --git a/application/utils.py b/application/utils.py index 9cbc656..55a63a9 100644 --- a/application/utils.py +++ b/application/utils.py @@ -1,17 +1,23 @@ -from werkzeug.utils import secure_filename import os +from werkzeug.utils import secure_filename from application import app from flask_login import current_user # type: ignore +# save image to static folder def saveImage(image: ...): filename = secure_filename(image.filename) + # Path should be /application/static/[user_id]/[filename] save_path = os.path.join( app.config["UPLOAD_FOLDER"], # type: ignore str(current_user.id), filename, ) + # Create path is it doesn't exist os.makedirs(os.path.dirname(save_path), exist_ok=True) + # Save the image image.save(save_path) # type: ignore - filename2 = str(current_user.id) + "/" + filename + # Return the filename that is stored in database. + # Only done to keep a single default image, this should be done differently + filename2 = str(current_user.id) + "/" + filename # [user_id]/[filename] return filename2 diff --git a/test/123123123.png b/test/123123123.png deleted file mode 100644 index dfef930..0000000 Binary files a/test/123123123.png and /dev/null differ