Няма описание

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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('/<user>/<action>/<tipo>', methods=['GET', 'POST'])
  40. def dispatcher(user, action, tipo):
  41. if not user in ["admin", "estudiante", "enfermera", "encargado", "facultad"]:
  42. return render_template('login.html') # Mejor error
  43. if not action in ["list", "view", "edit", "add"]:
  44. return render_template('login.html') # Mejor error
  45. if not tipo in ["enfermera", "admin", "estudiante", "madre", "facultad", "curso"]:
  46. return render_template('login.html') # Mejor error
  47. print("here")
  48. if tipo == "curso":
  49. return render_template("formacurso.html")
  50. return render_template("listuser.html", tipo=tipo, admin=1)
  51. @app.route('/be/<user>/<action>/<tipo>', methods=['GET', 'POST'])
  52. def database(user, action, tipo):
  53. if not user in ["admin", "estudiante", "enfermera", "encargado", "facultad"]:
  54. return render_template('login.html') # Mejor error
  55. if not action in ["list", "view", "edit", "add"]:
  56. return render_template('login.html') # Mejor error
  57. if not tipo in ["enfermera", "admin", "estudiante", "madre", "facultad", "curso"]:
  58. return render_template('login.html') # Mejor error
  59. # @app.route('/view/list/<tipo>/', methods=['GET', 'POST'])
  60. # def viewlist(tipo):
  61. # if tipo == "curso":
  62. # return render_template("formacurso.html")
  63. #
  64. # return render_template("listuser.html", tipo=tipo, admin=1)
  65. @app.route('/list/<tipo>/', methods=['GET', 'POST'])
  66. def list(tipo):
  67. if tipo in ["enfermera", "admin", "estudiante", "madre", "facultad", "curso"]:
  68. return jsonify(globals()[tipo].list())
  69. @app.route('/dashAdmin', methods=['GET', 'POST'])
  70. def dashAdmin():
  71. # data = json.loads('formaEstudiantes.json')
  72. return {}
  73. app.secret_key = os.urandom(52)
  74. if __name__ == "__main__":
  75. app.run(host='0.0.0.0', port=9000, debug=True)