init
This commit is contained in:
commit
6dcb020bb5
16 files changed
+488
No files matched your search
@@ -0,0 +1,41 @@
|
||||
import base64
|
||||
import secrets
|
||||
import logging
|
||||
|
||||
import flask
|
||||
import flask_login
|
||||
import api.api as api
|
||||
import database
|
||||
|
||||
app = flask.Flask(__name__)
|
||||
app.secret_key = secrets.token_hex(16)
|
||||
app.register_blueprint(api.api)
|
||||
logging.basicConfig(
|
||||
format="%(asctime)s [%(levelname)s] %(name)s:%(lineno)d - %(message)s",
|
||||
level=logging.DEBUG
|
||||
)
|
||||
|
||||
login_manager = flask_login.LoginManager()
|
||||
login_manager.session_protection = "strong"
|
||||
login_manager.init_app(app)
|
||||
|
||||
|
||||
@login_manager.request_loader
|
||||
def load_user(request: flask.Request) -> database.User | None:
|
||||
api_key = request.headers.get('Authorization')
|
||||
if api_key:
|
||||
api_key = api_key.replace('Basic ', '', 1)
|
||||
try:
|
||||
api_key = base64.b64decode(api_key).decode()
|
||||
except TypeError:
|
||||
pass
|
||||
|
||||
username, password = api_key.split(':')
|
||||
|
||||
user = database.get_user(username, password)
|
||||
return user
|
||||
|
||||
return None
|
||||
|
||||
if __name__ == "__main__":
|
||||
app.run(debug=True)
|
||||
Reference in new issue
Block a user