Browse Source

Sends emails trim and lower case

pull/7363/head
Timshel 6 days ago
parent
commit
daf6f7780a
  1. 2
      src/api/core/sends.rs
  2. 8
      src/auth/send.rs
  3. 2
      src/db/models/send.rs

2
src/api/core/sends.rs

@ -535,7 +535,7 @@ async fn update_send_from_data(
send.expiration_date = data.expiration_date.map(|d| d.naive_utc());
send.hide_email = data.hide_email.unwrap_or(false);
send.disabled = data.disabled;
send.emails = data.emails.map(|e| e.to_lowercase());
send.emails = data.emails.map(|e| e.trim().to_lowercase()).filter(|e| !e.is_empty());
// Only change the value if it's present
if let Some(password) = data.password {

8
src/auth/send.rs

@ -104,8 +104,8 @@ impl SendTokens {
if let Some(mut split) = send.emails.as_ref().map(|s| s.split(',')) {
let now = Utc::now().naive_utc();
match email.as_ref() {
Some(e) if split.any(|s| s == e) => {
match email.map(|e| e.trim().to_lowercase()) {
Some(e) if split.any(|s| s.trim() == e) => {
if let Some(code) = otp {
if let Some(db_otp) = o_otp {
if crypto::ct_eq(&code, &db_otp.code) && now < db_otp.expiration_date {
@ -124,8 +124,8 @@ impl SendTokens {
} else {
// SEND OTP CODE
let code = crypto::generate_email_token(CONFIG.email_token_size());
SendOTP::new(send_id, e, code.clone()).save(conn).await?;
mail::send_sends_otp(e, &code).await?;
SendOTP::new(send_id, &e, code.clone()).save(conn).await?;
mail::send_sends_otp(&e, &code).await?;
}
return Self::expected_error("Email OTP required", "email_and_otp_required");
}

2
src/db/models/send.rs

@ -102,7 +102,7 @@ impl Send {
max_access_count,
access_count: 0,
emails: emails.map(|e| e.to_lowercase()),
emails: emails.map(|e| e.trim().to_lowercase()).filter(|e| !e.is_empty()),
creation_date: now,
revision_date: now,

Loading…
Cancel
Save