feat(handlers/templates): Add "New Thread" handler and template

This commit is contained in:
Vincent Ambo 2018-04-09 23:37:41 +02:00
parent fb7df7a346
commit 103a59485f
3 changed files with 62 additions and 1 deletions

View file

@ -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,

View file

@ -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))