No Description

registro-run.py 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. from flask import Flask, render_template, jsonify, session, request
  2. from flask import escape, redirect
  3. import json, os
  4. import estudiante, madre, admin, enfermera, facultad, curso
  5. from authlib import *
  6. app = Flask(__name__)
  7. @app.route('/', methods=['GET', 'POST'])
  8. def index():
  9. # return "Hello, World!"
  10. print(session)
  11. auth = Auth(session)
  12. if not auth.checkAuth():
  13. return render_template("login.html")
  14. print(session["gallitosccom"],session["id"])
  15. print("Enfermera", auth.checkRole("enfermera"))
  16. print("Estudiante", auth.checkRole("estudiante"))
  17. print("Admin", auth.checkRole("admin"))
  18. print("Facultad", auth.checkRole("facultad"))
  19. print("Madre", auth.checkRole("madre"))
  20. print(session)
  21. return render_template("listuser.html", tipo="enfermera", admin=1)
  22. @app.route('/login', methods=['POST'])
  23. def do_login():
  24. auth = Auth(session)
  25. if not (request.form['password'] and request.form["username"]):
  26. return render_template('login.html')
  27. username = "%s" % escape(request.form["username"])
  28. password = escape(request.form["password"])
  29. #
  30. if auth.do_login(username, password):
  31. # Mandar al dashboard
  32. return redirect("/")
  33. # Algo esta mal Mandar al login.
  34. return render_template('login.html')
  35. @app.route("/logout")
  36. def logout():
  37. Auth(session).do_logout()
  38. return render_template('login.html')
  39. @app.route('/view/list/<tipo>/', methods=['GET', 'POST'])
  40. def viewlist(tipo):
  41. if tipo == "curso":
  42. return render_template("formacurso.html")
  43. return render_template("listuser.html", tipo=tipo, admin=1)
  44. @app.route('/list/<tipo>/', methods=['GET', 'POST'])
  45. def list(tipo):
  46. if tipo in ["enfermera", "admin", "estudiante", "madre", "facultad", "curso"]:
  47. return jsonify(globals()[tipo].list())
  48. @app.route('/forma/<accion>/<tipo>/', methods=['GET', 'POST'])
  49. @app.route('/forma/<accion>/<tipo>/<id>', methods=['GET', 'POST'])
  50. def formas(accion,tipo,id=None):
  51. if not tipo in ["enfermera", "admin", "estudiante", "madre", "facultad"]:
  52. return # Redirigirlo a una pagina de errorCallback
  53. if not accion in ["edit", "add"]:
  54. return # Redirigirlo a una pagina de errorCallback
  55. return render_template('forma.html', tipo=tipo, accion=accion, id=id)
  56. @app.route('/formaDatos/<accion>/<tipo>/', methods=['GET', 'POST'])
  57. @app.route('/formaDatos/<accion>/<tipo>/<id>', methods=['GET', 'POST'])
  58. def formaEst(accion, tipo, id=None):
  59. # data = json.loads('formaEstudiantes.json')
  60. #getattr(globals()["enfermera"], "list")()
  61. if not tipo in ["enfermera", "admin", "estudiante", "madre", "facultad"]:
  62. return # Redirigirlo a una pagina de errorCallback
  63. if not accion in ["edit", "add"]:
  64. return # Redirigirlo a una pagina de errorCallback
  65. return jsonify(getattr(globals()[tipo], accion)())
  66. @app.route('/dashAdmin', methods=['GET', 'POST'])
  67. def dashAdmin():
  68. # data = json.loads('formaEstudiantes.json')
  69. return {}
  70. app.secret_key = os.urandom(52)
  71. if __name__ == "__main__":
  72. app.run(host='0.0.0.0', port=9000, debug=True)