add auth flag check
This commit is contained in:
parent
7e3c500b1e
commit
bb34bdd653
@ -1,3 +1,5 @@
|
|||||||
|
use std::env;
|
||||||
|
|
||||||
use log::info;
|
use log::info;
|
||||||
use rocket::form::{Form, FromForm};
|
use rocket::form::{Form, FromForm};
|
||||||
use rocket::request::FlashMessage;
|
use rocket::request::FlashMessage;
|
||||||
@ -42,14 +44,22 @@ impl<'r> FromRequest<'r> for Authenticated {
|
|||||||
type Error = LoginError;
|
type Error = LoginError;
|
||||||
|
|
||||||
async fn from_request(req: &'r Request<'_>) -> request::Outcome<Self, Self::Error> {
|
async fn from_request(req: &'r Request<'_>) -> request::Outcome<Self, Self::Error> {
|
||||||
let authenticated = req
|
// check for disable auth env var; set to false if unset
|
||||||
.cookies()
|
let authentication_is_disabled =
|
||||||
.get_private(AUTH_COOKIE_KEY)
|
env::var("DISABLE_ROCKET_AUTH").unwrap_or_else(|_| "false".to_string());
|
||||||
.and_then(|cookie| cookie.value().parse().ok())
|
if authentication_is_disabled == "true" {
|
||||||
.map(|_value: String| Authenticated {});
|
let auth = Authenticated {};
|
||||||
match authenticated {
|
request::Outcome::Success(auth)
|
||||||
Some(auth) => request::Outcome::Success(auth),
|
} else {
|
||||||
None => request::Outcome::Failure((Status::Forbidden, LoginError::UserNotLoggedIn)),
|
let authenticated = req
|
||||||
|
.cookies()
|
||||||
|
.get_private(AUTH_COOKIE_KEY)
|
||||||
|
.and_then(|cookie| cookie.value().parse().ok())
|
||||||
|
.map(|_value: String| Authenticated {});
|
||||||
|
match authenticated {
|
||||||
|
Some(auth) => request::Outcome::Success(auth),
|
||||||
|
None => request::Outcome::Failure((Status::Forbidden, LoginError::UserNotLoggedIn)),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user