From 3207c8ea57eac714417494e06ce0f82864b7ff1e Mon Sep 17 00:00:00 2001 From: Vika Date: Sun, 20 Apr 2025 08:25:57 +0300 Subject: WIP: Theme support Kittybox can now ship with several different stylesheets, provided by the renderer. Unknown stylesheets fall back to the default one, which is the same Kittybox has shipped since its inception. There's also a settings field for custom CSS, but it's not exposed anywhere yet. Change-Id: I2850dace5c40f9fed04b4651c551a861df5b83d3 --- src/login.rs | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) (limited to 'src/login.rs') diff --git a/src/login.rs b/src/login.rs index 3038d9c..1b6a6f3 100644 --- a/src/login.rs +++ b/src/login.rs @@ -23,7 +23,7 @@ use kittybox_frontend_renderer::{LoginPage, LogoutPage, Template}; use kittybox_indieauth::{AuthorizationResponse, Error, GrantType, PKCEVerifier, Scope, Scopes}; use sha2::Digest; -use crate::database::Storage; +use crate::database::{settings::Setting, Storage}; /// Show a login page. async fn get( @@ -32,9 +32,11 @@ async fn get( ) -> impl axum::response::IntoResponse { let hcard_url: url::Url = format!("https://{}/", host).parse().unwrap(); - let (blogname, channels) = tokio::join!( + let (blogname, theme, channels) = tokio::join!( db.get_setting::(&hcard_url) .map(Result::unwrap_or_default), + db.get_setting::(&hcard_url) + .map(Result::unwrap_or_default), db.get_channels(&hcard_url).map(|i| i.unwrap_or_default()) ); ( @@ -47,6 +49,7 @@ async fn get( title: "Sign in with your website", blog_name: blogname.as_ref(), feeds: channels, + theme: theme.into_inner(), user: None, content: LoginPage {}.to_string(), } @@ -380,14 +383,27 @@ async fn callback( /// of crawlers working with a user's cookies (wget?). If a crawler is /// stupid enough to execute JS and send a POST request though, that's /// on the crawler. -async fn logout_page() -> impl axum::response::IntoResponse { +async fn logout_page( + State(db): State, + Host(host): Host, +) -> impl axum::response::IntoResponse { + let me: url::Url = format!("https://{host}/").parse().unwrap(); + let (blog_name, theme, channels) = tokio::join!( + db.get_setting::(&me) + .map(Result::unwrap_or_default), + db.get_setting::(&me) + .map(Result::unwrap_or_default), + db.get_channels(&me).map(|i| i.unwrap_or_default()) + ); + ( StatusCode::OK, [("Content-Type", "text/html")], Template { title: "Signing out...", - blog_name: "Kittybox", - feeds: vec![], + blog_name: blog_name.as_ref(), + theme: theme.into_inner(), + feeds: channels, user: None, content: LogoutPage {}.to_string(), } @@ -501,6 +517,6 @@ where axum::routing::Router::new() .route("/start", axum::routing::get(get::).post(post)) .route("/finish", axum::routing::get(callback)) - .route("/logout", axum::routing::get(logout_page).post(logout)) + .route("/logout", axum::routing::get(logout_page::).post(logout)) .route("/client_metadata", axum::routing::get(client_metadata::)) } -- cgit 1.4.1