Skip to content

Commit

Permalink
feat: Add "email in use" template
Browse files Browse the repository at this point in the history
  • Loading branch information
JadedBlueEyes committed Aug 19, 2024
1 parent c8a9660 commit d59dcdc
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 0 deletions.
8 changes: 8 additions & 0 deletions locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,13 @@
"action": "Click on the link below to reset your password:",
"in_error": "If you didn't initiate this request and feel that you've received this email in error, don't worry, you don't need to take any further action and can safely disregard this email.",
"contact": "If you still have problems logging in, please drop us a line."
},
"email_in_use": {
"title": "Email address already in use",
"info": "You have requested to verify this email address for the MusicBrainz account {user_name}, but we already have at least one account using this address in our database.",
"action_username": "If you have forgotten your old username, you can recover it from the following link:",
"action_password": "You can then request a password reset, if needed, from the link below:",
"in_error": "If you didn't initiate this request and feel that you've received this email in error, don't worry, you don't need to take any further action and can safely disregard this email.",
"second_account": "If you have a specific reason why you need a second account (for example, you want to run a bot and have notes also reach you at this address) please drop us a line. We will look into your specific case."
}
}
2 changes: 2 additions & 0 deletions src/templates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use crate::Locale;
mod basic;
mod edit_note;
mod editor_message;
mod email_in_use;
mod reset_password;
mod subscription;
mod verify_email;
Expand All @@ -24,6 +25,7 @@ pub fn get(template_id: &str) -> Option<Template> {
"edit-note" => Some(edit_note::edit_note),
"editor-message" => Some(editor_message::editor_message),
"verify-email" => Some(verify_email::verify_email),
"email-in-use" => Some(email_in_use::email_in_use),
"reset-password" => Some(reset_password::reset_password),
_ => None,
}
Expand Down
84 changes: 84 additions & 0 deletions src/templates/email_in_use.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
use std::borrow::Borrow;

use mf1::t_l_string as tl;
use mrml::{mjml::Mjml, text::Text};
use mrmx::WithAttribute;
use mrmx_macros::view;
use serde::Deserialize;
use serde_json::Value;

use crate::{components::*, Locale};

use super::TemplateError;

#[derive(Deserialize, Debug, Default)]
#[serde(default)]
struct EmailInUse {
to_name: String,
lost_username_url: String,
lost_password_url: String,
// ip?
}

pub(crate) fn email_in_use(params: Value, l: Locale) -> Result<Mjml, TemplateError> {
let ctx: Option<EmailInUse> = serde_json::from_value(params)?;
let EmailInUse {
ref to_name,
ref lost_username_url,
ref lost_password_url,
} = ctx.unwrap_or_default();
Ok(view! {
<mjml>
<mj-head>
{ head().into() }
<mj-title>{ tl!(l, email_in_use.title ).borrow() }</mj-title>
</mj-head>
<mj-body width="500px" padding="0">
<mj-section padding="20px 0">
<mj-column padding="0">
{ header().into() }

<mj-text>
<p>{ Text::from(tl!(l, greeting_line, name = to_name)).into() }</p>
<p>{ Text::from(tl!(l, email_in_use.info, user_name = to_name )).into() }</p>
<p>{ Text::from(tl!(l, email_in_use.action_username )).into() }</p>
</mj-text>

<mj-wrapper mj-class="wrapper">
<mj-text>
<p>
<a href={lost_username_url}>{ Text::from(lost_username_url).into()}</a>
</p>
</mj-text>
</mj-wrapper>
<mj-text>
<p>{ Text::from(tl!(l, email_in_use.action_password )).into() }</p>
</mj-text>
<mj-wrapper mj-class="wrapper">
<mj-text>
<p>
<a href={lost_password_url}>{ Text::from(lost_password_url).into()}</a>
</p>
</mj-text>
</mj-wrapper>

<mj-text>
<p>{ Text::from(tl!(l, link_copy_info)).into() }</p>
<p>{ Text::from(tl!(l, email_in_use.in_error)).into() }</p>
<p>{ Text::from(tl!(l, email_in_use.second_account)).into() }</p>
</mj-text>

<mj-text>
<p><em>{ Text::from(tl!(l, metabrainz_signoff)).into() }</em></p>
</mj-text>
<mj-divider padding="10px 15px" border-color="#F5F5F5" border-width="3px" />
<mj-text font-size="12px" color="#8D8D8D">
<p>{ Text::from(tl!(l, do_not_reply)).into() }</p>
</mj-text>
</mj-column>
</mj-section>
</mj-body>
</mjml>

})
}

0 comments on commit d59dcdc

Please sign in to comment.