Added validation of number of guests

If number of guests is 255 (which is the default value), no email will be sent
to the recepient. Most normal users have Javascript enabled, so their browser
should throw an error if the number of guests isn't filled out.
This commit is contained in:
Dennis Potter 2019-10-13 12:08:23 +02:00
parent 0fc8a03659
commit 415d759fb6
Signed by: Dennis
GPG Key ID: 186A8AD440942BAF

View File

@ -106,6 +106,15 @@ fn validate_email(email: &String) -> bool {
Regex::new(r"^[a-zA-Z0-9\.\-_]+@[a-zA-Z0-9\-\.]+\.[a-zA-Z]+$").unwrap().is_match(email) Regex::new(r"^[a-zA-Z0-9\.\-_]+@[a-zA-Z0-9\-\.]+\.[a-zA-Z]+$").unwrap().is_match(email)
} }
fn validate_guests(guests: &u8) -> bool {
// Check if the default number of guests (255) changed.
if guests < &255 {
true
} else {
false
}
}
fn strip_tld(url: &str) -> Option<String> { fn strip_tld(url: &str) -> Option<String> {
// Get the top level domain which is used to determine the language // Get the top level domain which is used to determine the language
@ -204,7 +213,7 @@ fn submit_task (host: HostHeader,
Some(x) => { Some(x) => {
// Check input for anything strange or something that does not look like // Check input for anything strange or something that does not look like
// an email address. // an email address.
if validate_name(&x.name) && validate_email(&x.email) { if validate_name(&x.name) && validate_email(&x.email) && validate_guests(&x.guests){
// Create HashMap to use with strfnt // Create HashMap to use with strfnt
let mut vars = HashMap::new(); let mut vars = HashMap::new();
vars.insert("name".to_string(), &x.name); vars.insert("name".to_string(), &x.name);
@ -255,7 +264,7 @@ fn submit_task (host: HostHeader,
&settings); &settings);
} }
} else { } else {
result = Err("Validate e-mail or name went wrong.".to_string()); result = Err("Validate e-mail, name, or number of guests went wrong.".to_string());
} }
// Send a message to the sender's e-mailaddres to inform about // Send a message to the sender's e-mailaddres to inform about