A corporation manager and dashboard for EVE Online
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

пре 8 година
пре 8 година
пре 8 година
пре 8 година
пре 8 година
пре 8 година
пре 8 година
пре 8 година
пре 8 година
пре 8 година
пре 8 година
пре 8 година
пре 8 година
пре 8 година
пре 8 година
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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)