Skip to content

Commit

Permalink
fix: bug, allow empty email is registration when it's optional
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
josecelano committed Jul 9, 2024
1 parent e0dbdbe commit 4fbeead
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/services/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,21 @@ impl RegistrationService {
if email.required && registration_form.email.is_none() {
return Err(ServiceError::EmailMissing);
}
registration_form.email.clone()
match &registration_form.email {
Some(email) => {
if email.trim() == String::new() {
None
} else {
Some(email.clone())
}
}
None => None,
}
}
None => None,
};

if let Some(email) = &registration_form.email {
if let Some(email) = &opt_email {
if !validate_email_address(email) {
return Err(ServiceError::EmailInvalid);
}
Expand Down

0 comments on commit 4fbeead

Please sign in to comment.