diff options
| author | metamuffin <metamuffin@disroot.org> | 2026-03-01 20:18:05 +0100 |
|---|---|---|
| committer | metamuffin <metamuffin@disroot.org> | 2026-03-01 20:18:05 +0100 |
| commit | 26c362a32a0856e912e95ac5f87c0241b36d5e2b (patch) | |
| tree | 4fd04fa3ad2d6774a9bea8bb539f3077aae1a8ce /server | |
| parent | 3af24f1c662e5bca365a2f46191f56a5159135ed (diff) | |
| download | jellything-26c362a32a0856e912e95ac5f87c0241b36d5e2b.tar jellything-26c362a32a0856e912e95ac5f87c0241b36d5e2b.tar.bz2 jellything-26c362a32a0856e912e95ac5f87c0241b36d5e2b.tar.zst | |
display login errors as flash
Diffstat (limited to 'server')
| -rw-r--r-- | server/src/ui/account/mod.rs | 38 | ||||
| -rw-r--r-- | server/src/ui/admin/users.rs | 3 |
2 files changed, 25 insertions, 16 deletions
diff --git a/server/src/ui/account/mod.rs b/server/src/ui/account/mod.rs index 9e5fa39..df8bec5 100644 --- a/server/src/ui/account/mod.rs +++ b/server/src/ui/account/mod.rs @@ -7,13 +7,11 @@ pub mod settings; -use super::error::MyError; use crate::{ auth::{hash_password, login}, request_info::RequestInfo, ui::error::MyResult, }; -use anyhow::anyhow; use jellycommon::{ jellyobject::Path, routes::{u_account_login, u_home}, @@ -64,14 +62,25 @@ pub fn r_account_login_post( ri: RequestInfo<'_>, jar: &CookieJar, form: Form<Contextual<LoginForm>>, -) -> MyResult<Either<Redirect, RawHtml<String>>> { +) -> MyResult<Either<Redirect, Either<Flash<Redirect>, RawHtml<String>>>> { let form = match &form.value { Some(v) => v, - None => return Err(MyError(anyhow!(format_form_error(form)))), + None => { + return Ok(Either::Right(Either::Left(Flash::error( + Redirect::to(u_account_login()), + format_form_error(form), + )))); + } + }; + let (session, need_pw_change) = match login(&ri.state, &form.username, &form.password, None) { + Ok(x) => x, + Err(e) => { + return Ok(Either::Right(Either::Left(Flash::error( + Redirect::to(u_account_login()), + format!("{e:#}"), + )))); + } }; - - let (session, need_pw_change) = login(&ri.state, &form.username, &form.password, None)?; - if need_pw_change { if let Some(new_password) = &form.new_password { let password_hash = hash_password(&form.username, &new_password); @@ -92,11 +101,13 @@ pub fn r_account_login_post( Ok(()) })?; } else { - return Ok(Either::Right(ri.respond_ui(&AccountSetPassword { - ri: &ri.render_info(), - password: &form.password, - username: &form.username, - }))); + return Ok(Either::Right(Either::Right(ri.respond_ui( + &AccountSetPassword { + ri: &ri.render_info(), + password: &form.password, + username: &form.username, + }, + )))); } } @@ -107,9 +118,8 @@ pub fn r_account_login_post( #[post("/account/logout")] pub fn r_account_logout_post(jar: &CookieJar) -> MyResult<Flash<Redirect>> { jar.remove(Cookie::build("session")); - Ok(Flash::new( + Ok(Flash::success( Redirect::found(u_account_login()), - "success", "Logged out!", )) } diff --git a/server/src/ui/admin/users.rs b/server/src/ui/admin/users.rs index 4b11279..f5fef24 100644 --- a/server/src/ui/admin/users.rs +++ b/server/src/ui/admin/users.rs @@ -71,9 +71,8 @@ pub fn r_admin_new_user(ri: RequestInfo, form: Form<NewUser>) -> MyResult<Flash< Ok(()) })?; - Ok(Flash::new( + Ok(Flash::success( Redirect::to(u_admin_users()), - "success", format!("User created; password: {password}"), )) } |