From e43313210269b8e48fe35b17ac416c9ba88ae4f3 Mon Sep 17 00:00:00 2001 From: Vika Date: Sun, 18 Aug 2024 00:30:15 +0300 Subject: feat: logins!! yes you can finally sign in this is also supposed to show private posts intended for you! maybe i can also reveal my email to those who sign in! :3 --- templates/src/indieauth.rs | 31 +++++++++---------------------- templates/src/lib.rs | 2 +- templates/src/login.rs | 14 ++++++++++++++ templates/src/templates.rs | 17 +++++++++++------ 4 files changed, 35 insertions(+), 29 deletions(-) (limited to 'templates') diff --git a/templates/src/indieauth.rs b/templates/src/indieauth.rs index 155b580..5f92196 100644 --- a/templates/src/indieauth.rs +++ b/templates/src/indieauth.rs @@ -1,11 +1,13 @@ -use kittybox_indieauth::{AuthorizationRequest, Scope}; +use kittybox_indieauth::{AuthorizationRequest, ClientMetadata, Scope}; use kittybox_util::auth::EnrolledCredential; +const INDIEAUTH_SPEC: &str = "https://indieauth.spec.indieweb.org/20240711/#authorization-request"; + markup::define! { AuthorizationRequestPage( request: AuthorizationRequest, credentials: Vec, - app: Option, + app: ClientMetadata, user: serde_json::Value ) { script[type="module"] { @@ -37,27 +39,12 @@ document.getElementById("indieauth_page").addEventListener("submit", submit_hand } p."mini-h-card" { - @if let Some(icon) = app - .as_ref() - .and_then(|app| app["properties"]["logo"][0].as_str()) - { - img.app_icon[src=icon]; - } else if let Some(icon) = app - .as_ref() - .and_then(|app| app["properties"]["logo"][0].as_object()) - { - img.app_icon[src=icon["src"].as_str().unwrap(), alt=icon["alt"].as_str().unwrap()]; + @if let Some(icon) = app.logo_uri.as_ref() { + img.app_icon[src=icon.as_str()]; } span { - a[href=app - .as_ref() - .and_then(|app| app["properties"]["url"][0].as_str()) - .unwrap_or_else(|| request.client_id.as_str()) - ] { - @app - .as_ref() - .and_then(|app| app["properties"]["name"][0].as_str()) - .unwrap_or_else(|| request.client_id.as_str()) + a[href=app.client_uri.as_str()] { + @app.client_name.as_deref().unwrap_or_else(|| request.client_id.as_str()) } " wants to confirm your identity." } @@ -152,7 +139,7 @@ document.getElementById("indieauth_page").addEventListener("submit", submit_hand p { "More info about meanings of these fields can be found in " - a[href="https://indieauth.spec.indieweb.org/20220212/#authorization-request"] { + a[href=INDIEAUTH_SPEC] { "the IndieAuth specification" } ", which this webpage uses." } diff --git a/templates/src/lib.rs b/templates/src/lib.rs index b7b9a24..81b1a60 100644 --- a/templates/src/lib.rs +++ b/templates/src/lib.rs @@ -5,7 +5,7 @@ pub use onboarding::OnboardingPage; mod indieauth; pub use indieauth::AuthorizationRequestPage; mod login; -pub use login::LoginPage; +pub use login::{LoginPage, LogoutPage}; mod mf2; pub use mf2::{Entry, VCard, Feed, Food, POSTS_PER_PAGE}; diff --git a/templates/src/login.rs b/templates/src/login.rs index 042c308..ed5dc4e 100644 --- a/templates/src/login.rs +++ b/templates/src/login.rs @@ -14,4 +14,18 @@ markup::define! { } } } + + LogoutPage { + script[type="module"] { + @markup::raw(r#"const form = document.getElementById("logout"); +form.submit(); +"#) + } + form[id="logout", method="POST"] { + p { "You will be logged out automatically if you have JavaScript on." } + noscript { p { "However, you don't seem to have it running. No worries, just press the button to be logged out." } } + + input[type="submit", value="Sign out"]; + } + } } diff --git a/templates/src/templates.rs b/templates/src/templates.rs index 4f7970c..3d22eac 100644 --- a/templates/src/templates.rs +++ b/templates/src/templates.rs @@ -1,10 +1,9 @@ use http::StatusCode; use kittybox_util::MicropubChannel; - use crate::{Feed, VCard}; markup::define! { - Template<'a>(title: &'a str, blog_name: &'a str, feeds: Vec, user: Option, content: String) { + Template<'a>(title: &'a str, blog_name: &'a str, feeds: Vec, user: Option<&'a kittybox_indieauth::ProfileUrl>, content: String) { @markup::doctype() html { head { @@ -41,12 +40,18 @@ markup::define! { li { a[href=&feed.uid] { @feed.name } } } li.shiftright { - @if user.is_none() { - a #login[href="/login/start"] { "Sign in" } - } else { + @if let Some(user) = &user { span { - @user.as_ref().unwrap() " - " a #logout[href="/logout"] { "Sign out" } + @if let Some(kittybox_indieauth::Profile { name: Some(name), photo, .. }) = &user.profile { + a[href=user.me.as_str()] { @name } + } else { + @user.me.as_str() + } + " - " + a #logout[href="/.kittybox/login/logout"] { "Sign out" } } + } else { + a #login[href="/.kittybox/login/start"] { "Sign in" } } } } -- cgit 1.4.1