Add template for unauthenticated response
This commit is contained in:
parent
4f83ee3a40
commit
abaea8673a
23
jon/auth.py
23
jon/auth.py
@ -1,7 +1,7 @@
|
|||||||
import random
|
import random
|
||||||
import string
|
import string
|
||||||
|
|
||||||
from flask import Blueprint, make_response, request, redirect, session
|
from flask import Blueprint, request, redirect, render_template, session
|
||||||
|
|
||||||
bp = Blueprint("auth", __name__, url_prefix="/auth")
|
bp = Blueprint("auth", __name__, url_prefix="/auth")
|
||||||
|
|
||||||
@ -9,22 +9,17 @@ 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 = """
|
ALLOWED_PATHS = [
|
||||||
For security-reasons we must make sure you are the person who executed jon :D <br />
|
"/favicon.ico",
|
||||||
<form action="" method="get">
|
"/static/jon.css"
|
||||||
<input type="password" name="token" placeholder="Token" />
|
]
|
||||||
<input type="submit" value="login" />
|
|
||||||
</form>
|
|
||||||
<hr />
|
|
||||||
|
|
||||||
"""
|
|
||||||
|
|
||||||
|
|
||||||
def before_request():
|
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.
|
Unless the session is authenticated, all requests result 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:
|
||||||
@ -32,8 +27,12 @@ def before_request():
|
|||||||
# Reload the page without query parameters
|
# Reload the page without query parameters
|
||||||
return redirect(request.path)
|
return redirect(request.path)
|
||||||
|
|
||||||
|
# Don't deny any paths in `ALLOWED_PATHS`
|
||||||
|
if request.path in ALLOWED_PATHS:
|
||||||
|
return
|
||||||
|
|
||||||
if not "authenticated" in session:
|
if not "authenticated" in session:
|
||||||
return ERROR_TEXT, 403
|
return render_template("auth/denied.html"), 403
|
||||||
|
|
||||||
|
|
||||||
@bp.get("/logout")
|
@bp.get("/logout")
|
||||||
|
65
jon/static/jon.css
Normal file
65
jon/static/jon.css
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
html {
|
||||||
|
font-family: Helvetica, sans-serif;
|
||||||
|
}
|
||||||
|
h1 {
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
nav > ul {
|
||||||
|
padding-left: 0;
|
||||||
|
}
|
||||||
|
nav > ul > li {
|
||||||
|
display: inline-block;
|
||||||
|
list-style: none;
|
||||||
|
}
|
||||||
|
nav > ul > li + li:before {
|
||||||
|
content: ' · ';
|
||||||
|
}
|
||||||
|
.current-page > a {
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
.current-page > a:after {
|
||||||
|
content: '↓';
|
||||||
|
font-size: 0.8em;
|
||||||
|
box-sizing: border-box;
|
||||||
|
position: absolute;
|
||||||
|
display: block;
|
||||||
|
right: 50%;
|
||||||
|
top: -1em;
|
||||||
|
width: 1em;
|
||||||
|
text-align: center;
|
||||||
|
margin-right: -0.5em;
|
||||||
|
animation: wiggle 0.8s ease-in-out 0s infinite;
|
||||||
|
/* animation-direction: alternate; */
|
||||||
|
}
|
||||||
|
.--align-left {
|
||||||
|
text-align: left;
|
||||||
|
}
|
||||||
|
.--align-right {
|
||||||
|
text-align: right;
|
||||||
|
}
|
||||||
|
.--centered {
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
@keyframes wiggle {
|
||||||
|
0%, 100% { margin-top: 0; }
|
||||||
|
50% { margin-top: -0.5em; }
|
||||||
|
/* 100% { transform: rotate(1turn); } */
|
||||||
|
}
|
||||||
|
table {
|
||||||
|
border-spacing: .5em 0;
|
||||||
|
}
|
||||||
|
th {
|
||||||
|
font-size: .8em;
|
||||||
|
}
|
||||||
|
@media print {
|
||||||
|
body {
|
||||||
|
font-size: 8px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.form-input > label {
|
||||||
|
font-size: .8em;
|
||||||
|
}
|
||||||
|
.form-input > input:not([type=radio]),
|
||||||
|
.form-input > select {
|
||||||
|
display: block;
|
||||||
|
}
|
36
jon/templates/auth/denied.html
Normal file
36
jon/templates/auth/denied.html
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<title>jon · not authenticated</title>
|
||||||
|
<link rel="stylesheet" href="/static/jon.css">
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<header>
|
||||||
|
<h1>jon</h1>
|
||||||
|
|
||||||
|
{% if config.DEBUG %}
|
||||||
|
<details>
|
||||||
|
<summary><code>config</code></summary>
|
||||||
|
<pre>{% for key, value in config.items() %}{{ key }} = {{ value }}
|
||||||
|
{% endfor %}</pre>
|
||||||
|
</details>
|
||||||
|
{% endif %}
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<main>
|
||||||
|
<p>
|
||||||
|
Damit kein Schabernack getrieben wird müssen wir sicherstellen, dass du die Person bist die jon ausgeführt hat.
|
||||||
|
Gib unten das Token ein, welches jon beim Starten ausgegeben hat.
|
||||||
|
</p>
|
||||||
|
<form method="GET">
|
||||||
|
<div class="form-input">
|
||||||
|
<label for="token">Token</label>
|
||||||
|
<input type="password" name="token" placeholder="Token" id="token">
|
||||||
|
</div>
|
||||||
|
<button type="submit">Authentifizieren</button>
|
||||||
|
</form>
|
||||||
|
</main>
|
||||||
|
</body>
|
||||||
|
</html>
|
@ -3,73 +3,7 @@
|
|||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<title>jon</title>
|
<title>jon</title>
|
||||||
<style>
|
<link rel="stylesheet" href="/static/jon.css">
|
||||||
html {
|
|
||||||
font-family: Helvetica, sans-serif;
|
|
||||||
}
|
|
||||||
h1 {
|
|
||||||
margin: 0;
|
|
||||||
}
|
|
||||||
nav > ul {
|
|
||||||
padding-left: 0;
|
|
||||||
}
|
|
||||||
nav > ul > li {
|
|
||||||
display: inline-block;
|
|
||||||
list-style: none;
|
|
||||||
}
|
|
||||||
nav > ul > li + li:before {
|
|
||||||
content: ' · ';
|
|
||||||
}
|
|
||||||
.current-page > a {
|
|
||||||
position: relative;
|
|
||||||
}
|
|
||||||
.current-page > a:after {
|
|
||||||
content: '↓';
|
|
||||||
font-size: 0.8em;
|
|
||||||
box-sizing: border-box;
|
|
||||||
position: absolute;
|
|
||||||
display: block;
|
|
||||||
right: 50%;
|
|
||||||
top: -1em;
|
|
||||||
width: 1em;
|
|
||||||
text-align: center;
|
|
||||||
margin-right: -0.5em;
|
|
||||||
animation: wiggle 0.8s ease-in-out 0s infinite;
|
|
||||||
/* animation-direction: alternate; */
|
|
||||||
}
|
|
||||||
.--align-left {
|
|
||||||
text-align: left;
|
|
||||||
}
|
|
||||||
.--align-right {
|
|
||||||
text-align: right;
|
|
||||||
}
|
|
||||||
.--centered {
|
|
||||||
text-align: center;
|
|
||||||
}
|
|
||||||
@keyframes wiggle {
|
|
||||||
0%, 100% { margin-top: 0; }
|
|
||||||
50% { margin-top: -0.5em; }
|
|
||||||
/* 100% { transform: rotate(1turn); } */
|
|
||||||
}
|
|
||||||
table {
|
|
||||||
border-spacing: .5em 0;
|
|
||||||
}
|
|
||||||
th {
|
|
||||||
font-size: .8em;
|
|
||||||
}
|
|
||||||
@media print {
|
|
||||||
body {
|
|
||||||
font-size: 8px;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.form-input > label {
|
|
||||||
font-size: .8em;
|
|
||||||
}
|
|
||||||
.form-input > input:not([type=radio]),
|
|
||||||
.form-input > select {
|
|
||||||
display: block;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<header>
|
<header>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user