diff --git a/src/config.rs b/src/config.rs index 85d97511..6b5d3de6 100644 --- a/src/config.rs +++ b/src/config.rs @@ -530,6 +530,7 @@ fn load_templates(path: &str) -> Handlebars { reg!("email/pw_hint_none", ".html"); reg!("email/pw_hint_some", ".html"); reg!("email/send_org_invite", ".html"); + reg!("email/twofactor_email", ".html"); reg!("admin/base"); reg!("admin/login"); diff --git a/src/mail.rs b/src/mail.rs index c729efad..735a5ecd 100644 --- a/src/mail.rs +++ b/src/mail.rs @@ -156,6 +156,19 @@ pub fn send_new_device_logged_in(address: &str, ip: &str, dt: &NaiveDateTime, de send_email(&address, &subject, &body_html, &body_text) } +pub fn send_token(address: &str, token: &str) -> EmptyResult { + + let (subject, body_html, body_text) = get_text( + "email/twofactor_email", + json!({ + "url": CONFIG.domain(), + "token": token, + }), + )?; + + send_email(&address, &subject, &body_html, &body_text) +} + fn send_email(address: &str, subject: &str, body_html: &str, body_text: &str) -> EmptyResult { let html = PartBuilder::new() .body(encode_to_str(body_html)) diff --git a/src/static/templates/email/twofactor_email.hbs b/src/static/templates/email/twofactor_email.hbs new file mode 100644 index 00000000..b2cb1611 --- /dev/null +++ b/src/static/templates/email/twofactor_email.hbs @@ -0,0 +1,9 @@ +Your Two-step Login Verification Code + + +

+ Your two-step verification code is: {{token}} + + Use this code to complete logging in with Bitwarden. +

+ diff --git a/src/static/templates/email/twofactor_email.html.hbs b/src/static/templates/email/twofactor_email.html.hbs new file mode 100644 index 00000000..32898047 --- /dev/null +++ b/src/static/templates/email/twofactor_email.html.hbs @@ -0,0 +1,129 @@ +Your Two-step Login Verification Code + + + + + + Bitwarden_rs + + + + + + + + + + +
+ + + + +
+ + + + +
+ + + + + + + +
+ Your two-step verification code is: {{token}} +
+ Use this code to complete logging in with Bitwarden. +
+
+ + + + + +
+
+ +