from flask import Flask, render_template, jsonify, session, request from flask import escape, redirect import json, os import estudiante, madre, admin, enfermera, facultad, curso from authlib import * app = Flask(__name__) @app.route('/', methods=['GET', 'POST']) def index(): # return "Hello, World!" print(session) auth = Auth(session) if not auth.checkAuth(): return render_template("login.html") print(session["gallitosccom"],session["id"]) print("Enfermera", auth.checkRole("enfermera")) print("Estudiante", auth.checkRole("estudiante")) print("Admin", auth.checkRole("admin")) print("Facultad", auth.checkRole("facultad")) print("Madre", auth.checkRole("madre")) print(session) return render_template("listuser.html", tipo="enfermera", admin=1) @app.route('/login', methods=['POST']) def do_login(): auth = Auth(session) if not (request.form['password'] and request.form["username"]): return render_template('login.html') username = "%s" % escape(request.form["username"]) password = escape(request.form["password"]) # if auth.do_login(username, password): # Mandar al dashboard return redirect("/") # Algo esta mal Mandar al login. return render_template('login.html') @app.route("/logout") def logout(): Auth(session).do_logout() return render_template('login.html') @app.route('///', methods=['GET', 'POST']) def dispatcher(user, action, tipo): if not user in ["admin", "estudiante", "enfermera", "encargado", "facultad"]: return render_template('login.html') # Mejor error if not action in ["list", "view", "edit", "add"]: return render_template('login.html') # Mejor error if not tipo in ["enfermera", "admin", "estudiante", "madre", "facultad", "curso"]: return render_template('login.html') # Mejor error print("here") if tipo == "curso": return render_template("formacurso.html") return render_template("listuser.html", tipo=tipo, admin=1) @app.route('/be///', methods=['GET', 'POST']) def database(user, action, tipo): if not user in ["admin", "estudiante", "enfermera", "encargado", "facultad"]: return render_template('login.html') # Mejor error if not action in ["list", "view", "edit", "add"]: return render_template('login.html') # Mejor error if not tipo in ["enfermera", "admin", "estudiante", "madre", "facultad", "curso"]: return render_template('login.html') # Mejor error # @app.route('/view/list//', methods=['GET', 'POST']) # def viewlist(tipo): # if tipo == "curso": # return render_template("formacurso.html") # # return render_template("listuser.html", tipo=tipo, admin=1) @app.route('/list//', methods=['GET', 'POST']) def list(tipo): if tipo in ["enfermera", "admin", "estudiante", "madre", "facultad", "curso"]: return jsonify(globals()[tipo].list()) @app.route('/dashAdmin', methods=['GET', 'POST']) def dashAdmin(): # data = json.loads('formaEstudiantes.json') return {} app.secret_key = os.urandom(52) if __name__ == "__main__": app.run(host='0.0.0.0', port=9000, debug=True)