diff options
Diffstat (limited to 'src/index.rs')
| -rw-r--r-- | src/index.rs | 54 |
1 files changed, 35 insertions, 19 deletions
diff --git a/src/index.rs b/src/index.rs index 98eb47f..a716af2 100644 --- a/src/index.rs +++ b/src/index.rs @@ -1,40 +1,56 @@ use axum::{response::IntoResponse, routing::get, Router}; +use sqlx::sqlite::SqlitePool; -pub fn router<S>() -> Router<S> -where - S: Send + Sync + Clone + 'static, -{ +use crate::login::repo::logins::Login; + +pub fn router() -> Router<SqlitePool> { Router::new().route("/", get(index)) } -async fn index() -> impl IntoResponse { - templates::index() +async fn index(login: Option<Login>) -> impl IntoResponse { + templates::index(login) } mod templates { use maud::{html, Markup, DOCTYPE}; - pub fn index() -> Markup { + + use crate::login::repo::logins::Login; + + pub fn index(login: Option<Login>) -> Markup { html! { (DOCTYPE) head { title { "hi" } } body { - form action="/login" method="post" { - label { - "name" - input name="name" type="text" {} - } - label { - "password" - input name="password" type="password" {} - } - button { "hi" } + @match login { + None => { (login_form()) } + Some(login) => { (logout_form(&login.name)) } } + } + } + } - form action="/logout" method="post" { - button { "bye" } + fn login_form() -> Markup { + html! { + form action="/login" method="post" { + label { + "name" + input name="name" type="text" {} } + label { + "password" + input name="password" type="password" {} + } + button { "hi" } + } + } + } + + fn logout_form(name: &str) -> Markup { + html! { + form action="/logout" method="post" { + button { "bye, " (name) } } } } |
