From 4fbeead9e641b81e68bd80d592066ec9411f87b2 Mon Sep 17 00:00:00 2001 From: Jose Celano Date: Tue, 9 Jul 2024 16:50:41 +0100 Subject: [PATCH] fix: bug, allow empty email is registration when it's optional If the email in the registration form is optional the application should allow not validate it when it's emtpy. It should only validate the email when is not empty. We only make sure that if present is a valid email. --- src/services/user.rs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/services/user.rs b/src/services/user.rs index ff885dcd..63560642 100644 --- a/src/services/user.rs +++ b/src/services/user.rs @@ -87,12 +87,21 @@ impl RegistrationService { if email.required && registration_form.email.is_none() { return Err(ServiceError::EmailMissing); } - registration_form.email.clone() + match ®istration_form.email { + Some(email) => { + if email.trim() == String::new() { + None + } else { + Some(email.clone()) + } + } + None => None, + } } None => None, }; - if let Some(email) = ®istration_form.email { + if let Some(email) = &opt_email { if !validate_email_address(email) { return Err(ServiceError::EmailInvalid); }