diff options
author | metamuffin <metamuffin@disroot.org> | 2023-12-19 10:32:52 +0100 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2023-12-19 10:32:52 +0100 |
commit | f0ad31971e53a1c1bfcca2723eea0bd1cbe9ba21 (patch) | |
tree | 28912cbb2db4d593bce69085b0ddb9a6e04a5ef1 /server/src/routes/ui/account/mod.rs | |
parent | 349f66ec59e9fcdd21959523ecabd16e5b2e471f (diff) | |
download | jellything-f0ad31971e53a1c1bfcca2723eea0bd1cbe9ba21.tar jellything-f0ad31971e53a1c1bfcca2723eea0bd1cbe9ba21.tar.bz2 jellything-f0ad31971e53a1c1bfcca2723eea0bd1cbe9ba21.tar.zst |
ui: switch account
Diffstat (limited to 'server/src/routes/ui/account/mod.rs')
-rw-r--r-- | server/src/routes/ui/account/mod.rs | 31 |
1 files changed, 23 insertions, 8 deletions
diff --git a/server/src/routes/ui/account/mod.rs b/server/src/routes/ui/account/mod.rs index 1c5b19a..543fa48 100644 --- a/server/src/routes/ui/account/mod.rs +++ b/server/src/routes/ui/account/mod.rs @@ -11,7 +11,10 @@ use std::collections::HashSet; use super::{error::MyError, layout::LayoutPage}; use crate::{ database::Database, - routes::ui::{error::MyResult, home::rocket_uri_macro_r_home, layout::DynLayoutPage}, + routes::ui::{ + account::session::Session, error::MyResult, home::rocket_uri_macro_r_home, + layout::DynLayoutPage, + }, uri, }; use anyhow::anyhow; @@ -75,22 +78,28 @@ pub struct LoginForm { } #[get("/account/login")] -pub fn r_account_login() -> DynLayoutPage<'static> { +pub fn r_account_login(sess: Option<Session>) -> DynLayoutPage<'static> { + let logged_in = sess.is_some(); + let title = if logged_in { "Switch Account" } else { "Login" }; LayoutPage { - title: "Login".to_string(), + title: title.to_string(), content: markup::new! { form.account[method="POST", action=""] { - h1 { "Login" } + h1 { @title } label[for="inp-username"] { "Username" } input[type="text", id="inp-username", name="username"]; br; label[for="inp-password"] { "Password" } input[type="password", id="inp-password", name="password"]; br; - input[type="submit", value="Login"]; + input[type="submit", value=title]; - p { "While logged in, a cookie will be used to identify you." } - p { "Don't have an account yet? " a[href=uri!(r_account_register())] { "Register here" } } + @if logged_in { + p { "Need another account? " a[href=uri!(r_account_register())] { "Register here" } } + } else { + p { "While logged in, a cookie will be used to identify you." } + p { "Don't have an account yet? " a[href=uri!(r_account_register())] { "Register here" } } + } } }, ..Default::default() @@ -114,8 +123,10 @@ pub fn r_account_logout() -> DynLayoutPage<'static> { #[post("/account/register", data = "<form>")] pub fn r_account_register_post<'a>( database: &'a State<Database>, + _sess: Option<Session>, form: Form<Contextual<'a, RegisterForm>>, ) -> MyResult<DynLayoutPage<'a>> { + let logged_in = _sess.is_some(); let form = match &form.value { Some(v) => v, None => return Err(format_form_error(form)), @@ -143,7 +154,11 @@ pub fn r_account_register_post<'a>( Ok(_) => Ok(LayoutPage { title: "Registration successful".to_string(), content: markup::new! { - h1 { "Registration successful, you may log in now." } + h1 { @if logged_in { + "Registration successful, you may switch account now." + } else { + "Registration successful, you may log in now." + }} }, ..Default::default() }), |