From a0a5786a065c41b42503fce2d4c0119f0d551b5b Mon Sep 17 00:00:00 2001 From: danielmyren <daniel.j.myren@gmail.com> Date: Mon, 15 Apr 2024 00:21:52 +0200 Subject: [PATCH] minor changes, it's possible to start the server --- .gitignore | 3 ++- backend/__init__.py | 28 ++++++++++++++++++++-------- backend/auth.py | 4 ++-- backend/requirements.txt | 1 + 4 files changed, 25 insertions(+), 11 deletions(-) diff --git a/.gitignore b/.gitignore index f872588..7debeac 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ .DS_Store -/backend/venv \ No newline at end of file +/backend/venv +/backend/__pycache__/ \ No newline at end of file diff --git a/backend/__init__.py b/backend/__init__.py index 8b91d90..6657434 100644 --- a/backend/__init__.py +++ b/backend/__init__.py @@ -1,9 +1,11 @@ +import os from flask import Flask from flask_sqlalchemy import SQLAlchemy from flask_security import Security, SQLAlchemyUserDatastore, auth_required, hash_password from flask_security.models import fsqla_v3 as fsqla from flask_login import LoginManager + def create_app(): app = app = Flask(__name__) @@ -13,10 +15,10 @@ def create_app(): # Standard Configurations: # Register models - from .server import default as default_blueprint + from server import default as default_blueprint app.register_blueprint(default_blueprint) - from .auth import auth as auth_blueprint + from auth import auth as auth_blueprint app.register_blueprint(auth_blueprint) @@ -26,15 +28,14 @@ def create_app(): if app.config['DEBUG']: # Generate a nice key using secrets.token_urlsafe() - # Add app.config['SECRET_KEY'] = os.environ.get("SECRET_KEY", TODO) + app.config['SECRET_KEY'] = os.environ.get("SECRET_KEY", "FaHW65b6vBDGlhazs-8JZHb4jiZvI_9jj6hcUa_EV1Q") # Bcrypt is set as default SECURITY_PASSWORD_HASH, which requires a salt # Generate a good salt using: secrets.SystemRandom().getrandbits(128) - #app.config['SECURITY_PASSWORD_SALT'] = os.environ.get("SECURITY_PASSWORD_SALT", TODO) + app.config['SECURITY_PASSWORD_SALT'] = os.environ.get("SECURITY_PASSWORD_SALT", "327589938147555935984237744799432734422") # have session and remember cookie be samesite (flask/flask_login) - # app.config["REMEMBER_COOKIE_SAMESITE"] = "strict" - # app.config["SESSION_COOKIE_SAMESITE"] = "strict" - pass + app.config["REMEMBER_COOKIE_SAMESITE"] = "strict" + app.config["SESSION_COOKIE_SAMESITE"] = "strict" else: # Secrets for the development environment are hard-coded. # Secrets for production/deployment must be passed securely to the app. @@ -57,10 +58,21 @@ def create_app(): class User(db.Model, fsqla.FsUserMixin): pass - db.init_app(app) user_datastore = SQLAlchemyUserDatastore(db, User, Role) app.security = Security(app, user_datastore) return app, db +if __name__ == '__main__': + app, db = create_app() + + with app.app_context(): + + # Create User to test with + db.create_all() + if not app.security.datastore.find_user(email="test@me.com"): + app.security.datastore.create_user(email="test@me.com", password=hash_password("password")) + db.session.commit() + + app.run() \ No newline at end of file diff --git a/backend/auth.py b/backend/auth.py index 804a44a..83aefd9 100644 --- a/backend/auth.py +++ b/backend/auth.py @@ -8,10 +8,10 @@ auth = Blueprint("auth", __name__) def login(): pass -@auth.route("signup") +@auth.route("/signup") def signup(): pass -@auth.route("logout") +@auth.route("/logout") def logout(): pass \ No newline at end of file diff --git a/backend/requirements.txt b/backend/requirements.txt index 0e22f81..b331980 100644 --- a/backend/requirements.txt +++ b/backend/requirements.txt @@ -20,6 +20,7 @@ itsdangerous==2.1.2 Jinja2==3.1.3 MarkupSafe==2.1.5 passlib==1.7.4 +setuptools==69.5.1 six==1.16.0 SQLAlchemy==2.0.29 SQLAlchemy-Utils==0.41.2 -- GitLab