From 0b60f20eb3d598acb0525a098445b56672b83985 Mon Sep 17 00:00:00 2001 From: vpl Date: Sat, 3 Aug 2019 08:07:14 +0200 Subject: [PATCH] Add email message for twofactor email codes --- src/config.rs | 1 + src/mail.rs | 13 ++ .../templates/email/twofactor_email.hbs | 9 ++ .../templates/email/twofactor_email.html.hbs | 129 ++++++++++++++++++ 4 files changed, 152 insertions(+) create mode 100644 src/static/templates/email/twofactor_email.hbs create mode 100644 src/static/templates/email/twofactor_email.html.hbs diff --git a/src/config.rs b/src/config.rs index 85d9751..6b5d3de 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 c729efa..735a5ec 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 0000000..b2cb161 --- /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 0000000..3289804 --- /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. +
+
+ + + + + +
+
+ +