diff options
author | Drew DeVault <sir@cmpwn.com> | 2017-02-08 06:16:50 -0500 |
---|---|---|
committer | Drew DeVault <sir@cmpwn.com> | 2017-02-08 06:16:50 -0500 |
commit | cb938b7fcadabee9e7ae13bf89774d9ccedfc541 (patch) | |
tree | 6c927bb5951eb3076958991545cc82211b6aaa1f /gitsrht/app.py | |
parent | 92d4adde7cc7ec4036730f2f1ab43cfde887f67c (diff) |
git -> gitsrht (module rename)
Diffstat (limited to 'gitsrht/app.py')
-rw-r--r-- | gitsrht/app.py | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/gitsrht/app.py b/gitsrht/app.py new file mode 100644 index 0000000..10cf25c --- /dev/null +++ b/gitsrht/app.py @@ -0,0 +1,48 @@ +from flask import render_template, request +from flask_login import LoginManager, current_user +import urllib.parse +import locale + +from srht.config import cfg, cfgi, load_config +load_config("git") +from srht.database import DbSession +db = DbSession(cfg("sr.ht", "connection-string")) +from gitsrht.types import User +db.init() + +from srht.flask import SrhtFlask +app = SrhtFlask("git", __name__) +app.secret_key = cfg("server", "secret-key") +login_manager = LoginManager() +login_manager.init_app(app) + +@login_manager.user_loader +def load_user(username): + return User.query.filter(User.username == username).first() + +login_manager.anonymous_user = lambda: None + +try: + locale.setlocale(locale.LC_ALL, 'en_US') +except: + pass + +def oauth_url(return_to): + return "{}/oauth/authorize?client_id={}&scopes=profile,keys&state={}".format( + cfg("network", "meta"), + cfg("meta.sr.ht", "oauth-client-id"), + urllib.parse.quote_plus(return_to)) + +from gitsrht.blueprints.auth import auth +from gitsrht.blueprints.public import public +from gitsrht.blueprints.manage import manage + +app.register_blueprint(auth) +app.register_blueprint(public) +app.register_blueprint(manage) + +@app.context_processor +def inject(): + return { + "oauth_url": oauth_url(request.full_path) + } |