Refactor prelogin.rs to use default labels for username and password

This commit is contained in:
Kevin Yue 2024-05-09 01:47:05 -04:00
parent 200d13ef15
commit 159673652c

View File

@ -181,22 +181,24 @@ fn parse_res_xml(res_xml: &str, is_gateway: bool) -> anyhow::Result<Prelogin> {
return Ok(Prelogin::Saml(saml_prelogin)); return Ok(Prelogin::Saml(saml_prelogin));
} }
let label_username = xml::get_child_text(&doc, "username-label"); let label_username = xml::get_child_text(&doc, "username-label").unwrap_or_else(|| {
let label_password = xml::get_child_text(&doc, "password-label"); info!("Username label has no value, using default");
// Check if the prelogin response is standard login String::from("Username")
if label_username.is_some() && label_password.is_some() { });
let auth_message = let label_password = xml::get_child_text(&doc, "password-label").unwrap_or_else(|| {
xml::get_child_text(&doc, "authentication-message").unwrap_or(String::from("Please enter the login credentials")); info!("Password label has no value, using default");
let standard_prelogin = StandardPrelogin { String::from("Password")
region, });
is_gateway,
auth_message,
label_username: label_username.unwrap(),
label_password: label_password.unwrap(),
};
Ok(Prelogin::Standard(standard_prelogin)) let auth_message =
} else { xml::get_child_text(&doc, "authentication-message").unwrap_or(String::from("Please enter the login credentials"));
Err(anyhow!("Invalid prelogin response")) let standard_prelogin = StandardPrelogin {
} region,
is_gateway,
auth_message,
label_username,
label_password,
};
Ok(Prelogin::Standard(standard_prelogin))
} }