From 9eb8501fae4b4024e1b2d052b213351deeae8b81 Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Sun, 8 Apr 2018 22:56:29 +0200 Subject: feat(handlers): Use cookie session backend to store author info --- src/main.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs index 570a1b39f5..2e2664a2cf 100644 --- a/src/main.rs +++ b/src/main.rs @@ -35,6 +35,7 @@ pub mod schema; use actix::prelude::*; use actix_web::*; +use actix_web::middleware::{Logger, SessionStorage, CookieSessionBackend}; use actix_web::http::Method; use db::*; use diesel::pg::PgConnection; @@ -80,6 +81,7 @@ fn main() { info!("Initialising HTTP server ..."); let bind_host = config_default("CONVERSE_BIND_HOST", "127.0.0.1:4567"); + let key: &[u8] = &[0; 32]; // TODO: generate! server::new(move || { let template_path = concat!(env!("CARGO_MANIFEST_DIR"), "/templates/**/*"); @@ -91,13 +93,15 @@ fn main() { }; App::with_state(state) - .middleware(middleware::Logger::default()) + .middleware(Logger::default()) + // TODO: Configure session backend with more secure settings. + .middleware(SessionStorage::new(CookieSessionBackend::new(key))) .resource("/", |r| r.method(Method::GET).with(forum_index)) .resource("/thread/submit", |r| r.method(Method::POST).with2(submit_thread)) .resource("/thread/reply", |r| r.method(Method::POST).with2(reply_thread)) .resource("/thread/{id}", |r| r.method(Method::GET).with2(forum_thread)) .resource("/oidc/login", |r| r.method(Method::GET).with(login)) - .resource("/oidc/callback", |r| r.method(Method::POST).with2(callback))}) + .resource("/oidc/callback", |r| r.method(Method::POST).with3(callback))}) .bind(&bind_host).expect(&format!("Could not bind on '{}'", bind_host)) .start(); -- cgit 1.4.1