diff --git a/crates/api/src/local_user/verify_email.rs b/crates/api/src/local_user/verify_email.rs index 4b6a8c928..813b68364 100644 --- a/crates/api/src/local_user/verify_email.rs +++ b/crates/api/src/local_user/verify_email.rs @@ -19,6 +19,11 @@ pub async fn verify_email( let site_view = SiteView::read_local(&mut context.pool()).await?; let token = data.token.clone(); let verification = EmailVerification::read_for_token(&mut context.pool(), &token).await?; + let local_user_id = verification.local_user_id; + let local_user_view = LocalUserView::read(&mut context.pool(), local_user_id).await?; + + // Check if their email has already been verified once, before this + let email_already_verified = local_user_view.local_user.email_verified; let form = LocalUserUpdateForm { // necessary in case this is a new signup @@ -27,18 +32,16 @@ pub async fn verify_email( email: Some(Some(verification.email)), ..Default::default() }; - let local_user_id = verification.local_user_id; LocalUser::update(&mut context.pool(), local_user_id, &form).await?; EmailVerification::delete_old_tokens_for_local_user(&mut context.pool(), local_user_id).await?; - // send out notification about registration application to admins if enabled - if site_view.local_site.application_email_admins { - let local_user = LocalUserView::read(&mut context.pool(), local_user_id).await?; - + // Send out notification about registration application to admins if enabled, and the user hasn't + // already been verified. + if site_view.local_site.application_email_admins && !email_already_verified { send_new_applicant_email_to_admins( - &local_user.person.name, + &local_user_view.person.name, &mut context.pool(), context.settings(), )