Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(users): Convert emails to lowercase from requests #6601

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 3 additions & 16 deletions crates/router/src/types/domain/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ impl UserEmail {
pub fn new(email: Secret<String, pii::EmailStrategy>) -> UserResult<Self> {
use validator::ValidateEmail;

let email_string = email.expose();
let email_string = email.expose().to_lowercase();
let email =
pii::Email::from_str(&email_string).change_context(UserErrors::EmailParsingError)?;

Expand All @@ -123,21 +123,8 @@ impl UserEmail {
}

pub fn from_pii_email(email: pii::Email) -> UserResult<Self> {
use validator::ValidateEmail;

let email_string = email.peek();
if email_string.validate_email() {
let (_username, domain) = match email_string.split_once('@') {
Some((u, d)) => (u, d),
None => return Err(UserErrors::EmailParsingError.into()),
};
if BLOCKED_EMAIL.contains(domain) {
return Err(UserErrors::InvalidEmailError.into());
}
Ok(Self(email))
} else {
Err(UserErrors::EmailParsingError.into())
}
let email_string = email.expose().map(|inner| inner.to_lowercase());
Self::new(email_string)
}

pub fn into_inner(self) -> pii::Email {
Expand Down
Loading