Askama + htmx for frontend

Server-side rendering with htmx and Tailwind CSS for the styling
This commit is contained in:
Alphonse Paix
2025-09-16 01:47:18 +02:00
parent 7c8ac0361e
commit 8a977df948
9 changed files with 402 additions and 36 deletions

View File

@@ -4,6 +4,7 @@ use crate::{
session_state::TypedSession,
startup::AppState,
};
use askama::Template;
use axum::{
Form, Json,
extract::State,
@@ -50,18 +51,25 @@ impl IntoResponse for LoginError {
}
}
#[derive(Template)]
#[template(path = "../templates/login.html")]
struct LoginTemplate {
error_html: String,
}
#[derive(serde::Deserialize)]
pub struct LoginFormData {
username: String,
password: SecretString,
}
pub async fn get_login(messages: Messages) -> impl IntoResponse {
pub async fn get_login(messages: Messages) -> Html<String> {
let mut error_html = String::new();
for message in messages {
writeln!(error_html, "<p><i>{}</i></p>", message).unwrap();
}
Html(format!(include_str!("login/login.html"), error_html))
let template = LoginTemplate { error_html };
Html(template.render().unwrap())
}
pub async fn post_login(