add auth flag check

This commit is contained in:
glyph 2021-11-23 12:29:58 +02:00
parent 7e3c500b1e
commit bb34bdd653
1 changed files with 18 additions and 8 deletions

View File

@ -1,3 +1,5 @@
use std::env;
use log::info;
use rocket::form::{Form, FromForm};
use rocket::request::FlashMessage;
@ -42,6 +44,13 @@ impl<'r> FromRequest<'r> for Authenticated {
type Error = LoginError;
async fn from_request(req: &'r Request<'_>) -> request::Outcome<Self, Self::Error> {
// check for disable auth env var; set to false if unset
let authentication_is_disabled =
env::var("DISABLE_ROCKET_AUTH").unwrap_or_else(|_| "false".to_string());
if authentication_is_disabled == "true" {
let auth = Authenticated {};
request::Outcome::Success(auth)
} else {
let authenticated = req
.cookies()
.get_private(AUTH_COOKIE_KEY)
@ -53,6 +62,7 @@ impl<'r> FromRequest<'r> for Authenticated {
}
}
}
}
// HELPERS AND ROUTES FOR /login