about summary refs log tree commit diff
diff options
context:
space:
mode:
authorVincent Ambo <tazjin@gmail.com>2018-04-09T21·37+0200
committerVincent Ambo <tazjin@gmail.com>2018-04-09T21·37+0200
commit103a59485fbb47e44740a976fb846791b8df0802 (patch)
tree864a7b0c74f79124785df51c70c34495b0f1bf10
parentfb7df7a34680524cd269d12e6b49fa487cef38b3 (diff)
feat(handlers/templates): Add "New Thread" handler and template
-rw-r--r--src/handlers.rs9
-rw-r--r--src/main.rs2
-rw-r--r--templates/new-thread.html52
3 files changed, 62 insertions, 1 deletions
diff --git a/src/handlers.rs b/src/handlers.rs
index c31cdf679bb7..3af8a8c40929 100644
--- a/src/handlers.rs
+++ b/src/handlers.rs
@@ -81,6 +81,15 @@ pub fn forum_thread(state: State<AppState>, thread_id: Path<i32>) -> ConverseRes
         .responder()
 }
 
+/// This handler presents the user with the "New Thread" form.
+pub fn new_thread(state: State<AppState>) -> Result<HttpResponse> {
+    let ctx = tera::Context::new();
+    let body = state.tera.render("new-thread.html", &ctx)?;
+    Ok(HttpResponse::Ok()
+       .content_type("text/html")
+       .body(body))
+}
+
 #[derive(Deserialize)]
 pub struct NewThreadForm {
     pub title: String,
diff --git a/src/main.rs b/src/main.rs
index 8400f570a9be..ef5d2e92f1b4 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -109,10 +109,10 @@ fn main() {
 
         App::with_state(state)
             .middleware(Logger::default())
-            // TODO: Configure session backend with more secure settings.
             .middleware(sessions)
             .middleware(RequireLogin)
             .resource("/", |r| r.method(Method::GET).with(forum_index))
+            .resource("/thread/new", |r| r.method(Method::GET).with(new_thread))
             .resource("/thread/submit", |r| r.method(Method::POST).with3(submit_thread))
             .resource("/thread/reply", |r| r.method(Method::POST).with3(reply_thread))
             .resource("/thread/{id}", |r| r.method(Method::GET).with2(forum_thread))
diff --git a/templates/new-thread.html b/templates/new-thread.html
new file mode 100644
index 000000000000..90c724b016be
--- /dev/null
+++ b/templates/new-thread.html
@@ -0,0 +1,52 @@
+<!doctype html>
+<html lang="en">
+  <head>
+    <meta charset="utf-8">
+    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
+    <!-- Bootstrap CSS -->
+    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
+    <title>Converse Index</title>
+  </head>
+  <body>
+    <header>
+      <nav class="navbar navbar-light bg-light justify-content-between mb-3">
+        <a class="navbar-brand" href="/">
+          <h2>Converse: New Thread</h2>
+        </a>
+        <form class="form-inline">
+          <a class="btn btn-outline-secondary my-2" href="/">Back to index</a>
+        </form>
+      </nav>
+    </header>
+    <div class="container border rounded">
+      <div class="col-8">
+        <p class="mt-3">Make <i>your own thread</i> on these here forums!</p>
+        <p>Remember that you can use <strong>Markdown</strong> when
+          writing your posts.</p>
+        <form action="/thread/submit" method="post">
+          <div class="row">
+            <div class="col-8 input-group m-3">
+              <div class="input-group-prepend">
+                <span class="input-group-text" id="title-text">Title:</span>
+              </div>
+              <input type="text" class="form-control" id="title" name="title" aria-describedby="title-text">
+            </div>
+          </div>
+          <div class="row">
+            <div class="col-8 input-group m-3">
+              <div class="input-group-prepend">
+                <span class="input-group-text" id="body-text">Body:</span>
+              </div>
+              <textarea class="form-control" id="body" name="body" aria-label="thread body"></textarea>
+            </div>
+          </div>
+          <div class="row">
+            <div class="col-2 m-3">
+              <button class="btn btn-outline-primary" type="submit">Post!</button>
+            </div>
+          </div>
+        </form>
+      </div>
+    </div>
+  </body>
+</html>