mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
add ingore_auth feature on backend
This commit is contained in:
@ -92,6 +92,7 @@ path = "src/main.rs"
|
||||
|
||||
[features]
|
||||
flowy_test = []
|
||||
ignore_auth = []
|
||||
|
||||
[dev-dependencies]
|
||||
parking_lot = "0.11"
|
||||
|
@ -49,9 +49,7 @@ where
|
||||
type Error = Error;
|
||||
type Future = LocalBoxFuture<'static, Result<Self::Response, Self::Error>>;
|
||||
|
||||
fn poll_ready(&self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
|
||||
self.service.poll_ready(cx)
|
||||
}
|
||||
fn poll_ready(&self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> { self.service.poll_ready(cx) }
|
||||
|
||||
fn call(&self, req: ServiceRequest) -> Self::Future {
|
||||
let mut authenticate_pass: bool = false;
|
||||
@ -68,9 +66,15 @@ where
|
||||
let result: Result<LoggedUser, ServerError> = header.try_into();
|
||||
match result {
|
||||
Ok(logged_user) => {
|
||||
authenticate_pass = AUTHORIZED_USERS.is_authorized(&logged_user);
|
||||
// Update user timestamp
|
||||
AUTHORIZED_USERS.store_auth(logged_user, true);
|
||||
if cfg!(feature = "ignore_auth") {
|
||||
authenticate_pass = true;
|
||||
AUTHORIZED_USERS.store_auth(logged_user, true);
|
||||
} else {
|
||||
authenticate_pass = AUTHORIZED_USERS.is_authorized(&logged_user);
|
||||
if authenticate_pass {
|
||||
AUTHORIZED_USERS.store_auth(logged_user, true);
|
||||
}
|
||||
}
|
||||
},
|
||||
Err(e) => log::error!("{:?}", e),
|
||||
}
|
||||
|
@ -15,11 +15,7 @@ pub struct LoggedUser {
|
||||
}
|
||||
|
||||
impl std::convert::From<Claim> for LoggedUser {
|
||||
fn from(c: Claim) -> Self {
|
||||
Self {
|
||||
user_id: c.user_id(),
|
||||
}
|
||||
}
|
||||
fn from(c: Claim) -> Self { Self { user_id: c.user_id() } }
|
||||
}
|
||||
|
||||
impl LoggedUser {
|
||||
@ -93,7 +89,6 @@ impl AuthorizedUsers {
|
||||
AuthStatus::Authorized(last_time) => {
|
||||
let current_time = Utc::now();
|
||||
let days = (current_time - last_time).num_days();
|
||||
log::debug!("user active {} from now", days);
|
||||
days < EXPIRED_DURATION_DAYS
|
||||
},
|
||||
AuthStatus::NotAuthorized => {
|
||||
|
Reference in New Issue
Block a user