Add a comment and code style stuff
This commit is contained in:
parent
1492451065
commit
476a7ebd47
@ -23,6 +23,8 @@ def create_app():
|
|||||||
|
|
||||||
db.init_app(app)
|
db.init_app(app)
|
||||||
|
|
||||||
|
# This function denies every request until `auth.ACCESS_TOKEN`
|
||||||
|
# is passed using `?token=` to authenticate the session.
|
||||||
@app.before_request
|
@app.before_request
|
||||||
def before_req_fun():
|
def before_req_fun():
|
||||||
return auth.before_request()
|
return auth.before_request()
|
||||||
@ -40,6 +42,6 @@ def create_app():
|
|||||||
def index():
|
def index():
|
||||||
return render_template("index.html")
|
return render_template("index.html")
|
||||||
|
|
||||||
print("Jon started. Token: %s" % auth.ACCESS_TOKEN, file=sys.stderr)
|
print(f"Jon started. Token: {auth.ACCESS_TOKEN}", file=sys.stderr)
|
||||||
|
|
||||||
return app
|
return app
|
||||||
|
@ -3,10 +3,10 @@ import string
|
|||||||
|
|
||||||
from flask import Blueprint, make_response, request, redirect, session
|
from flask import Blueprint, make_response, request, redirect, session
|
||||||
|
|
||||||
bp = Blueprint('auth', __name__, url_prefix="/auth")
|
bp = Blueprint("auth", __name__, url_prefix="/auth")
|
||||||
|
|
||||||
|
|
||||||
ACCESS_TOKEN = ''.join(random.choice(string.ascii_lowercase) for i in range(64))
|
ACCESS_TOKEN = "".join(random.choice(string.ascii_lowercase) for i in range(64))
|
||||||
|
|
||||||
|
|
||||||
ERROR_TEXT = """
|
ERROR_TEXT = """
|
||||||
@ -24,10 +24,12 @@ def before_request():
|
|||||||
"""
|
"""
|
||||||
If the correct token query parameter is passed along with any request,
|
If the correct token query parameter is passed along with any request,
|
||||||
we mark this session authenticated by setting `session["authenticated"]`.
|
we mark this session authenticated by setting `session["authenticated"]`.
|
||||||
|
Unless the session is authenticated, all requests results in a 403 FORBIDDEN.
|
||||||
"""
|
"""
|
||||||
if "token" in request.args:
|
if "token" in request.args:
|
||||||
if request.args["token"] == ACCESS_TOKEN:
|
if request.args["token"] == ACCESS_TOKEN:
|
||||||
session["authenticated"] = ()
|
session["authenticated"] = ()
|
||||||
|
# Reload the page without query parameters
|
||||||
return redirect(request.path)
|
return redirect(request.path)
|
||||||
|
|
||||||
if not "authenticated" in session:
|
if not "authenticated" in session:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user