change to use jinja2 and stop saving file and then reading the data

This commit is contained in:
Ugric
2026-01-23 04:51:30 +00:00
parent ecd728fe27
commit 6c17b6c115
6 changed files with 198 additions and 140 deletions

21
templates/base.jinja Normal file
View File

@@ -0,0 +1,21 @@
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="icon" type="image/png" sizes="96x96" href="{{ url_for('static', filename='favicon-96x96.png') }}">
<link rel="icon" type="image/svg+xml" href="{{ url_for('static', filename='favicon.svg') }}">
<link rel="shortcut icon" href="{{ url_for('static', filename='favicon.ico') }}">
<link rel="apple-touch-icon" sizes="180x180" href="{{ url_for('static', filename='apple-touch-icon.png') }}">
<meta name="apple-mobile-web-app-title" content="Timtabla">
<link rel="manifest" href="{{ url_for('static', filename='site.webmanifest') }}">
<meta charset="UTF-8">
<title>Timtabla{% if page_title|trim %} - {{ page_title|trim }}{% endif %}</title>
<link rel="stylesheet" href="{{ url_for('static', filename='styles.css') }}">
{% block head %}{% endblock %}
</head>
<body>
</body>
{% block body %}{% endblock %}
</html>

View File

@@ -1,96 +0,0 @@
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="icon" type="image/png" sizes="96x96" href="{{ url_for('static', filename='favicon-96x96.png') }}">
<link rel="icon" type="image/svg+xml" href="{{ url_for('static', filename='favicon.svg') }}">
<link rel="shortcut icon" href="{{ url_for('static', filename='favicon.ico') }}">
<link rel="apple-touch-icon" sizes="180x180" href="{{ url_for('static', filename='apple-touch-icon.png') }}">
<meta name="apple-mobile-web-app-title" content="Timtabla">
<link rel="manifest" href="{{ url_for('static', filename='site.webmanifest') }}">
<meta charset="UTF-8">
<title>Timtabla</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 0;
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
background: linear-gradient(135deg, #03551B, #0b3c5d);
}
.login-box {
background:white;
padding:30px;
border-radius:8px;
box-shadow:0 0 10px rgba(0,0,0,0.1);
width:300px;
}
input {
width:100%;
padding:8px;
margin:8px 0;
}
button {
width:100%;
padding:10px;
background:#0066cc;
color:white;
border:none;
cursor:pointer;
}
button:hover {
background:#004999;
}
.error {
color:red;
margin-top:10px;
}
</style>
</head>
<body>
<div class="login-box">
<h2>Login to Download</h2>
<input type="text" id="username" placeholder="Username" required>
<input type="password" id="password" placeholder="Password" required>
<button onclick="loginAndDownload()">Login & Download</button>
<div class="error" id="errorMsg"></div>
</div>
<script>
async function loginAndDownload() {
const username = document.getElementById("username").value;
const password = document.getElementById("password").value;
const errorMsg = document.getElementById("errorMsg");
errorMsg.textContent = "";
try {
const response = await fetch("/login-and-download", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ username, password })
});
if (!response.ok) {
throw new Error("Invalid login or server error");
}
const blob = await response.blob();
const url = window.URL.createObjectURL(blob);
const a = document.createElement("a");
a.href = url;
a.download = "timetable.ics";
document.body.appendChild(a);
a.click();
a.remove();
window.URL.revokeObjectURL(url);
} catch (err) {
errorMsg.textContent = err.message;
}
}
</script>
</body>
</html>

16
templates/login.jinja Normal file
View File

@@ -0,0 +1,16 @@
{%set page_title = "Login"%}
{% extends "base.jinja" %}
{% block body %}
<form class="login-box" method="POST" action="/login-and-download">
<h2>Coventry University Login</h2>
<input type="text" name="username" placeholder="Username" required>
<input type="password" name="password" placeholder="Password" required>
<button type="submit">Login & Download</button>
<!-- Optional: server can re-render this with an error message -->
{% if error|trim %}<div class="error">{{error}}</div>{% endif %}
</form>
{% endblock %}