1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- 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"], session["email"])
- 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('/view/list/<tipo>/', 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/<tipo>/', methods=['GET', 'POST'])
- def list(tipo):
- if tipo in ["enfermera", "admin", "estudiante", "madre", "facultad", "curso"]:
- return jsonify(globals()[tipo].list())
-
-
- @app.route('/forma/<accion>/<tipo>/', methods=['GET', 'POST'])
- @app.route('/forma/<accion>/<tipo>/<id>', methods=['GET', 'POST'])
- def formas(accion,tipo,id=None):
-
- if not tipo in ["enfermera", "admin", "estudiante", "madre", "facultad"]:
- return # Redirigirlo a una pagina de errorCallback
- if not accion in ["edit", "add"]:
- return # Redirigirlo a una pagina de errorCallback
- return render_template('forma.html', tipo=tipo, accion=accion, id=id)
-
-
- @app.route('/formaDatos/<accion>/<tipo>/', methods=['GET', 'POST'])
- @app.route('/formaDatos/<accion>/<tipo>/<id>', methods=['GET', 'POST'])
- def formaEst(accion, tipo, id=None):
- # data = json.loads('formaEstudiantes.json')
- #getattr(globals()["enfermera"], "list")()
- if not tipo in ["enfermera", "admin", "estudiante", "madre", "facultad"]:
- return # Redirigirlo a una pagina de errorCallback
- if not accion in ["edit", "add"]:
- return # Redirigirlo a una pagina de errorCallback
-
- return jsonify(getattr(globals()[tipo], accion)())
-
- @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)
|