Geen omschrijving

registro-run.py 3.1KB

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