diff options
| author | Paul-Christian Volkmer | 2024-01-18 14:29:52 +0100 |
|---|---|---|
| committer | GitHub | 2024-01-18 14:29:52 +0100 |
| commit | 358373cf70212b97044e9714ad1b913fcd24e6bc (patch) | |
| tree | edabf0677d519437dfe78bdb0c8cd7ba2d217fd3 /src/main/resources | |
| parent | 531a8589db2bf170e6272602ccb4a3c4457186d8 (diff) | |
| parent | 27a62321faec1087048e624fe68ab53c4fdbc0a3 (diff) | |
Merge pull request #30 from CCC-MF/issue_29
Issue #29: Unterstützung für Endpoint-Tokens
Diffstat (limited to 'src/main/resources')
| -rw-r--r-- | src/main/resources/db/migration/mariadb/V0_2_0__Tokens.sql | 8 | ||||
| -rw-r--r-- | src/main/resources/db/migration/postgresql/V0_2_0__Tokens.sql | 9 | ||||
| -rw-r--r-- | src/main/resources/static/scripts.js | 7 | ||||
| -rw-r--r-- | src/main/resources/static/style.css | 24 | ||||
| -rw-r--r-- | src/main/resources/templates/configs.html | 4 | ||||
| -rw-r--r-- | src/main/resources/templates/configs/tokens.html | 39 | ||||
| -rw-r--r-- | src/main/resources/templates/login.html | 2 |
7 files changed, 88 insertions, 5 deletions
diff --git a/src/main/resources/db/migration/mariadb/V0_2_0__Tokens.sql b/src/main/resources/db/migration/mariadb/V0_2_0__Tokens.sql new file mode 100644 index 0000000..98e27d9 --- /dev/null +++ b/src/main/resources/db/migration/mariadb/V0_2_0__Tokens.sql @@ -0,0 +1,8 @@ +CREATE TABLE IF NOT EXISTS token +( + id int auto_increment primary key, + name varchar(255) not null, + username varchar(255) not null unique, + password varchar(255) not null, + created_at datetime default utc_timestamp() not null +);
\ No newline at end of file diff --git a/src/main/resources/db/migration/postgresql/V0_2_0__Tokens.sql b/src/main/resources/db/migration/postgresql/V0_2_0__Tokens.sql new file mode 100644 index 0000000..c89c52e --- /dev/null +++ b/src/main/resources/db/migration/postgresql/V0_2_0__Tokens.sql @@ -0,0 +1,9 @@ +CREATE TABLE IF NOT EXISTS token +( + id serial, + name varchar(255) not null, + username varchar(255) not null unique, + password varchar(255) not null, + created_at timestamp with time zone default now() not null, + PRIMARY KEY (id) +);
\ No newline at end of file diff --git a/src/main/resources/static/scripts.js b/src/main/resources/static/scripts.js index 73ad71b..fdd3f52 100644 --- a/src/main/resources/static/scripts.js +++ b/src/main/resources/static/scripts.js @@ -4,14 +4,17 @@ const dateFormat = new Intl.DateTimeFormat('de-DE', dateFormatOptions); const dateTimeFormatOptions = { year: 'numeric', month: '2-digit', day: '2-digit', hour: '2-digit', minute: 'numeric', second: 'numeric' }; const dateTimeFormat = new Intl.DateTimeFormat('de-DE', dateTimeFormatOptions); -window.addEventListener('load', () => { +const formatTimeElements = () => { Array.from(document.getElementsByTagName('time')).forEach((timeTag) => { let date = Date.parse(timeTag.getAttribute('datetime')); if (! isNaN(date)) { timeTag.innerText = dateTimeFormat.format(date); } }); -}); +}; + +window.addEventListener('load', formatTimeElements); +window.addEventListener('htmx:afterRequest', formatTimeElements); function drawPieChart(url, elemId, title, data) { if (data) { diff --git a/src/main/resources/static/style.css b/src/main/resources/static/style.css index e2bf65a..3249aad 100644 --- a/src/main/resources/static/style.css +++ b/src/main/resources/static/style.css @@ -202,13 +202,15 @@ form.samplecode-input input:focus-visible { background: none; } -.login-form form * { +.login-form form *, +.token-form form * { padding: 0.5em; border: 1px solid var(--table-border); border-radius: 3px; } -.login-form button { +.login-form button, +.token-form button { margin: 1em 0; background: var(--bg-blue); color: white; @@ -535,4 +537,22 @@ a.reload { font-size: .6em; align-content: center; justify-content: center; +} + +.new-token { + padding: 1em; + background: var(--bg-green-op); +} + +.new-token > pre { + margin: 0; + border: 1px solid var(--bg-green); + padding: .5em; + width: max-content; + display: inline-block; +} + +.no-token { + padding: 1em; + background: var(--bg-red-op); }
\ No newline at end of file diff --git a/src/main/resources/templates/configs.html b/src/main/resources/templates/configs.html index 3c3d744..ebef7ca 100644 --- a/src/main/resources/templates/configs.html +++ b/src/main/resources/templates/configs.html @@ -37,6 +37,9 @@ </table> </section> + <section th:insert="~{configs/tokens.html}"> + </section> + <section hx-ext="sse" th:sse-connect="@{/configs/events}"> <div th:insert="~{configs/connectionAvailable.html}" th:hx-get="@{/configs?connectionAvailable}" hx-trigger="sse:connection-available"> </div> @@ -86,6 +89,7 @@ </th:block> </section> </main> + <script th:src="@{/scripts.js}"></script> <script th:src="@{/webjars/htmx.org/dist/htmx.min.js}"></script> <script th:src="@{/webjars/htmx.org/dist/ext/sse.js}"></script> </body> diff --git a/src/main/resources/templates/configs/tokens.html b/src/main/resources/templates/configs/tokens.html new file mode 100644 index 0000000..e707fbf --- /dev/null +++ b/src/main/resources/templates/configs/tokens.html @@ -0,0 +1,39 @@ +<div th:if="${not tokensEnabled}"> + <h2><span>⛔</span> Tokens</h2> + <p>Die Verwendung von Tokens ist nicht aktiviert.</p> +</div> + +<div id="tokens" th:if="${tokensEnabled}"> + <h2><span>✅</span> Tokens</h2> + <div class="border"> + <div th:if="${tokens.isEmpty()}">Noch keine Tokens vorhanden.</div> + <table th:if="${not tokens.isEmpty()}"> + <thead> + <tr> + <th>Name</th> + <th>Erstellt</th> + <th></th> + </tr> + </thead> + <tbody> + <tr th:each="token : ${tokens}"> + <td>[[ ${token.name} ]]</td> + <td><time th:datetime="${token.createdAt}">[[ ${token.createdAt} ]]</time></td> + <td><button class="btn btn-red" th:hx-delete="@{/configs/tokens/{id}(id=${token.id})}" hx-target="#tokens">Löschen</button></td> + </tr> + </tbody> + </table> + <div th:if="${newTokenValue != null and success}" class="new-token"> + Verwendung über HTTP-Basic. Bitte notieren, wird nicht erneut angezeigt: <pre>[[ ${newTokenValue} ]]</pre> + </div> + <div th:if="${success != null and not success}" class="no-token"> + Das Token konnte nicht erzeugt werden. Versuchen Sie einen anderen Namen. + </div> + <div class="token-form"> + <form th:hx-post="@{/configs/tokens}" hx-target="#tokens"> + <input placeholder="Token-Name" name="name" required /> + <button>Token Erstellen</button> + </form> + </div> + </div> +</div>
\ No newline at end of file diff --git a/src/main/resources/templates/login.html b/src/main/resources/templates/login.html index 018122d..9a63b46 100644 --- a/src/main/resources/templates/login.html +++ b/src/main/resources/templates/login.html @@ -15,7 +15,7 @@ <form method="post" th:action="@{/login}"> <input type="text" id="username" name="username" class="form-control" placeholder="Username" required="" autofocus=""> <input type="password" id="password" name="password" class="form-control" placeholder="Password" required=""> - <button class="" type="submit">Anmelden</button> + <button type="submit">Anmelden</button> </form> </div> </main> |
