forked from PeachCloud/peach-workspace
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,6 +44,13 @@ 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> {
|
||||||
|
// 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
|
let authenticated = req
|
||||||
.cookies()
|
.cookies()
|
||||||
.get_private(AUTH_COOKIE_KEY)
|
.get_private(AUTH_COOKIE_KEY)
|
||||||
@ -53,6 +62,7 @@ impl<'r> FromRequest<'r> for Authenticated {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// HELPERS AND ROUTES FOR /login
|
// HELPERS AND ROUTES FOR /login
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user