forked from Anteros-Code-Mentoria/poc-mvc-ocr
84 lines
2.5 KiB
Python
84 lines
2.5 KiB
Python
from flask import Flask
|
|
from app.database import db
|
|
# Importação dos blueprints
|
|
from app.routes.usuario import usuarios_bp
|
|
from app.routes.organizacao import organizacoes_bp
|
|
from app.routes.documentos import documentos_bp
|
|
|
|
|
|
def create_app():
|
|
app = Flask(__name__)
|
|
app.config.from_object("config")
|
|
|
|
# Inicializa a extensão SQLAlchemy
|
|
db.init_app(app)
|
|
|
|
# Registra os blueprints
|
|
app.register_blueprint(usuarios_bp)
|
|
app.register_blueprint(organizacoes_bp)
|
|
app.register_blueprint(documentos_bp)
|
|
|
|
return app
|
|
from flask import Flask
|
|
from flasgger import Swagger
|
|
from app.database import db
|
|
from app.models.user import User
|
|
from app.routes.user_routes import user_bp
|
|
from app.routes.login_form import login_bp
|
|
from app.routes.dashboard import dashboard_bp
|
|
from app.routes.invoice_routes import invoice_bp
|
|
from werkzeug.security import generate_password_hash
|
|
|
|
def create_default_user():
|
|
# Verifica se o banco de dados está vazio
|
|
user = User.query.first()
|
|
|
|
if not user:
|
|
# Cria um usuário padrão com senha "senha123"
|
|
default_user = User(
|
|
name="admin",
|
|
email="admin@example.com",
|
|
password=generate_password_hash("senha123", method="pbkdf2:sha256")
|
|
)
|
|
|
|
# Adiciona o usuário no banco de dados
|
|
db.session.add(default_user)
|
|
db.session.commit()
|
|
|
|
print("Usuário padrão criado com sucesso!")
|
|
|
|
|
|
def create_app():
|
|
app = Flask(__name__)
|
|
app.config.from_object("config")
|
|
|
|
db.init_app(app)
|
|
|
|
|
|
# Inicializa o Flasgger com a definição de segurança para autenticação JWT
|
|
swagger = Swagger(app,
|
|
template={
|
|
"securityDefinitions": {
|
|
"BearerAuth": {
|
|
"type": "apiKey",
|
|
"in": "header",
|
|
"name": "Authorization",
|
|
"description": "Digite 'Bearer <token>'"
|
|
}
|
|
},
|
|
"security": [
|
|
{
|
|
"BearerAuth": []
|
|
}
|
|
]
|
|
})
|
|
|
|
|
|
# Registrar Blueprints
|
|
app.register_blueprint(user_bp, url_prefix="/users")
|
|
app.register_blueprint(invoice_bp, url_prefix="/invoices")
|
|
app.register_blueprint(login_bp, url_prefix="/login_bp")
|
|
app.register_blueprint(dashboard_bp, url_prefix="/dashboard")
|
|
|
|
return app
|