A corporation manager and dashboard for EVE Online
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

app.py 2.3 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. #! /usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. from pathlib import Path
  4. from flask import Flask, flash, g, redirect, request, url_for
  5. from flask_mako import MakoTemplates, render_template
  6. import calefaction
  7. from calefaction.auth import AuthManager
  8. from calefaction.config import Config
  9. from calefaction.database import Database
  10. from calefaction.eve import EVE
  11. from calefaction.messages import Messages
  12. from calefaction.util import (
  13. try_func, make_error_catcher, make_route_restricter,
  14. set_up_asset_versioning)
  15. app = Flask(__name__)
  16. basepath = Path(__file__).resolve().parent
  17. config = Config(basepath / "config")
  18. Database.path = str(basepath / "data" / "db.sqlite3")
  19. eve = EVE(config)
  20. auth = AuthManager(config, eve)
  21. catch_exceptions = make_error_catcher(app, "error.mako")
  22. route_restricted = make_route_restricter(
  23. auth, lambda: redirect(url_for("index"), 303))
  24. MakoTemplates(app)
  25. set_up_asset_versioning(app)
  26. config.install(app)
  27. calefaction.enable_logging()
  28. @app.before_request
  29. def prepare_request():
  30. g.auth = auth
  31. g.config = config
  32. g.eve = eve
  33. g.version = calefaction.__version__
  34. app.before_request(Database.pre_hook)
  35. app.teardown_appcontext(Database.post_hook)
  36. @app.route("/")
  37. @catch_exceptions
  38. def index():
  39. success, _ = try_func(auth.is_authenticated)
  40. if success:
  41. return render_template("home.mako")
  42. return render_template("landing.mako")
  43. @app.route("/login", methods=["GET", "POST"])
  44. @catch_exceptions
  45. def login():
  46. code = request.args.get("code")
  47. state = request.args.get("state")
  48. success, caught = try_func(lambda: auth.handle_login(code, state))
  49. if success:
  50. flash(Messages.LOGGED_IN, "success")
  51. elif getattr(g, "_session_expired", False):
  52. flash(Messages.SESSION_EXPIRED, "error")
  53. elif not caught:
  54. flash(Messages.LOGIN_FAILED, "error")
  55. return redirect(url_for("index"), 303)
  56. @app.route("/logout", methods=["GET", "POST"])
  57. @catch_exceptions
  58. def logout():
  59. if request.method == "GET":
  60. return render_template("logout.mako")
  61. auth.handle_logout()
  62. flash(Messages.LOGGED_OUT, "success")
  63. return redirect(url_for("index"), 303)
  64. @app.route("/test")
  65. @catch_exceptions
  66. @route_restricted
  67. def test():
  68. ...
  69. return "Success! You are authenticated!"
  70. if __name__ == "__main__":
  71. app.run(debug=True, port=8080)