diff --git a/.gitignore b/.gitignore index 64aadb7..0a1abd8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ backend/target backend/db +backend/db/db.sqlite3 diff --git a/backend/Cargo.lock b/backend/Cargo.lock index 4bfa366..4e55654 100644 --- a/backend/Cargo.lock +++ b/backend/Cargo.lock @@ -122,6 +122,17 @@ dependencies = [ "percent-encoding", ] +[[package]] +name = "askama_axum" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a41603f7cdbf5ac4af60760f17253eb6adf6ec5b6f14a7ed830cf687d375f163" +dependencies = [ + "askama", + "axum-core", + "http 1.1.0", +] + [[package]] name = "askama_derive" version = "0.12.5" @@ -1317,6 +1328,7 @@ name = "jean-marie" version = "0.1.1" dependencies = [ "askama", + "askama_axum", "axum", "axum-extra", "axum-server", @@ -1326,7 +1338,6 @@ dependencies = [ "dotenvy", "headers", "http 1.1.0", - "minijinja", "oauth2", "reqwest 0.12.7", "serde", @@ -1442,12 +1453,6 @@ version = "2.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" -[[package]] -name = "memo-map" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38d1115007560874e373613744c6fba374c17688327a71c1476d1a5954cc857b" - [[package]] name = "mime" version = "0.3.17" @@ -1464,17 +1469,6 @@ dependencies = [ "unicase", ] -[[package]] -name = "minijinja" -version = "2.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1028b628753a7e1a88fc59c9ba4b02ecc3bc0bd3c7af23df667bc28df9b3310e" -dependencies = [ - "memo-map", - "self_cell", - "serde", -] - [[package]] name = "minimal-lexical" version = "0.2.1" @@ -1794,9 +1788,9 @@ dependencies = [ [[package]] name = "pkg-config" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec" +checksum = "953ec861398dccce10c670dfeaf3ec4911ca479e9c02154b3a215178c5f566f2" [[package]] name = "polyval" @@ -2195,12 +2189,6 @@ dependencies = [ "libc", ] -[[package]] -name = "self_cell" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d369a96f978623eb3dc28807c4852d6cc617fed53da5d3c400feff1ef34a714a" - [[package]] name = "serde" version = "1.0.210" @@ -2662,18 +2650,18 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.63" +version = "1.0.64" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c0342370b38b6a11b6cc11d6a805569958d54cfa061a29969c3b5ce2ea405724" +checksum = "d50af8abc119fb8bb6dbabcfa89656f46f84aa0ac7688088608076ad2b459a84" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.63" +version = "1.0.64" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4558b58466b9ad7ca0f102865eccc95938dca1a74a856f2b57b6629050da261" +checksum = "08904e7672f5eb876eaaf87e0ce17857500934f4981c4a0ab2b4aa98baac7fc3" dependencies = [ "proc-macro2", "quote", @@ -2854,9 +2842,9 @@ dependencies = [ [[package]] name = "tower-http" -version = "0.6.0" +version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "41515cc9e193536d93fd0dbbea0c73819c08eca76e0b30909a325c3ec90985bb" +checksum = "8437150ab6bbc8c5f0f519e3d5ed4aa883a83dd4cdd3d1b21f9482936046cb97" dependencies = [ "async-compression", "base64 0.22.1", diff --git a/backend/Cargo.toml b/backend/Cargo.toml index 1b0a63e..58cc602 100644 --- a/backend/Cargo.toml +++ b/backend/Cargo.toml @@ -11,17 +11,17 @@ axum = { version = "0.7.6" } axum_session = { version = "0.14.2" } axum-server = { version = "0.7.1" } axum-extra = { version = "0.9.4", features = ["cookie-private", "typed-header"] } +askama = "0.12.0" +askama_axum = "0.4.0" headers = "0.4" serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" tokio = { version = "1.40", features = ["full"] } tracing = "0.1" tracing-subscriber = { version="0.3", features = ["env-filter"] } -askama = "0.12" -minijinja = { version = "2", features = ["loader"] } oauth2 = "4.4" http = "1.1" -tower-http = { version = "0.6.0", features = ["full"] } +tower-http = { version = "0.6.1", features = ["full"] } chrono = { version = "0.4.38", features = ["serde"] } sqlx = { version = "0.8", features = ["sqlite", "runtime-tokio"] } uuid = { version = "1.10", features = ["v4"] } diff --git a/backend/db/db.sqlite3-shm b/backend/db/db.sqlite3-shm deleted file mode 100644 index c2ea797..0000000 Binary files a/backend/db/db.sqlite3-shm and /dev/null differ diff --git a/backend/db/db.sqlite3-wal b/backend/db/db.sqlite3-wal deleted file mode 100644 index 1cb50c0..0000000 Binary files a/backend/db/db.sqlite3-wal and /dev/null differ diff --git a/backend/src/error_handling.rs b/backend/src/error_handling.rs index 9731ae3..1bd14c1 100644 --- a/backend/src/error_handling.rs +++ b/backend/src/error_handling.rs @@ -58,8 +58,8 @@ impl IntoResponse for AppError { } } -impl From for AppError { - fn from(err: minijinja::Error) -> Self { +impl From for AppError { + fn from(err: askama_axum::Error) -> Self { AppError::new(format!("Template error: {:#}", err)) } } diff --git a/backend/src/main.rs b/backend/src/main.rs index 718d18e..d5abb1a 100644 --- a/backend/src/main.rs +++ b/backend/src/main.rs @@ -1,5 +1,5 @@ use std::net::SocketAddr; -use askama::Template; +use askama_axum::Template; use axum::{ middleware, response::{Html, IntoResponse, Response}, routing::{get, get_service}, Extension, Router }; @@ -78,9 +78,13 @@ async fn main() { // build our application with some routes let app = Router::new() + //Routes that require authentication .route("/logout", get(logout)) .route("/profile", get(profile)) + .route("/useradmin", get(useradmin)) .route_layer(middleware::from_fn_with_state(app_state.clone(), check_auth)) + + //Routes that don't require authentication .nest_service("/assets", ServeDir::new("templates/assets") .fallback(get_service(ServeDir::new("templates/assets")))) .route("/", get(index)) diff --git a/backend/src/routes.rs b/backend/src/routes.rs index 7286af9..37681b8 100644 --- a/backend/src/routes.rs +++ b/backend/src/routes.rs @@ -1,4 +1,4 @@ -use askama::Template; +use askama_axum::Template; use axum::{response::IntoResponse, Extension}; use http::Request; @@ -21,4 +21,23 @@ pub async fn profile( let template = ProfileTemplate { logged_in, name}; HtmlTemplate(template) +} + +#[derive(Template)] +#[template(path = "useradmin.html")] +struct UserAdminTemplate { + logged_in: bool, + name: String, +} + +pub async fn useradmin( + Extension(user_data): Extension>, + _request: Request, +) -> impl IntoResponse { + let user_email = user_data.map(|s| s.user_email); + let logged_in = user_email.is_some(); + let name = user_email.unwrap_or_default(); + + let template = UserAdminTemplate { logged_in, name}; + HtmlTemplate(template) } \ No newline at end of file diff --git a/backend/templates/useradmin.html b/backend/templates/useradmin.html new file mode 100644 index 0000000..15e071b --- /dev/null +++ b/backend/templates/useradmin.html @@ -0,0 +1,6 @@ +{% extends "base.html" %} +{% block title %}User Profile{% endblock %} +{% block content %} +This is the user administration page.
+Your email address: {{ name }}. +{% endblock %} \ No newline at end of file