From bdcc10bd40fa1910d12afde6c63fa8d85a81fceb Mon Sep 17 00:00:00 2001 From: filipriec Date: Fri, 18 Apr 2025 17:08:38 +0200 Subject: [PATCH] auth verification of emptiness --- client/src/tui/functions/common/login.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/client/src/tui/functions/common/login.rs b/client/src/tui/functions/common/login.rs index 5a602be..206c5f4 100644 --- a/client/src/tui/functions/common/login.rs +++ b/client/src/tui/functions/common/login.rs @@ -21,6 +21,20 @@ pub async fn save( let identifier = login_state.username.clone(); let password = login_state.password.clone(); + // --- Client-side validation --- + // Prevent login attempt if the identifier field is empty or whitespace. + if identifier.trim().is_empty() { + let error_message = "Username/Email cannot be empty.".to_string(); + app_state.show_dialog( + "Login Failed", + &error_message, + vec!["OK".to_string()], + DialogPurpose::LoginFailed, + ); + login_state.error_message = Some(error_message.clone()); + return Ok(error_message); + } + // Clear previous error/dialog state before attempting login_state.error_message = None; app_state.hide_dialog(); // Hide any previous dialog @@ -54,6 +68,7 @@ pub async fn save( DialogPurpose::LoginSuccess, ); login_state.password.clear(); + login_state.username.clear(); login_state.current_cursor_pos = 0; Ok("Login successful, details shown in dialog.".to_string()) } @@ -67,6 +82,8 @@ pub async fn save( ); login_state.error_message = Some(error_message.clone()); login_state.set_has_unsaved_changes(true); + login_state.username.clear(); + login_state.password.clear(); Ok(format!("Login failed: {}", error_message)) } }