auth verification of emptiness

This commit is contained in:
filipriec
2025-04-18 17:08:38 +02:00
parent 2a1fafc3f9
commit bdcc10bd40

View File

@@ -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))
}
}