refactor(main): Use actix-web's identity middleware for auth

This commit is contained in:
Vincent Ambo 2018-05-01 23:00:01 +02:00 committed by Vincent Ambo
parent 095293e8e3
commit 6d69f5001e

View file

@ -68,7 +68,8 @@ pub mod schema;
use actix::prelude::*; use actix::prelude::*;
use actix_web::*; use actix_web::*;
use actix_web::http::Method; use actix_web::http::Method;
use actix_web::middleware::{Logger, SessionStorage, CookieSessionBackend}; use actix_web::middleware::Logger;
use actix_web::middleware::identity::{IdentityService, CookieIdentityPolicy};
use db::*; use db::*;
use diesel::pg::PgConnection; use diesel::pg::PgConnection;
use diesel::r2d2::{ConnectionManager, Pool}; use diesel::r2d2::{ConnectionManager, Pool};
@ -180,13 +181,16 @@ fn start_http_server(base_url: String,
renderer: renderer_addr.clone(), renderer: renderer_addr.clone(),
}; };
let sessions = SessionStorage::new( let identity = IdentityService::new(
CookieSessionBackend::signed(&key) CookieIdentityPolicy::new(&key)
.secure(base_url.starts_with("https"))); .name("converse_auth")
.path("/")
.secure(base_url.starts_with("https"))
);
let app = App::with_state(state) let app = App::with_state(state)
.middleware(Logger::default()) .middleware(Logger::default())
.middleware(sessions) .middleware(identity)
.resource("/", |r| r.method(Method::GET).with(forum_index)) .resource("/", |r| r.method(Method::GET).with(forum_index))
.resource("/thread/new", |r| r.method(Method::GET).with(new_thread)) .resource("/thread/new", |r| r.method(Method::GET).with(new_thread))
.resource("/thread/submit", |r| r.method(Method::POST).with3(submit_thread)) .resource("/thread/submit", |r| r.method(Method::POST).with3(submit_thread))