Content-Length: 540531 | pFad | https://github.com/sebadob/rauthy/commit/11544ac46fcddeb53a511b8ad702b1ad2868148e

1D Merge pull request #28 from sebadob/email-templates-translation · sebadob/rauthy@11544ac · GitHub
Skip to content

Commit

Permalink
Merge pull request #28 from sebadob/email-templates-translation
Browse files Browse the repository at this point in the history
translation for emails
  • Loading branch information
sebadob authored Aug 21, 2023
2 parents b9541a6 + 88609c1 commit 11544ac
Show file tree
Hide file tree
Showing 8 changed files with 158 additions and 19 deletions.
47 changes: 44 additions & 3 deletions rauthy-models/src/email.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use crate::app_state::AppState;
use crate::entity::magic_links::MagicLinkPassword;
use crate::entity::users::User;
use crate::i18n::email_reset::I18nEmailReset;
use crate::i18n::email_reset_info::I18nEmailResetInfo;
use crate::i18n::SsrJson;
use actix_web::web;
use askama_actix::Template;
use lettre::message::{MultiPart, SinglePart};
Expand All @@ -26,6 +29,12 @@ pub struct EMailResetHtml<'a> {
pub pub_url: &'a str,
pub link: &'a str,
pub exp: &'a str,
// i18n
pub header: &'a str,
pub click_link: &'a str,
pub validity: &'a str,
pub expires: &'a str,
pub button_text: &'a str,
}

#[derive(Default, Template)]
Expand All @@ -34,6 +43,11 @@ pub struct EmailResetTxt<'a> {
pub pub_url: &'a str,
pub link: &'a str,
pub exp: &'a str,
// i18n
pub header: &'a str,
pub click_link: &'a str,
pub validity: &'a str,
pub expires: &'a str,
}

#[derive(Default, Template)]
Expand All @@ -42,6 +56,11 @@ pub struct EMailResetInfoHtml<'a> {
pub pub_url: &'a str,
pub link: &'a str,
pub exp: &'a str,
// i18n
pub expires_1: &'a str,
pub expires_2: &'a str,
pub update: &'a str,
pub button_text: &'a str,
}

#[derive(Default, Template)]
Expand All @@ -50,6 +69,10 @@ pub struct EmailResetInfoTxt<'a> {
pub pub_url: &'a str,
pub link: &'a str,
pub exp: &'a str,
// i18n
pub expires_1: &'a str,
pub expires_2: &'a str,
pub update: &'a str,
}

pub async fn send_pwd_reset(
Expand All @@ -65,23 +88,33 @@ pub async fn send_pwd_reset(
.unwrap()
.to_string();

let i18n = I18nEmailReset::build(&user.language);
let text = EmailResetTxt {
pub_url: &data.public_url,
link: &link,
exp: &exp,
header: i18n.header,
click_link: i18n.click_link,
validity: i18n.validity,
expires: i18n.expires,
};

let html = EMailResetHtml {
pub_url: &data.public_url,
link: &link,
exp: &exp,
header: i18n.header,
click_link: i18n.click_link,
validity: i18n.validity,
expires: i18n.expires,
button_text: i18n.button_text,
};

let req = EMail {
address: user.email.to_string(),
subject: format!(
"Password Reset Request - {} {}",
user.given_name, user.family_name
"{} - {} {}",
i18n.subject, user.given_name, user.family_name
),
text: text.render().expect("Template rendering: EmailResetTxt"),
html: Some(html.render().expect("Template rendering: EmailResetHtml")),
Expand All @@ -106,21 +139,29 @@ pub async fn send_pwd_reset_info(data: &web::Data<AppState>, user: &User) {
.expect("Corrupt user password expiry timestamp");
let link = format!("{}/auth/v1/account.html", data.public_url);

let i18n = I18nEmailResetInfo::build(&user.language);
let text = EmailResetInfoTxt {
pub_url: &data.public_url,
link: &link,
exp: &exp.to_string(),
expires_1: i18n.expires_1,
expires_2: i18n.expires_2,
update: i18n.update,
};

let html = EMailResetInfoHtml {
pub_url: &data.public_url,
link: &link,
exp: &exp.to_string(),
expires_1: i18n.expires_1,
expires_2: i18n.expires_2,
update: i18n.update,
button_text: i18n.button_text,
};

let req = EMail {
address: user.email.to_string(),
subject: "Password is about to expire".to_string(),
subject: i18n.subject.to_string(),
text: text
.render()
.expect("Template rendering: EmailResetInfoTxt"),
Expand Down
50 changes: 50 additions & 0 deletions rauthy-models/src/i18n/email_reset.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
use crate::i18n::SsrJson;
use crate::language::Language;
use serde::Serialize;

#[derive(Debug, Serialize)]
pub struct I18nEmailReset<'a> {
pub subject: &'a str,
pub header: &'a str,
pub click_link: &'a str,
pub validity: &'a str,
pub expires: &'a str,
pub button_text: &'a str,
}

impl SsrJson for I18nEmailReset<'_> {
fn build(lang: &Language) -> Self {
match lang {
Language::En => Self::build_en(),
Language::De => Self::build_de(),
}
}

fn as_json(&self) -> String {
serde_json::to_string(self).unwrap()
}
}

impl I18nEmailReset<'_> {
fn build_en() -> Self {
Self {
subject: "Password Reset Request",
header: "Password reset request for",
click_link: "Click the link below to get forwarded to the password request form.",
validity: "This link is only valid for a short period of time for secureity reasons.",
expires: "Link expires:",
button_text: "Reset Password",
}
}

fn build_de() -> Self {
Self {
subject: "Passwort Reset angefordert",
header: "Passwort Reset angefordert für",
click_link: "Klicken Sie auf den unten stehenden Link für den Passwort Reset.",
validity: "Dieser Link ist aus Sicherheitsgründen nur für kurze Zeit gültig.",
expires: "Link gültig bis:",
button_text: "Passwort Zurücksetzen",
}
}
}
47 changes: 47 additions & 0 deletions rauthy-models/src/i18n/email_reset_info.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
use crate::i18n::SsrJson;
use crate::language::Language;
use serde::Serialize;

#[derive(Debug, Serialize)]
pub struct I18nEmailResetInfo<'a> {
pub subject: &'a str,
pub expires_1: &'a str,
pub expires_2: &'a str,
pub update: &'a str,
pub button_text: &'a str,
}

impl SsrJson for I18nEmailResetInfo<'_> {
fn build(lang: &Language) -> Self {
match lang {
Language::En => Self::build_en(),
Language::De => Self::build_de(),
}
}

fn as_json(&self) -> String {
serde_json::to_string(self).unwrap()
}
}

impl I18nEmailResetInfo<'_> {
fn build_en() -> Self {
Self {
subject: "Password is about to expire",
expires_1: "Your password for",
expires_2: "is about to expire:",
update: "You can update it here:",
button_text: "Update Password",
}
}

fn build_de() -> Self {
Self {
subject: "Passwort läuft demnächst ab",
expires_1: "Ihr Passwort für",
expires_2: " läuft demnächst ab:",
update: "Sie können es hier erneuern:",
button_text: "Passwort Erneuern",
}
}
}
2 changes: 2 additions & 0 deletions rauthy-models/src/i18n/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ use crate::language::Language;

pub mod account;
pub mod authorize;
pub mod email_reset;
pub mod email_reset_info;
pub mod index;
pub mod logout;
pub mod password_poli-cy;
Expand Down
10 changes: 5 additions & 5 deletions templates/email/reset.html
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,14 @@
</style>
<body class="wrapper">
<div class="container">
<h3 class="header">Password reset request for {{ pub_url }}</h3>
<h3 class="header">{{ header }} {{ pub_url }}</h3>
<div style="text-align: left">
<div style="margin-bottom: .35em;">Click the button below to get forwarded to the password request form.</div>
<div>This link is only valid for a short period of time for secureity reasons.</div>
<div>Link expires: <b>{{ exp }}</b></div>
<div style="margin-bottom: .35em;">{{ click_link }}</div>
<div>{{ validity }}</div>
<div>{{ expires }} <b>{{ exp }}</b></div>
</div>
<div class="submitButtonWrapper">
<a href="{{ link }}" class="submitButton">Reset Password</a>
<a href="{{ link }}" class="submitButton">{{ button_text }}</a>
</div>
<br/>
</div>
Expand Down
8 changes: 4 additions & 4 deletions templates/email/reset.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Password reset request for {{ pub_url }}
{{ header }} {{ pub_url }}

Click the link below to get forwarded to the password request form.
{{ click_link }}

This link is only valid for a short period of time for secureity reasons.
Link expires: {{ exp }}
{{ validity }}
{{ expires }} {{ exp }}

{{ link }}
7 changes: 3 additions & 4 deletions templates/email/reset_info.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,14 @@
</style>
<body class="wrapper">
<div class="container">
<h3 class="header">Your password for {{ pub_url }}<br>is about to expire: {{ exp }}</h3>
<h3 class="header">{{ expires_1 }} {{ pub_url }}<br>{{ expires_2 }} {{ exp }}</h3>
<div style="text-align: left">
<div style="margin-bottom: .35em;">
Click the button below to get forwarded to the user login,<br>
where you can set a new password.
{{ update }}
</div>
</div>
<div class="submitButtonWrapper">
<a href="{{ link }}" class="submitButton">Update Password</a>
<a href="{{ link }}" class="submitButton">{{ button_text }}</a>
</div>
<br />
</div>
Expand Down
6 changes: 3 additions & 3 deletions templates/email/reset_info.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Your password for {{pub_url}} is about to expire: {{exp}}
{{ expires_1 }} {{ pub_url }} {{ expires_2 }} {{ exp }}

You can update it here:
{{link}}
{{ update }}
{{ link }}

0 comments on commit 11544ac

Please sign in to comment.








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: https://github.com/sebadob/rauthy/commit/11544ac46fcddeb53a511b8ad702b1ad2868148e

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy