chiark / gitweb /
wip email templates etc.
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 5 Dec 2020 10:57:59 +0000 (10:57 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 5 Dec 2020 11:17:50 +0000 (11:17 +0000)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
nwtemplates/token-other.tera [moved from emails/token-other.tera with 77% similarity]
nwtemplates/token-unix.tera [moved from emails/token-unix.tera with 83% similarity]
src/adhoc-templates.rs [deleted file]
src/nwtemplates.rs [new file with mode: 0644]
src/spec.rs

similarity index 77%
rename from emails/token-other.tera
rename to nwtemplates/token-other.tera
index 3ac7da7f36ffbec375d79df65038807104daa3e8..99b197144f38437664fc6019ab68569f260123ab 100644 (file)
@@ -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
similarity index 83%
rename from emails/token-unix.tera
rename to nwtemplates/token-unix.tera
index a464b7d4563cc561043ab315377e26aaea45ec30..dacbb4d8b51e960a9a741e025efba30df5399dcd 100644 (file)
@@ -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 (file)
index f62ef5e..0000000
+++ /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<Option<State>> = 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<Arc<State>>;
-
-impl State {
-  
-}
diff --git a/src/nwtemplates.rs b/src/nwtemplates.rs
new file mode 100644 (file)
index 0000000..5005aa2
--- /dev/null
@@ -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<Option<State>> = 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<D: Serialize>(template_name: &str, data: &D) {
+  fn get_st() -> MappedRwLockReadGuard<State> {
+    STATE.read().as_ref().unwrap()
+  }
+  get_st().render(template_name, data)
+}
index 2b42880097a1e3c9b7897cd6b92a70ee904620e0..2115d1c95eee54dd5f672b7b807bd08d1503cff9 100644 (file)
@@ -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#"\
 "#,