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