def create_app(): app_flask = Flask(__name__) secret = secrets.token_urlsafe(32) app_flask.secret_key = secret app_flask.config.from_object('src.custom_config.DevelopmentConfig') # path = src.config['PATH_CONFIG'] os.environ['PATH_CONFIG']='./config/Dashboard_dev.yaml' yml = init_properties(os.environ['PATH_CONFIG']) PropertiesDb(yml['db']) PropertiesGenerales(yml['generales']) PropertiesDf(yml['df']) PropertiesSQL(yml['sql']) PropertiesQueries(yml['queries']) PropertiesQueriesHistorico(yml['queries_historicos']) PropertiesDemanda(yml['queries_distribucion_demanda']) PropertiesTendencia(yml['queries_tendencia_venta']) PropertiesEstancia(yml['queries_estancia']) PropertiesUsuario(yml['nuevo_usuario']) PropertiesCostos(yml['costos']) app_flask.register_blueprint(controller_module) app_flask.register_blueprint(errors) db = Db() db.create_session() log.info("Empieza la aplicacion") return app_flask
def do_admin_login(): if request.method == "POST": POST_USERNAME = str(request.form['username']) POST_PASSWORD = str(request.form['password']) db = Db() engine = db.create_session() # Base = declarative_base() Session = sessionmaker(bind=engine) s = Session() query = s.query(User).filter(User.username.in_([POST_USERNAME]), User.password.in_([POST_PASSWORD])) result = query.first() if result: session['logged_in'] = True # session['nombre']=result.nombre return home() else: return render_template("errors_users.html") else: return redirect(url_for('controller_module.home'))
from src.db import Db from src.log import log from sqlalchemy import * from sqlalchemy import create_engine, ForeignKey from sqlalchemy.orm import sessionmaker from sqlalchemy import Column, Date, Integer, String from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.orm import relationship, backref db=Db() engine = db.create_session() Base = declarative_base() Session = sessionmaker(bind=engine) session = Session() class User(Base): __tablename__ = 'users' id = Column(Integer, Sequence('user_id_seq'), primary_key=True) nombre = Column(String(50)) apellido = Column(String(50)) username = Column(String(50)) password = Column(String(50)) def __init__(self, nombre, apellido,username, password): self.nombre = nombre self.apellido= apellido self.username=username self.password=password def __repr__(self):