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.
 
 
 
 
 

86 lignes
2.3 KiB

  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. @app.before_request
  28. def prepare_request():
  29. g.auth = auth
  30. g.config = config
  31. g.eve = eve
  32. g.version = calefaction.__version__
  33. app.before_request(Database.pre_hook)
  34. app.teardown_appcontext(Database.post_hook)
  35. @app.route("/")
  36. @catch_exceptions
  37. def index():
  38. success, _ = try_func(auth.is_authenticated)
  39. if success:
  40. return render_template("home.mako")
  41. return render_template("landing.mako")
  42. @app.route("/login", methods=["GET", "POST"])
  43. @catch_exceptions
  44. def login():
  45. code = request.args.get("code")
  46. state = request.args.get("state")
  47. success, caught = try_func(lambda: auth.handle_login(code, state))
  48. if success:
  49. flash(Messages.LOGGED_IN, "success")
  50. elif getattr(g, "_session_expired", False):
  51. flash(Messages.SESSION_EXPIRED, "error")
  52. elif not caught:
  53. flash(Messages.LOGIN_FAILED, "error")
  54. return redirect(url_for("index"), 303)
  55. @app.route("/logout", methods=["GET", "POST"])
  56. @catch_exceptions
  57. def logout():
  58. if request.method == "GET":
  59. return render_template("logout.mako")
  60. auth.handle_logout()
  61. flash(Messages.LOGGED_OUT, "success")
  62. return redirect(url_for("index"), 303)
  63. @app.route("/test")
  64. @catch_exceptions
  65. @route_restricted
  66. def test():
  67. ...
  68. return "Success! You are authenticated!"
  69. if __name__ == "__main__":
  70. app.run(debug=True, port=8080)