2021-04-21 16:47:18 +00:00
|
|
|
"""
|
|
|
|
This is the runner for the server.
|
|
|
|
"""
|
2021-04-19 14:14:51 +00:00
|
|
|
from flask import Flask
|
|
|
|
import os
|
|
|
|
import werkzeug.middleware.proxy_fix
|
2021-04-19 14:23:50 +00:00
|
|
|
from .routes import *
|
2021-04-22 14:54:27 +00:00
|
|
|
from .database import Base, tables
|
2021-04-21 16:47:18 +00:00
|
|
|
import psycopg2
|
2021-04-22 16:46:41 +00:00
|
|
|
from .gestione import *
|
|
|
|
from flask_jwt_extended import *
|
2021-04-19 14:14:51 +00:00
|
|
|
|
|
|
|
app = Flask(__name__)
|
|
|
|
if os.getenv('COOKIE_SECRET'):
|
|
|
|
app.secret_key = os.getenv('COOKIE_SECRET')
|
|
|
|
else:
|
|
|
|
app.secret_key = "testing"
|
2021-04-22 16:46:41 +00:00
|
|
|
if os.getenv("JWT_SECRET_KEY"):
|
|
|
|
app.config["JWT_SECRET_KEY"] = os.getenv("JWT_SECRET_KEY")
|
|
|
|
else:
|
|
|
|
app.config["JWT_SECRET_KEY"] = "testing"
|
|
|
|
|
2021-04-19 14:14:51 +00:00
|
|
|
reverse_proxy_app = werkzeug.middleware.proxy_fix.ProxyFix(app=app, x_for=1, x_proto=0, x_host=1, x_port=0, x_prefix=0)
|
|
|
|
app.config['SQLALCHEMY_DATABASE_URI'] = 'postgresql://postgres:password@localhost:5432/PdSDev'
|
2021-04-21 16:47:18 +00:00
|
|
|
Base.app = app
|
|
|
|
Base.init_app(app)
|
2021-04-22 16:46:41 +00:00
|
|
|
jwt = JWTManager(app)
|
2021-04-19 14:14:51 +00:00
|
|
|
# Routes setup
|
2021-04-22 16:46:41 +00:00
|
|
|
|
2021-04-22 14:54:27 +00:00
|
|
|
app.add_url_rule("/doa", view_func=page_doa, methods=["GET", "POST"])
|
2021-04-22 16:46:41 +00:00
|
|
|
app.add_url_rule("/api/login", view_func=page_login, methods=["POST"])
|
|
|
|
app.add_url_rule("/api/user/create", view_func=page_user_create, methods=["POST"])
|
2021-04-19 14:14:51 +00:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2021-04-21 16:47:18 +00:00
|
|
|
Base.create_all()
|
2021-04-22 16:46:41 +00:00
|
|
|
if not User.query.filter_by(isAdmin=True).all():
|
|
|
|
Base.session.add(User(email="admin@admin.com", password=gen_password("password"), username="admin", isAdmin=True))
|
|
|
|
Base.session.commit()
|
2021-04-19 14:14:51 +00:00
|
|
|
app.run(debug=True)
|