From: Ian Jackson Date: Sat, 5 Dec 2020 00:03:26 +0000 (+0000) Subject: wip email templates etc. X-Git-Tag: otter-0.2.0~285 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=17873454da5f814789a5c4896edf542b567c17c4;p=otter.git wip email templates etc. Signed-off-by: Ian Jackson --- diff --git a/Cargo.toml b/Cargo.toml index 3420370b..bbfeb60d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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 index 00000000..3ac7da7f --- /dev/null +++ b/emails/token-other.tera @@ -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 index 00000000..a464b7d4 --- /dev/null +++ b/emails/token-unix.tera @@ -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 index 00000000..f62ef5ea --- /dev/null +++ b/src/adhoc-templates.rs @@ -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> = 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/config.rs b/src/config.rs index 2883433a..854c4d6c 100644 --- a/src/config.rs +++ b/src/config.rs @@ -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, @@ -28,6 +30,7 @@ pub struct ServerConfigSpec { pub log: Option, pub bundled_sources: Option, pub shapelibs: Option>, + pub sendmail: Option, } #[derive(Debug,Clone)] @@ -44,6 +47,7 @@ pub struct ServerConfig { pub log: LogSpecification, pub bundled_sources: String, pub shapelibs: Vec, + pub sendmail: String, } impl TryFrom for ServerConfig { diff --git a/src/imports.rs b/src/imports.rs index 9dfd0a8d..783d5738 100644 --- a/src/imports.rs +++ b/src/imports.rs @@ -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::*; diff --git a/src/spec.rs b/src/spec.rs index c2656a8a..2b428800 100644 --- a/src/spec.rs +++ b/src/spec.rs @@ -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)]