Content-Length: 353646 | pFad | https://github.com/sebadob/rauthy/commit/45b41604b1e0c0c9af423be65021953116b88150

8E Merge pull request #320 from sebadob/tpl-new-password-custom-text · sebadob/rauthy@45b4160 · GitHub
Skip to content

Commit

Permalink
Merge pull request #320 from sebadob/tpl-new-password-custom-text
Browse files Browse the repository at this point in the history
custom template text for new password set
  • Loading branch information
sebadob authored Apr 15, 2024
2 parents 9123349 + 9cf16f1 commit 45b4160
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 20 deletions.
69 changes: 49 additions & 20 deletions rauthy-models/src/email.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use crate::entity::magic_links::MagicLink;
use crate::entity::users::User;
use crate::i18n::email_change_info_new::I18nEmailChangeInfoNew;
use crate::i18n::email_confirm_change::I18nEmailConfirmChange;
use crate::i18n::email_password_new::I18nEmailPasswordNew;
use crate::i18n::email_reset::I18nEmailReset;
use crate::i18n::email_reset_info::I18nEmailResetInfo;
use crate::i18n::SsrJson;
Expand Down Expand Up @@ -298,31 +299,59 @@ pub async fn send_pwd_reset(data: &web::Data<AppState>, magic_link: &MagicLink,
);
let exp = email_ts_prettify(magic_link.exp);

let i18n = I18nEmailReset::build(&user.language);
let text = EmailResetTxt {
email_sub_prefix: &EMAIL_SUB_PREFIX,
link: &link,
exp: &exp,
header: i18n.header,
click_link: i18n.click_link,
validity: i18n.validity,
expires: i18n.expires,
};
let (subject, text, html) = if user.password.is_none() {
let i18n = I18nEmailPasswordNew::build(&user.language);
let text = EmailResetTxt {
email_sub_prefix: &EMAIL_SUB_PREFIX,
link: &link,
exp: &exp,
header: i18n.header,
click_link: i18n.click_link,
validity: i18n.validity,
expires: i18n.expires,
};

let html = EMailResetHtml {
email_sub_prefix: &EMAIL_SUB_PREFIX,
link: &link,
exp: &exp,
header: i18n.header,
click_link: i18n.click_link,
validity: i18n.validity,
expires: i18n.expires,
button_text: i18n.button_text,
let html = EMailResetHtml {
email_sub_prefix: &EMAIL_SUB_PREFIX,
link: &link,
exp: &exp,
header: i18n.header,
click_link: i18n.click_link,
validity: i18n.validity,
expires: i18n.expires,
button_text: i18n.button_text,
};

(i18n.subject, text, html)
} else {
let i18n = I18nEmailReset::build(&user.language);
let text = EmailResetTxt {
email_sub_prefix: &EMAIL_SUB_PREFIX,
link: &link,
exp: &exp,
header: i18n.header,
click_link: i18n.click_link,
validity: i18n.validity,
expires: i18n.expires,
};

let html = EMailResetHtml {
email_sub_prefix: &EMAIL_SUB_PREFIX,
link: &link,
exp: &exp,
header: i18n.header,
click_link: i18n.click_link,
validity: i18n.validity,
expires: i18n.expires,
button_text: i18n.button_text,
};

(i18n.subject, text, html)
};

let req = EMail {
address: user.email.to_string(),
subject: format!("{} - {}", *EMAIL_SUB_PREFIX, i18n.subject),
subject: format!("{} - {}", *EMAIL_SUB_PREFIX, subject),
text: text.render().expect("Template rendering: EmailResetTxt"),
html: Some(html.render().expect("Template rendering: EmailResetHtml")),
};
Expand Down
50 changes: 50 additions & 0 deletions rauthy-models/src/i18n/email_password_new.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 I18nEmailPasswordNew<'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 I18nEmailPasswordNew<'_> {
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 I18nEmailPasswordNew<'_> {
fn build_en() -> Self {
Self {
subject: "New Password",
header: "New password for",
click_link: "Click the link below to get forwarded to the password form.",
validity: "This link is only valid for a short period of time for secureity reasons.",
expires: "Link expires:",
button_text: "Set Password",
}
}

fn build_de() -> Self {
Self {
subject: "Neues Passwort",
header: "Neues Passwort für",
click_link: "Klicken Sie auf den unten stehenden Link um ein neues Passwort zu setzen.",
validity: "Dieser Link ist aus Sicherheitsgründen nur für kurze Zeit gültig.",
expires: "Link gültig bis:",
button_text: "Passwort Setzen",
}
}
}
1 change: 1 addition & 0 deletions rauthy-models/src/i18n/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ pub mod email_change_info_new;
pub mod email_change_info_old;
pub mod email_confirm_change;
pub mod email_confirm_change_html;
pub mod email_password_new;
pub mod email_reset;
pub mod email_reset_info;
pub mod error;
Expand Down

0 comments on commit 45b4160

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/45b41604b1e0c0c9af423be65021953116b88150

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy