diff --git a/reqenv/src/lib.rs b/reqenv/src/lib.rs index f4686f9..b6ba972 100644 --- a/reqenv/src/lib.rs +++ b/reqenv/src/lib.rs @@ -23,6 +23,7 @@ use app_env::{ }; use app_auth::{ AuthStore, + User, UserCtx, LoginRequest, // BEARER_PREFIX, @@ -120,4 +121,8 @@ impl ReqEnv { pub async fn user_authentication(&self) -> anyhow::Result { self.req.user_authentication().await } + #[allow(clippy::missing_errors_doc)] + pub async fn get_user(&self) -> User { + self.req.get_user().await + } } \ No newline at end of file diff --git a/reqtasks/src/lib.rs b/reqtasks/src/lib.rs index c2bf6b9..d8f19dc 100644 --- a/reqtasks/src/lib.rs +++ b/reqtasks/src/lib.rs @@ -21,6 +21,7 @@ use app_env::{ use app_tools::{hash_from_data,read_path_file}; use app_auth::{ AuthStore, + User, UserCtx, BEARER_PREFIX, AuthError, @@ -391,6 +392,23 @@ impl ReqTasks { role = String::from(""); } role + } + #[allow(clippy::missing_errors_doc)] + pub async fn get_user(&self) -> User { + let token = self.token_from_header().unwrap_or_else(|e| { + if envmnt::get_isize("DEBUG", 0) > 0 { + println!("{}",e); + } + String::from("") + }); + if !token.is_empty() { + if let Some(user_id) = self.auth_store.sessions.read().await.get(&token) { + if let Some(user) = self.auth_store.users.read().await.get(user_id) { + return user.to_owned() + } + } + } + User::default() } #[allow(clippy::missing_errors_doc)] pub async fn check_authentication(&self, token: String) -> anyhow::Result {