chore: fix struct definition

This commit is contained in:
Jesús Pérez Lorenzo 2021-10-19 20:58:19 +01:00
parent b7df108967
commit de2cce474c
2 changed files with 23 additions and 0 deletions

View File

@ -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<UserCtx> {
self.req.user_authentication().await
}
#[allow(clippy::missing_errors_doc)]
pub async fn get_user(&self) -> User {
self.req.get_user().await
}
}

View File

@ -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<UserCtx> {