Added settings and API key stuff

Signed-off-by: Marcel Müller <neikos@neikos.email>
This commit is contained in:
Marcel Müller 2026-01-23 19:31:53 +01:00
parent 9d08e23352
commit a80ad57ca9
14 changed files with 396 additions and 45 deletions

View file

@ -1,6 +1,6 @@
{% macro text_input(label, name, id="",type="text") %}
{% macro text_input(label, name, id="",type="text",value="") %}
<div class="flex flex-col">
<label for="{{id}}" class="font-bold">{{label}}:</label>
<input class="border rounded p-1 bg-gray-50" type="{{type}}" name="{{name}}" id="{{id}}" />
<input class="border rounded p-1 bg-gray-50" type="{{type}}" name="{{name}}" id="{{id}}" {% if value %}value="{{value}}"{% endif %} />
</div>
{% endmacro text_input %}

View file

@ -0,0 +1,25 @@
{% extends "base.tera.html" %}
{% import "inputs.tera.html" as inputs %}
{% block title %}
Home
{% endblock title %}
{% block content %}
<div class="place-self-center mx-auto p-4 space-y-4 bg-red-200 md:border border-red-300 shadow-xl md:rounded">
<h1 class="font-bold text-2xl">There was an internal error</h1>
<p>
{{ error }}
</p>
<hr class="bg-red-800 border-0 h-px">
<p>
This error usually indicates that the problem is not on your side.
<br>
Additional information was logged for the operator.
<br>
Feel free to try again later.
</p>
</div>
{% endblock content %}

View file

@ -0,0 +1,69 @@
{% extends "base.tera.html" %}
{% import "inputs.tera.html" as inputs %}
{% block title %}
API Keys - {{ current_user.username }}
{% endblock title %}
{% block content %}
<div class="flex flex-col md:flex-row grow">
<div class="basis-1/4 p-4 m-4 space-y-4">
{% include "settings/sidebar.tera.html" %}
</div>
<div class="basis-3/4 p-4">
<h1 class="font-bold text-3xl">API Keys</h1>
<form action="/settings/new_api_key" method="POST" class="space-y-4">
{{ inputs::text_input(label="Name", name="name", id="name", type="text") }}
{{ inputs::text_input(label="Expiration Date", name="expiration_date", id="expiration_date", type="date", value=one_year_date)}}
<div class="flex flex-col">
<button type="submit" class="bg-blue-500 p-2 rounded-lg text-white">
Create API Key
</button>
</div>
</form>
<hr class="my-4 w-1/2 border-0 bg-zinc-300 h-0.5 mx-auto">
<h2 class="font-bold text-2xl my-4">Current API Tokens</h2>
<table class="border-collapse border-spacing-2 border border-zinc-400 w-full">
<thead class="bg-orange-50">
<tr>
<th class="border border-zinc-300 w-1/4 p-4 font-semibold">Name</th>
<th class="border border-zinc-300 w-1/4 p-4 font-semibold">Active</th>
<th class="border border-zinc-300 w-1/4 p-4 font-semibold">Expiration Date</th>
<th class="border border-zinc-300 w-1/4 p-4 font-semibold">Actions</th>
</tr>
</thead>
<tbody>
{% for api_key in api_keys %}
<tr>
<td class="border border-zinc-200 p-2">{{ api_key.name}}</td>
<td class="border border-zinc-200 p-2 text-center">
{% if api_key.revoked %}
<span class="align-middle">No Longer Active</span><span class="inline-block align-middle size-6 ml-2 bg-zinc-500 rounded-lg"></span>
{% else %}
<span class="align-middle">Currently Active</span><span class="inline-block align-middle size-6 ml-2 bg-green-500 rounded-lg"></span>
{% endif %}
</td>
<td class="border border-zinc-200 p-2 text-center">{{ api_key.expiration_date }}</td>
<td class="border border-zinc-200 p-2 text-center">
{% if api_key.revoked %}
<span class="text-zinc-700">A revoked API Key cannot be revived</span>
{% else %}
<form action="/settings/revoke_api_key" method="POST">
<input type="hidden" name="api_key_id" value="{{ api_key.id }}">
<button type="submit" class="px-4 py-2 inline-block border border-red-700 bg-red-600 text-white rounded pointer-link">
Revoke API Key
</button>
</form>
{% endif %}
</td>
</tr>
{% endfor %}
<tbody>
</table>
</div>
</div>
{% endblock content %}

View file

@ -0,0 +1,27 @@
{% extends "base.tera.html" %}
{% import "inputs.tera.html" as inputs %}
{% block title %}
Change Password - {{ current_user.username }}
{% endblock title %}
{% block content %}
<div class="flex flex-col md:flex-row grow">
<div class="basis-1/4 p-4 m-4 space-y-4">
{% include "settings/sidebar.tera.html" %}
</div>
<div class="basis-3/4 p-4">
<h1 class="font-bold text-3xl">Change Password</h1>
<form action="/settings/change_password" method="POST" class="space-y-4">
{{ inputs::text_input(label="Old Password", name="old_password", id="old_password", type="password") }}
{{ inputs::text_input(label="New Password", name="password", id="password", type="password") }}
{{ inputs::text_input(label="Repeat New Password", name="confirm_password", id="confirm_password", type="password") }}
<div class="flex flex-col">
<button type="submit" class="bg-blue-500 p-2 rounded-lg text-white">
Change Password
</button>
</div>
</form>
</div>
</div>
{% endblock content %}

View file

@ -0,0 +1,19 @@
{% extends "base.tera.html" %}
{% import "inputs.tera.html" as inputs %}
{% block title %}
Settings - {{ current_user.username }}
{% endblock title %}
{% block content %}
<div class="flex flex-col md:flex-row grow">
<div class="basis-1/4 p-4 m-4 space-y-4">
{% include "settings/sidebar.tera.html" %}
</div>
<div class="basis-3/4 p-4">
<p>THIS IS YOUR MAIN SETTINGS WOOHOOOO</p>
<p>Your username is: <em>{{ current_user.username }}</em></p>
</div>
</div>
{% endblock content %}

View file

@ -0,0 +1,12 @@
<h2 class="text-xl font-bold px-4">Settings</h2>
<ul class="space-y-2 bg-zinc-200 p-2 rounded border border-zinc-400 shadow">
<li class="hover:bg-zinc-400">
<a class="p-1 px-2 inline-block w-full" href="/settings">Overview</a>
</li>
<li class="hover:bg-zinc-400">
<a class="p-1 px-2 inline-block w-full" href="/settings/change_password">Change Password</a>
</li>
<li class="hover:bg-zinc-400">
<a class="p-1 px-2 inline-block w-full" href="/settings/api_keys">API Keys</a>
</li>
</ul>