diff options
author | Vincent Ambo <tazjin@gmail.com> | 2018-04-11T23·28+0200 |
---|---|---|
committer | Vincent Ambo <tazjin@gmail.com> | 2018-04-11T23·28+0200 |
commit | bf02c70f74ea13452d9ee129ad047075e64cdfd6 (patch) | |
tree | 5b6a6f4f4f22cf5bd096935f238e3c37280f7294 /src/main.rs | |
parent | e7a54a5affd40f92f788f46ab64033d14860959a (diff) |
feat(handlers/main): Add 'anonymous' mode for forum
Adds a `REQUIRE_LOGIN` environment variable which, if set to anything other than true, will let users post anonymously on the forums.
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/src/main.rs b/src/main.rs index eeab96e83ced..8188d498712d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -112,6 +112,8 @@ fn main() { key_bytes }; + let require_login = config_default("REQUIRE_LOGIN", "true".into()) == "true"; + server::new(move || { let state = AppState { db: db_addr.clone(), @@ -123,17 +125,22 @@ fn main() { CookieSessionBackend::signed(&key) .secure(base_url.starts_with("https"))); - App::with_state(state) + let app = App::with_state(state) .middleware(Logger::default()) .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)) .resource("/oidc/login", |r| r.method(Method::GET).with(login)) - .resource("/oidc/callback", |r| r.method(Method::POST).with3(callback))}) + .resource("/oidc/callback", |r| r.method(Method::POST).with3(callback)); + + if require_login { + app.middleware(RequireLogin) + } else { + app + }}) .bind(&bind_host).expect(&format!("Could not bind on '{}'", bind_host)) .start(); |