From d42070cb2d97456c92a0097a3a7c0a1a30be3885 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Sat, 5 Dec 2020 10:57:59 +0000 Subject: [PATCH] wip email templates etc. Signed-off-by: Ian Jackson --- {emails => nwtemplates}/token-other.tera | 4 ++-- {emails => nwtemplates}/token-unix.tera | 2 +- src/adhoc-templates.rs | 28 ------------------------ src/nwtemplates.rs | 25 +++++++++++++++++++++ src/spec.rs | 22 ++++++++++++++++--- 5 files changed, 47 insertions(+), 34 deletions(-) rename {emails => nwtemplates}/token-other.tera (77%) rename {emails => nwtemplates}/token-unix.tera (83%) delete mode 100644 src/adhoc-templates.rs create mode 100644 src/nwtemplates.rs diff --git a/emails/token-other.tera b/nwtemplates/token-other.tera similarity index 77% rename from emails/token-other.tera rename to nwtemplates/token-other.tera index 3ac7da7f..99b19714 100644 --- a/emails/token-other.tera +++ b/nwtemplates/token-other.tera @@ -4,9 +4,9 @@ Subject: Game access link {} Hi. A user on this Otter game server, with account {{ account }} has invited you to join the game - {} + {{ game_name }} -You can play, directly, by visiting this link +You can play, directly, by visiting this link in a suitable browser. {{ token_url }} They have set for you the nickname, within the game, of diff --git a/emails/token-unix.tera b/nwtemplates/token-unix.tera similarity index 83% rename from emails/token-unix.tera rename to nwtemplates/token-unix.tera index a464b7d4..dacbb4d8 100644 --- a/emails/token-unix.tera +++ b/nwtemplates/token-unix.tera @@ -6,7 +6,7 @@ Hi. I'm inviting you to join the game {{ game_name }} on this Otter server. -You can play, directly, by visiting this link +You can play, directly, by visiting this link in a suitable browser. {{ token_url }} I have set for you the nickname, within the game, of diff --git a/src/adhoc-templates.rs b/src/adhoc-templates.rs deleted file mode 100644 index f62ef5ea..00000000 --- a/src/adhoc-templates.rs +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright 2020 Ian Jackson -// SPDX-License-Identifier: AGPL-3.0-or-later -// There is NO WARRANTY. - -use parking_lot::Mutex; - -static TERA : Mutex> = const_mutex(None); - -pub fn template_render(name: &str) { - let guard = TERA.lock(); - let tera = -} - -struct State { - tera: tera::Tera; -} - -impl Default for State { - fn default() -> State { State { - tera: tera::new( - } } -} - -type TeraWrapper = RwLock>; - -impl State { - -} diff --git a/src/nwtemplates.rs b/src/nwtemplates.rs new file mode 100644 index 00000000..5005aa2e --- /dev/null +++ b/src/nwtemplates.rs @@ -0,0 +1,25 @@ +// Copyright 2020 Ian Jackson +// SPDX-License-Identifier: AGPL-3.0-or-later +// There is NO WARRANTY. + +use parking_lot::RwLock; + +static STATE : RwLock> = const_mutex(None); + +#[throws(StartupError)] +pub fn init() { + let guard = STATE.write(); + assert!(guard.is_none()); + let glob = format!("{}/*.tera", config().nwtemplates); + *guard = State { + tera: tera::new(&glob)?, + }; +} + +#[throws(tera::Error)] +pub fn template_render(template_name: &str, data: &D) { + fn get_st() -> MappedRwLockReadGuard { + STATE.read().as_ref().unwrap() + } + get_st().render(template_name, data) +} diff --git a/src/spec.rs b/src/spec.rs index 2b428800..2115d1c9 100644 --- a/src/spec.rs +++ b/src/spec.rs @@ -394,11 +394,27 @@ pub mod implementation { ipl: &IPlayerState, token: AccessTokenInfo) -> AccessTokenReport { - let message = tempfile::tempfile()?; - let gname = &g.name; + let messagefile = tempfile::tempfile()?; + + #[derive(Serialize)] + struct CommonData<'r> { + player_email: &'r str, + game_name: &'r str, + token_url: &'r str, + nick: &'r str, + }; + let common = CommonData { + player_email: &self.addr, + game_name: &g.name, + token_url: & + } - match &ipl.account { + let message = match &ipl.account { AS::Unix { user } => { + struct Data { + pub gname: + } + write!(&mut message, r#"\ "#, -- 2.30.2