diff options
Diffstat (limited to 'server/src/routes')
-rw-r--r-- | server/src/routes/ui/account/mod.rs | 31 | ||||
-rw-r--r-- | server/src/routes/ui/account/settings.rs | 3 |
2 files changed, 25 insertions, 9 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() }), diff --git a/server/src/routes/ui/account/settings.rs b/server/src/routes/ui/account/settings.rs index 625ae7f..66a4f88 100644 --- a/server/src/routes/ui/account/settings.rs +++ b/server/src/routes/ui/account/settings.rs @@ -7,7 +7,7 @@ use super::{format_form_error, hash_password}; use crate::{ database::Database, routes::ui::{ - account::session::Session, + account::{rocket_uri_macro_r_account_login, session::Session}, error::MyResult, layout::{DynLayoutPage, LayoutPage}, }, @@ -49,6 +49,7 @@ fn settings_page(session: Session, flash: Option<MyResult<String>>) -> DynLayout } } h2 { "Account" } + a.switch_account[href=uri!(r_account_login())] { "Switch Account" } form[method="POST", action=uri!(r_account_settings_post())] { label[for="username"] { "Username" } input[type="text", id="username", disabled, value=&session.user.name]; |