diff options
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>)) } |