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 --- src/frontend/mod.rs | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) (limited to 'src/frontend/mod.rs') diff --git a/src/frontend/mod.rs b/src/frontend/mod.rs index 42e8754..c4a86b4 100644 --- a/src/frontend/mod.rs +++ b/src/frontend/mod.rs @@ -239,15 +239,16 @@ pub async fn homepage( Host(host): Host, Query(query): Query, State(db): State, + session: Option ) -> impl IntoResponse { - let user = None; // TODO authentication // This is stupid, but there is no other way. let hcard_url: url::Url = format!("https://{}/", host).parse().unwrap(); let feed_path = format!("https://{}/feeds/main", host); + let user = session.as_ref().map(|s| &s.0.me); match tokio::try_join!( - get_post_from_database(&db, &hcard_url.as_str(), None, user.as_ref()), - get_post_from_database(&db, &feed_path, query.after, user.as_ref()) + get_post_from_database(&db, &hcard_url.as_str(), None, user), + get_post_from_database(&db, &feed_path, query.after, user) ) { Ok(((hcard, _), (hfeed, cursor))) => { // Here, we know those operations can't really fail @@ -275,7 +276,7 @@ pub async fn homepage( title: blogname.as_ref(), blog_name: blogname.as_ref(), feeds: channels, - user: user.as_ref().map(url::Url::to_string), + user: session.as_deref(), content: MainPage { feed: &hfeed, card: &hcard, @@ -316,7 +317,7 @@ pub async fn homepage( title: blogname.as_ref(), blog_name: blogname.as_ref(), feeds: channels, - user: user.as_ref().map(url::Url::to_string), + user: session.as_deref(), content: ErrorPage { code: err.code(), msg: Some(err.msg().to_string()), @@ -335,16 +336,17 @@ pub async fn catchall( State(db): State, Host(host): Host, Query(query): Query, + session: Option, uri: Uri, ) -> impl IntoResponse { - let user: Option = None; // TODO authentication + let user: Option<&url::Url> = session.as_deref().map(|p| &p.me); // TODO authentication let host = url::Url::parse(&format!("https://{}/", host)).unwrap(); let path = host .clone() .join(uri.path()) .unwrap(); - match get_post_from_database(&db, path.as_str(), query.after, user.as_ref()).await { + match get_post_from_database(&db, path.as_str(), query.after, user).await { Ok((post, cursor)) => { let (blogname, channels) = tokio::join!( db.get_setting::(&host) @@ -363,7 +365,7 @@ pub async fn catchall( title: blogname.as_ref(), blog_name: blogname.as_ref(), feeds: channels, - user: user.as_ref().map(url::Url::to_string), + user: session.as_deref(), content: match post.pointer("/type/0").and_then(|i| i.as_str()) { Some("h-entry") => Entry { post: &post }.to_string(), Some("h-feed") => Feed { feed: &post, cursor: cursor.as_deref() }.to_string(), @@ -393,7 +395,7 @@ pub async fn catchall( title: blogname.as_ref(), blog_name: blogname.as_ref(), feeds: channels, - user: user.as_ref().map(url::Url::to_string), + user: session.as_deref(), content: ErrorPage { code: err.code(), msg: Some(err.msg().to_owned()), -- cgit 1.4.1