Refactor API structure: add internal handling, update templates, and remove deprecated files

This commit is contained in:
marc-go committed 2026-10-10 13:43:18 +02:00
1 parent 313ffec92c
commit a33de15f0c
16 files changed
+91 -29

No files matched your search

@@ -0,0 +1,115 @@
<!DOCTYPE html>
<html lang="en">
<head>
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@400;500;700&display=swap" rel="stylesheet">
<script type="importmap">
{
"imports": {
"@material/web/": "https://esm.run/@material/web/"
}
}
</script>
<script type="module">
import '@material/web/all.js';
import {styles as typescaleStyles} from '@material/web/typography/md-typescale-styles.js';
document.adoptedStyleSheets.push(typescaleStyles.styleSheet);
</script>
<title>%appname% // Entrys</title>
<style>
:root {
--md-sys-color-primary: rgb(58, 58, 255);
}
p {
font-family: Verdana, Geneva, Tahoma, sans-serif;
}
hr {
border: 1px solid rgb(211, 211, 211);
}
.loader {
display: flex;
justify-content: center;
align-items: center;
}
#date {
color: gray;
}
</style>
</head>
<body>
<h1 class="md-typescale-display-large">%appname%</h1>
<md-filled-tonal-button id="entry_add">
Add Entry
</md-filled-tonal-button>
<h2 class="md-typescale-display-medium">All Entrys</h2>
%entrys%
<md-dialog id="add_entry_dialog">
<div slot="headline">
Add entry
</div>
<form slot="content" method="dialog">
<md-filled-text-field id="entry_name" label="Name"></md-filled-text-field><br><br>
<md-filled-text-field id="entry_text" label="Text" rows="5" style="resize: vertical;" type="textarea"></md-filled-text-field>
<div class="loader" id="loader" style="display: none;">
<md-circular-progress id="add_entry_load" indeterminate></md-circular-progress>
</div>
<p id="entry_return"></p>
</form>
<div slot="actions">
<md-filled-button id="entry_submit">Submit</md-filled-button>
<md-text-button id="entry_close">Close</md-text-button>
</div>
</md-dialog>
<script>
document.getElementById("entry_add").addEventListener("click", function() {
document.getElementById("add_entry_dialog").setAttribute("open", "");
});
document.getElementById("entry_close").addEventListener("click", function() {
document.getElementById("add_entry_dialog").removeAttribute("open");
});
document.getElementById("entry_submit").addEventListener("click", function() {
document.getElementById("entry_name").style.display = "none";
document.getElementById("entry_text").style.display = "none";
document.getElementById("entry_submit").style.display = "none";
document.getElementById("entry_close").style.display = "none";
document.getElementById("loader").style.display = "flex";
name = document.getElementById("entry_name").value;
text = document.getElementById("entry_text").value;
fetch("/api/entrys/add.php", {
method: "POST",
body: JSON.stringify({
name: name,
text: text
})
})
.then(response => response.json())
.then(data => {
document.getElementById("loader").style.display = "none";
if (data.status !== 200) {
document.getElementById("entry_return").innerHTML = "API returned an error: " + data.error_text;
document.getElementById("entry_close").style.display = "block";
}else{
document.getElementById("entry_return").innerHTML = "Success! Maybe your entry must be aproved by the owner.";
document.getElementById("entry_close").style.display = "block";
}
})
.catch(error => {
document.getElementById("loader").style.display = "none";
document.getElementById("entry_return").innerHTML = "There was an error: " + error;
document.getElementById("entry_close").style.display = "block";
});
});
</script>
</body>
</html>
+18
View File
@@ -0,0 +1,18 @@
.icon {
display: flex;
justify-content: center;
align-items: center;
font-size: 100pt;
}
.text {
text-align: center;
font-family: Verdana, Geneva, Tahoma, sans-serif;
}
.code {
font-family: monospace;
background-color: rgb(226, 225, 225);
padding: 1px;
border-radius: 5px;
}
+20
View File
@@ -0,0 +1,20 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Error</title>
%css%
</head>
<body>
<div class="page-content">
<div class="icon">
⚠️
</div>
<div class="text">
<h2>Error</h2>
<p>%error%</p>
</div>
</div>
</body>
</html>
+76
View File
@@ -0,0 +1,76 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>%appname% // Login</title>
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@400;500;700&display=swap" rel="stylesheet">
<script type="importmap">
{
"imports": {
"@material/web/": "https://esm.run/@material/web/"
}
}
</script>
<script type="module">
import '@material/web/all.js';
import {styles as typescaleStyles} from '@material/web/typography/md-typescale-styles.js';
document.adoptedStyleSheets.push(typescaleStyles.styleSheet);
</script>
<style>
.page-content {
display: flex;
justify-content: center;
text-align: center;
align-items: center;
}
.center {
display: block;
}
</style>
</head>
<body>
<div class="page-content">
<div class="center">
<h1 class="md-typescale-display-large">%appname%</h1>
<h3 class="md-typescale-display-medium">Admin Panel Login</h3><br><br>
<p class="md-typescale-body-medium" id="error_msg" style="display: none;"></p>
<md-filled-text-field type="text" id="login_username" placeholder="Username"></md-filled-text-field><br><br>
<md-filled-text-field type="password" id="login_password" placeholder="Password"></md-filled-text-field><br><br>
<md-filled-button id="login_button">Login</md-filled-button>
</div>
</div>
<script>
document.getElementById("login_button").addEventListener("click", function() {
var username = document.getElementById("login_username").value;
var password = document.getElementById("login_password").value;
fetch("/api/auth/login.php", {
method:"POST",
body: JSON.stringify({
username: username,
password: password
}),
headers: {
"Content-type": "application/json; charset=UTF-8"
}
})
.then(response => response.json())
.then(data => {
if (data.status == 200) {
window.location.reload();
}else{
document.getElementById("error_msg").innerHTML = data.error_text;
document.getElementById("error_msg").style.display = "block";
}
})
.catch(error => {
document.getElementById("error_msg").innerHTML = error;
document.getElementById("error_msg").style.display = "block";
})
});
</script>
</body>
</html>
+145
View File
@@ -0,0 +1,145 @@
<!DOCTYPE html>
<html lang="en">
<head>
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@400;500;700&display=swap" rel="stylesheet">
<script type="importmap">
{
"imports": {
"@material/web/": "https://esm.run/@material/web/"
}
}
</script>
<script type="module">
import '@material/web/all.js';
import {styles as typescaleStyles} from '@material/web/typography/md-typescale-styles.js';
document.adoptedStyleSheets.push(typescaleStyles.styleSheet);
</script>
<title>Setup</title>
<style>
:root {
--md-sys-color-primary: rgb(58, 58, 255);
}
body {
display: flex;
justify-content: center;
align-items: center;
text-align: center;
}
p {
font-family: Verdana, Geneva, Tahoma, sans-serif;
}
</style>
</head>
<body>
<div class="content">
<h1 class="md-typescale-display-medium">Hello!</h1>
<p>Welcome to your Guestbook! Enter here your prefered username and password.</p>
<md-filled-text-field label="Username" type="text" id="setup-username"></md-filled-text-field><br><br>
<md-filled-text-field label="Password" type="password" id="setup-password"></md-filled-text-field><br><br>
<md-filled-text-field label="Repeat Password" type="password" id="setup-password-repeat"></md-filled-text-field><br><br>
<md-filled-button id="submit-button">Save</md-filled-button>
</div>
<md-dialog id="http-dialog">
<div slot="headline">
Warning
</div>
<form slot="content" method="dialog">
Your browser is using http instead of https. That means your connection is not encrypted and everyone in your network can read your credentials.
</form>
<div slot="actions">
<md-text-button id="http-dialog-close-button">I know what i'm doing!</md-text-button>
</div>
</md-dialog>
<md-dialog id="error-dialog">
<div slot="headline">
Error
</div>
<form slot="content" method="dialog" id="error-dialog-text">
</form>
<div slot="actions">
<md-filled-button id="close-button">Close</md-filled-button>
</div>
</md-dialog>
<md-dialog id="success-dialog">
<div slot="headline">
Success!
</div>
<form slot="content" method="dialog" id="error-dialog-text">
Your Guestbook is finaly configurated! You can find the admin Panel on <span id="success-admin-url"></span>.
</form>
<div slot="actions">
<md-filled-button id="success-dialog-home">Open Guestbook</md-filled-button>
<md-filled-button id="success-dialog-admin">Open Admin Panel</md-filled-button>
</div>
</md-dialog>
<script>
if (window.location.protocol == "http:") {
document.getElementById("http-dialog").setAttribute("open", "");
document.getElementById("http-dialog-close-button").addEventListener("click", function() {
document.getElementById("http-dialog").removeAttribute("open");
});
}
document.getElementById("submit-button").addEventListener("click", function() {
checkSetup();
});
document.getElementById("close-button").addEventListener("click", function() {
document.getElementById("error-dialog").removeAttribute("open");
});
document.getElementById("success-dialog-home").addEventListener("click", function() {
window.location.reload();
});
document.getElementById("success-dialog-admin").addEventListener("click", function() {
window.location.href = "/admin";
});
function checkSetup() {
const username = document.getElementById("setup-username").value;
const password = document.getElementById("setup-password").value;
const password_repeat = document.getElementById("setup-password-repeat").value;
// Check if Passwords match
if (password !== password_repeat) {
console.error("Passwords does not match");
document.getElementById("error-dialog-text").innerHTML = "Passwords does not match";
document.getElementById("error-dialog").setAttribute("open", "");
}
// Send data
fetch("/api/setup/save.php", {
method: "POST",
body: JSON.stringify({
username: username,
password: password,
password_repeat: password_repeat
}),
headers: {
"Content-type": "application/json; charset=UTF-8"
}
})
.then(response => response.json())
.then(data => {
if (data.status == 200) {
document.getElementById("success-admin-url").innerHTML = window.location.href + "admin";
document.getElementById("success-dialog").setAttribute("open", "");
}else{
console.error("Server returned following message: " + data.error);
document.getElementById("error-dialog-text").innerHTML = data.display_error;
document.getElementById("error-dialog").setAttribute("open", "");
}
})
}
</script>
</body>
</html>
+28
View File
@@ -0,0 +1,28 @@
{
"error":{
"name":"error",
"dir_name":"error",
"html_file":"error.html",
"css_files":[
"error.css"
]
},
"setup":{
"name":"setup",
"dir_name":"setup",
"html_file":"setup.html",
"css_files":[]
},
"entrys_frontend":{
"name":"entrys_frontend",
"dir_name":"entrys_frontend",
"html_file":"entrys_frontend.html",
"css_files":[]
},
"login":{
"name":"login",
"dir_name":"login",
"html_file":"login.html",
"css_files":[]
}
}