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.
 
 
 
 
 

69 lines
1.8 KiB

  1. #! /usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. from pathlib import Path
  4. from flask import Flask, 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.exceptions import AccessDeniedError, EVEAPIError
  12. from calefaction.util import catch_errors, set_up_asset_versioning
  13. app = Flask(__name__)
  14. basepath = Path(__file__).resolve().parent
  15. config = Config(basepath / "config")
  16. Database.path = str(basepath / "data" / "db.sqlite3")
  17. eve = EVE(config)
  18. auth = AuthManager(config, eve)
  19. MakoTemplates(app)
  20. set_up_asset_versioning(app)
  21. config.install(app)
  22. @app.before_request
  23. def prepare_request():
  24. g.auth = auth
  25. g.config = config
  26. g.eve = eve
  27. g.version = calefaction.__version__
  28. app.before_request(Database.pre_hook)
  29. app.teardown_appcontext(Database.post_hook)
  30. @app.route("/")
  31. @catch_errors(app)
  32. def index():
  33. ... # handle flashed error messages in _base.mako
  34. if auth.is_authenticated(): # ... need to check for exceptions
  35. return render_template("home.mako")
  36. return render_template("landing.mako")
  37. @app.route("/login", methods=["GET", "POST"])
  38. @catch_errors(app)
  39. def login():
  40. code = request.args.get("code")
  41. state = request.args.get("state")
  42. try:
  43. auth.handle_login(code, state)
  44. except EVEAPIError:
  45. ... # flash error message
  46. except AccessDeniedError:
  47. ... # flash error message
  48. if getattr(g, "_session_expired"):
  49. ... # flash error message
  50. return redirect(url_for("index"), 303)
  51. # @app.route("/logout") ...
  52. # @auth.route_restricted ...
  53. # check for same exceptions as login() and use same flashes
  54. if __name__ == "__main__":
  55. app.run(debug=True, port=8080)