Skip to content
Snippets Groups Projects
Commit a0a5786a authored by danielmyren's avatar danielmyren
Browse files

minor changes, it's possible to start the server

parent f2a292e7
Branches
No related tags found
No related merge requests found
.DS_Store
/backend/venv
\ No newline at end of file
/backend/venv
/backend/__pycache__/
\ No newline at end of file
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
......@@ -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
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment