about summary refs log tree commit diff
path: root/src/render.rs
diff options
context:
space:
mode:
authorVincent Ambo <tazjin@gmail.com>2018-04-11T23·07+0200
committerVincent Ambo <tazjin@gmail.com>2018-04-11T23·07+0200
commite7a54a5affd40f92f788f46ab64033d14860959a (patch)
tree34b89cbad6e6f71aedad65edcdd47c137eb79dc7 /src/render.rs
parentf46f6f3c4296a16e3040398df2774756dec29e93 (diff)
feat(handler): Perform basic input validation on new thread view
Diffstat (limited to 'src/render.rs')
-rw-r--r--src/render.rs18
1 files changed, 15 insertions, 3 deletions
diff --git a/src/render.rs b/src/render.rs
index 527cc404481d..37f1c4b7fe60 100644
--- a/src/render.rs
+++ b/src/render.rs
@@ -141,7 +141,15 @@ impl Handler<ThreadPage> for Renderer {
 }
 
 /// Message used to render new thread page.
-pub struct NewThreadPage;
+///
+/// It can optionally contain a vector of warnings to display to the
+/// user in alert boxes, such as input validation errors.
+#[derive(Default)]
+pub struct NewThreadPage {
+    pub alerts: Vec<&'static str>,
+    pub title: Option<String>,
+    pub body: Option<String>,
+}
 
 impl Message for NewThreadPage {
     type Result = Result<String>;
@@ -150,7 +158,11 @@ impl Message for NewThreadPage {
 impl Handler<NewThreadPage> for Renderer {
     type Result = Result<String>;
 
-    fn handle(&mut self, _: NewThreadPage, _: &mut Self::Context) -> Self::Result {
-        Ok(self.tera.render("new-thread.html", &Context::new())?)
+    fn handle(&mut self, msg: NewThreadPage, _: &mut Self::Context) -> Self::Result {
+        let mut ctx = Context::new();
+        ctx.add("alerts", &msg.alerts);
+        ctx.add("title", &msg.title.map(|s| escape_html(&s)));
+        ctx.add("body", &msg.body.map(|s| escape_html(&s)));
+        Ok(self.tera.render("new-thread.html", &ctx)?)
     }
 }