diff options
author | Vika <vika@fireburn.ru> | 2025-04-20 08:25:57 +0300 |
---|---|---|
committer | Vika <vika@fireburn.ru> | 2025-04-20 10:01:01 +0300 |
commit | 3207c8ea57eac714417494e06ce0f82864b7ff1e (patch) | |
tree | 70cfde719dd596dbe05d38276526e763d55eac1d /src/login.rs | |
parent | b3288627d171fff9a289a56a4ae27307985f9f96 (diff) | |
download | kittybox-3207c8ea57eac714417494e06ce0f82864b7ff1e.tar.zst |
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
Diffstat (limited to 'src/login.rs')
-rw-r--r-- | src/login.rs | 28 |
1 files changed, 22 insertions, 6 deletions
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<S: Storage + Send + Sync + 'static>( @@ -32,9 +32,11 @@ async fn get<S: Storage + Send + Sync + 'static>( ) -> 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::<crate::database::settings::SiteName>(&hcard_url) .map(Result::unwrap_or_default), + db.get_setting::<crate::database::settings::Theme>(&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<S: Storage + Send + Sync + 'static>( 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<D: Storage + 'static>( + State(db): State<D>, + 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::<crate::database::settings::SiteName>(&me) + .map(Result::unwrap_or_default), + db.get_setting::<crate::database::settings::Theme>(&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::<S>).post(post)) .route("/finish", axum::routing::get(callback)) - .route("/logout", axum::routing::get(logout_page).post(logout)) + .route("/logout", axum::routing::get(logout_page::<S>).post(logout)) .route("/client_metadata", axum::routing::get(client_metadata::<S>)) } |