chore: add get role
This commit is contained in:
parent
c208bf07f1
commit
bfd480349e
1 changed files with 18 additions and 0 deletions
|
|
@ -363,6 +363,24 @@ impl ReqTasks {
|
||||||
pub async fn user_authentication(&self) -> anyhow::Result<UserCtx> {
|
pub async fn user_authentication(&self) -> anyhow::Result<UserCtx> {
|
||||||
let token = self.token_from_header().unwrap_or_else(|e| { println!("{}",e); String::from("")});
|
let token = self.token_from_header().unwrap_or_else(|e| { println!("{}",e); String::from("")});
|
||||||
self.check_authentication(token).await
|
self.check_authentication(token).await
|
||||||
|
}
|
||||||
|
#[allow(clippy::missing_errors_doc)]
|
||||||
|
pub async fn user_role(&self) -> String {
|
||||||
|
let token = self.token_from_header().unwrap_or_else(|e| { println!("{}",e); String::from("")});
|
||||||
|
if token.is_empty() {
|
||||||
|
return String::from("");
|
||||||
|
}
|
||||||
|
let role: String;
|
||||||
|
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) {
|
||||||
|
role = format!("{}",user.role);
|
||||||
|
} else {
|
||||||
|
role = String::from("");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
role = String::from("");
|
||||||
|
}
|
||||||
|
role
|
||||||
}
|
}
|
||||||
#[allow(clippy::missing_errors_doc)]
|
#[allow(clippy::missing_errors_doc)]
|
||||||
pub async fn check_authentication(&self, token: String) -> anyhow::Result<UserCtx> {
|
pub async fn check_authentication(&self, token: String) -> anyhow::Result<UserCtx> {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue