1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- 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('/<user>/<action>/<tipo>', 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/<user>/<action>/<tipo>', 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/<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('/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)
|