Skip to content

Commit

Permalink
Add delivery_email to database.
Browse files Browse the repository at this point in the history
This ensures that we have one case-insensitive email to compare against and one case-sensitive to send emails to.
  • Loading branch information
ffreddow committed Dec 18, 2024
1 parent 5800f7d commit 8e10474
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 3 deletions.
6 changes: 5 additions & 1 deletion backend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -390,16 +390,18 @@ pub(crate) mod tests {
#[actix_web::test]
async fn test_clean_verification_tokens() {
let user_id = uuid::Uuid::new_v4();
let email = format!("{}@invalid", user_id.to_string());
let user = User {
id: user_id,
name: user_id.to_string(),
email: format!("{}@invalid", user_id.to_string()),
email: email.clone(),
login_key: String::new(),
email_verified: false,
secret: Vec::new(),
secret_nonce: Vec::new(),
secret_salt: Vec::new(),
login_salt: Vec::new(),
delivery_email: Some(email),
};

let user2_id = uuid::Uuid::new_v4();
Expand All @@ -413,6 +415,7 @@ pub(crate) mod tests {
secret_nonce: Vec::new(),
secret_salt: Vec::new(),
login_salt: Vec::new(),
delivery_email: None,
};

let user3_id = uuid::Uuid::new_v4();
Expand All @@ -426,6 +429,7 @@ pub(crate) mod tests {
secret_nonce: Vec::new(),
secret_salt: Vec::new(),
login_salt: Vec::new(),
delivery_email: None,
};

let verify_id = uuid::Uuid::new_v4();
Expand Down
3 changes: 2 additions & 1 deletion backend/src/routes/auth/register.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ pub async fn register(
secret_nonce: data.secret_nonce.clone(),
login_salt: data.login_salt.clone(),
secret_salt: data.secret_salt.clone(),
delivery_email: Some(data.email.clone()),
};

let mut conn = get_connection(&state)?;
Expand Down Expand Up @@ -226,7 +227,7 @@ pub async fn register(
send_verification_mail(
user_insert.name,
verify,
mail,
data.email.clone(),
state.mailer.clone(),
state.frontend_url.clone(),
lang.into(),
Expand Down
8 changes: 7 additions & 1 deletion backend/src/routes/auth/start_recovery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,16 @@ pub async fn start_recovery(

#[cfg(not(test))]
std::thread::spawn(move || {
let email = if let Some(email) = user.delivery_email {
email
} else {
user.email
};

send_email(
user.name,
token_id,
user.email,
email,
state.mailer.clone(),
state.frontend_url.clone(),
lang.into(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- This file should undo anything in `up.sql`
ALTER TABLE "users" DROP COLUMN "delivery_email";
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- Your SQL goes here
ALTER TABLE "users" ADD COLUMN "delivery_email" VARCHAR;
1 change: 1 addition & 0 deletions db_connector/src/models/users.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ pub struct User {
pub secret_nonce: Vec<u8>,
pub secret_salt: Vec<u8>,
pub login_salt: Vec<u8>,
pub delivery_email: Option<String>,
}
1 change: 1 addition & 0 deletions db_connector/src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ diesel::table! {
secret_salt -> Bytea,
#[sql_name = "login-salt"]
login_salt -> Bytea,
delivery_email -> Nullable<Varchar>,
}
}

Expand Down

0 comments on commit 8e10474

Please sign in to comment.