Skip to content

Commit 4fbeead

Browse files
committed
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.
1 parent e0dbdbe commit 4fbeead

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/services/user.rs

+11-2
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,21 @@ impl RegistrationService {
8787
if email.required && registration_form.email.is_none() {
8888
return Err(ServiceError::EmailMissing);
8989
}
90-
registration_form.email.clone()
90+
match &registration_form.email {
91+
Some(email) => {
92+
if email.trim() == String::new() {
93+
None
94+
} else {
95+
Some(email.clone())
96+
}
97+
}
98+
None => None,
99+
}
91100
}
92101
None => None,
93102
};
94103

95-
if let Some(email) = &registration_form.email {
104+
if let Some(email) = &opt_email {
96105
if !validate_email_address(email) {
97106
return Err(ServiceError::EmailInvalid);
98107
}

0 commit comments

Comments
 (0)