chiark / gitweb /
wip email templates etc.
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 5 Dec 2020 00:03:26 +0000 (00:03 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 5 Dec 2020 11:17:11 +0000 (11:17 +0000)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
Cargo.toml
emails/token-other.tera [new file with mode: 0644]
emails/token-unix.tera [new file with mode: 0644]
src/adhoc-templates.rs [new file with mode: 0644]
src/config.rs
src/imports.rs
src/spec.rs

index 3420370b9dbb54e9445b97f1402e3e2bc3dc4c5b..bbfeb60de11b5bddc618671108184b4da3a228c6 100644 (file)
@@ -57,6 +57,7 @@ serde_with = "1"
 slotmap = { version = "0.4", features = ['serde'] }
 strum = { version = "0.20", features = ['derive'] }
 thiserror = "1"
+tempfile = "3"
 toml = "0.5"
 typetag = "0.1.6"
 uds = "0"
diff --git a/emails/token-other.tera b/emails/token-other.tera
new file mode 100644 (file)
index 0000000..3ac7da7
--- /dev/null
@@ -0,0 +1,16 @@
+To: {{ player_email }}
+Subject: Game access link {}
+
+Hi.  A user on this Otter game server, with account
+  {{ account }}
+has invited you to join the game
+  {}
+
+You can play, directly, by visiting this link
+  {{ token_url }}
+
+They have set for you the nickname, within the game, of
+  {{ nick }}
+If you want that changing, please contact them.
+
+Regards.
diff --git a/emails/token-unix.tera b/emails/token-unix.tera
new file mode 100644 (file)
index 0000000..a464b7d
--- /dev/null
@@ -0,0 +1,16 @@
+From: Otter game server on behalf of <{{ unix_user }}}>
+To: {{ player_email }}
+Subject: Game access link {{ name }}
+
+Hi.  I'm inviting you to join the game
+  {{ game_name }}
+on this Otter server.
+
+You can play, directly, by visiting this link
+  {{ token_url }}
+
+I have set for you the nickname, within the game, of
+  {{ nick }}
+If you want that changing, please contact me.
+
+Regards.
diff --git a/src/adhoc-templates.rs b/src/adhoc-templates.rs
new file mode 100644 (file)
index 0000000..f62ef5e
--- /dev/null
@@ -0,0 +1,28 @@
+// 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 {
+  
+}
index 2883433ab33e3b5d3515748bf440ac4d7582cd3c..854c4d6c411d2469b77779472b3d2577cb5f9e28 100644 (file)
@@ -13,6 +13,8 @@ pub const EXIT_DISASTER  : i32 = 16;
 pub const DEFAULT_CONFIG_DIR      : &str = "/etc/otter";
 pub const DEFAULT_CONFIG_LEAFNAME : &str = "server.toml";
 
+pub const DEFAULT_SENDMAIL_PROGRAM : &str = "/usr/sbin/sendmail";
+
 #[derive(Deserialize,Debug,Clone)]
 pub struct ServerConfigSpec {
   pub base_dir: Option<String>,
@@ -28,6 +30,7 @@ pub struct ServerConfigSpec {
   pub log: Option<toml::Value>,
   pub bundled_sources: Option<String>,
   pub shapelibs: Option<Vec<shapelib::Config1>>,
+  pub sendmail: Option<String>,
 }
 
 #[derive(Debug,Clone)]
@@ -44,6 +47,7 @@ pub struct ServerConfig {
   pub log: LogSpecification,
   pub bundled_sources: String,
   pub shapelibs: Vec<shapelib::Config1>,
+  pub sendmail: String,
 }
 
 impl TryFrom<ServerConfigSpec> for ServerConfig {
index 9dfd0a8d8af5034653c401689e942069ff47f657..783d5738d312f127755b8c9139871979b228a156 100644 (file)
@@ -74,6 +74,8 @@ pub use rocket::{post, get, routes};
 pub use rocket_contrib::helmet::*;
 pub use rocket_contrib::json::Json;
 pub use rocket_contrib::templates::Template;
+pub use rocket_contrib::templates::Engines;
+pub use rocket_contrib::templates::tera::{self, Value};
 pub use serde::ser::SerializeTuple;
 pub use serde::{Serialize, Deserialize, de::DeserializeOwned};
 pub use serde::{Serializer, Deserializer};
@@ -83,7 +85,6 @@ pub use slotmap::dense::DenseSlotMap;
 pub use strum::EnumString;
 pub use thiserror::Error;
 pub use vecdeque_stableix::Deque as StableIndexVecDeque;
-
 pub use zcoord::{self, ZCoord};
 
 pub use crate::accounts::*;
index c2656a8ae32948fb59fea42ebea222b48700b725..2b42880097a1e3c9b7897cd6b92a70ee904620e0 100644 (file)
@@ -116,6 +116,12 @@ pub struct PlayerAccessUnset;
 #[derive(Debug,Serialize,Deserialize)]
 pub struct FixedToken { pub token: RawToken }
 
+#[derive(Debug,Serialize,Deserialize)]
+pub struct TokenByEmail {
+  /// RFC822 recipient field syntax (therefore, ASCII)
+  pub addr: Sring,
+}
+
 #[derive(Debug,Serialize,Deserialize)]
 pub struct UrlOnStdout;
 
@@ -379,6 +385,40 @@ pub mod implementation {
     }
   }
 
+  #[typetag::serde]
+  impl PlayerAccessSpec for TokenByEmail {
+    #[throws(TDE)]
+    fn deliver<'t>(&self,
+                   g: &Instance,
+                   gpl: &GPlayerState,
+                   ipl: &IPlayerState,
+                   token: AccessTokenInfo)
+                   -> AccessTokenReport {
+      let message = tempfile::tempfile()?;
+      let gname = &g.name;
+
+      match &ipl.account {
+        AS::Unix { user } => {
+          
+          write!(&mut message, r#"\
+"#,
+             &self.addr, &gname,
+             &ipl.account, &gname,
+                 
+
+      write!(&mut message, r#"\
+!      "#,
+             &self.addr, &gname,
+             &ipl.account, &gname,
+      let command = Command::new(&config().sendmail)
+        .args(&["-oee","-odb","-oi","--"])
+        .stdin(
+        
+      
+      AccessTokenReport { lines: todo!() }
+    }
+  }
+
   impl TryFrom<&ColourSpec> for Colour {
     type Error = SpecError;
     #[throws(SpecError)]