__init__.py 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. """
  2. Website and API
  3. """
  4. import os
  5. from flask import Flask
  6. from flask_sqlalchemy import SQLAlchemy
  7. from flask_login import LoginManager
  8. from flask_migrate import Migrate
  9. from flask_argon2 import Argon2
  10. from dotenv import load_dotenv
  11. from sqlalchemy import MetaData
  12. from rival_regions_wrapper.middleware import LocalAuthentication
  13. load_dotenv()
  14. # app
  15. class Config():
  16. """Config settings for the application"""
  17. SECRET_KEY = os.environ["SECRET_KEY"]
  18. SQLALCHEMY_DATABASE_URI = os.environ["DATABASE_URI"]
  19. SQLALCHEMY_TRACK_MODIFICATIONS = False
  20. SEND_FILE_MAX_AGE_DEFAULT = 1296000
  21. app = Flask(__name__)
  22. app.config.from_object(Config())
  23. app.jinja_env.lstrip_blocks = True
  24. app.jinja_env.trim_blocks = True
  25. # db
  26. convention = {
  27. "ix": 'ix_%(column_0_label)s',
  28. "uq": "uq_%(table_name)s_%(column_0_name)s",
  29. "ck": "ck_%(table_name)s_%(constraint_name)s",
  30. "fk": "fk_%(table_name)s_%(column_0_name)s_%(referred_table_name)s",
  31. "pk": "pk_%(table_name)s"
  32. }
  33. metadata = MetaData(naming_convention=convention)
  34. db = SQLAlchemy(app, metadata=metadata)
  35. migrate = Migrate(app, db)
  36. # Login
  37. login_manager = LoginManager()
  38. login_manager.init_app(app)
  39. login_manager.login_view = "login"
  40. login_manager.login_message_category = "warning"
  41. argon2 = Argon2(app)
  42. # Rival Region wrapper
  43. rrclient = LocalAuthentication(False, os.environ["CAPTCHA_KEY"])
  44. rrclient.set_credentials(
  45. os.environ["USERNAME"],
  46. os.environ["PASSWORD"],
  47. os.environ["LOGIN_METHOD"]
  48. )
  49. alt_rrclient = None
  50. # alt_rrclient = LocalAuthentication(
  51. # os.environ["ALT_USERNAME"], os.environ["ALT_PASSWORD"], os.environ["ALT_LOGIN_METHOD"]
  52. # )