14223e7feat: claim, sign in, and sign out through the browser1mo | 1 | use topcoat::{ |
| 2 | Result, |
| 3 | context::Cx, |
| 4 | router::{error::redirect, page}, |
| 5 | view::view, |
| 6 | }; |
| 7 | |
| 8 | use crate::domain::Actor; |
| 9 | |
| 10 | use super::context::{claimed, current_actor}; |
| 11 | |
| 12 | |
| 13 | |
| 14 | |
| 15 | |
| 16 | #[page("/")] |
| 17 | async fn home(cx: &Cx) -> Result { |
| 18 | if !claimed(cx).await? { |
| 19 | return Err(redirect("/setup").into()); |
| 20 | } |
| 21 | |
| 22 | let actor = current_actor(cx).await?; |
| 23 | |
| 24 | view! { |
| 25 | <h1>"steid"</h1> |
| 26 | (match &actor { |
| 27 | Actor::User(id) => view! { |
| 28 | <p>"Signed in as " <code>(id.as_str())</code></p> |
| 29 | <form method="post" action="/logout"> |
| 30 | <button type="submit">"Sign out"</button> |
| 31 | </form> |
| 32 | }, |
| 33 | Actor::Anonymous => view! { |
| 34 | <p>"Not signed in."</p> |
| 35 | <p><a href="/login">"Sign in"</a></p> |
| 36 | }, |
| 37 | }?) |
| 38 | } |
| 39 | } |