[FastAPI] add /tos routes (get, post)

This clones the end goal behavior of PHP, but it does not
concern itself with the revision form array at all.

Since this page on PHP renders out the entire list of
terms that a user needs to accept, we can treat a
POST request with the "accept" checkbox enabled as a
request to accept all unaccepted (or outdated revision)
terms.

This commit also adds in a new http middleware used to
redirect authenticated users to '/tos' if they have not
yet accepted all terms.

Signed-off-by: Kevin Morris <kevr@0cost.org>
This commit is contained in:
Kevin Morris 2021-06-13 12:18:17 -07:00
parent e624e25c0f
commit adb42882c5
4 changed files with 258 additions and 4 deletions

46
templates/tos/index.html Normal file
View file

@ -0,0 +1,46 @@
{% extends "partials/layout.html" %}
{% block pageContent %}
<div id="dev-login" class="box">
<h2>AUR {% trans %}Terms of Service{% endtrans %}</h2>
<form method="post" action="/tos">
<fieldset>
<p>
{{
"Logged-in as: %s"
| tr | format(
"<strong>" + request.user.Username + "</strong>")
| safe
}}
</p>
<p>
{{
"The following documents have been updated. "
"Please review them carefully:" | tr
}}
</p>
<ul>
{% for term in unaccepted_terms %}
<li>
<a href="{{ term.URL }}">{{ term.Description }}</a>
(revision {{ term.Revision }})
</li>
{% endfor %}
</ul>
<p>
{% for term in unaccepted_terms %}
<input type="hidden"
name="rev[{{ loop.index }}]"
value="{{ term.Revision }}" />
{% endfor %}
<input type="checkbox" name="accept" />
{{ "I accept the terms and conditions above." | tr }}
</p>
<p>
<input type="submit" name="submit"
value="{{ 'Continue' | tr }}" />
</p>
</fieldset>
</form>
</div>
{% endblock %}