mirror of
https://github.com/shiroyashik/sculptor.git
synced 2025-12-06 13:01:12 +03:00
added session check + updates check fixed
This commit is contained in:
parent
63f0b0d732
commit
584983810b
4 changed files with 36 additions and 14 deletions
|
|
@ -2,12 +2,14 @@ use std::sync::Arc;
|
|||
|
||||
use anyhow::anyhow;
|
||||
use axum::{
|
||||
async_trait, extract::FromRequestParts, http::{request::Parts, StatusCode}
|
||||
async_trait, extract::{FromRequestParts, State}, http::{request::Parts, StatusCode}, response::{IntoResponse, Response}
|
||||
};
|
||||
use dashmap::DashMap;
|
||||
use tracing::{debug, trace};
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::AppState;
|
||||
|
||||
use super::types::*;
|
||||
|
||||
// It's an extractor that pulls a token from the Header.
|
||||
|
|
@ -137,7 +139,7 @@ impl UManager {
|
|||
) -> Option<dashmap::mapref::one::Ref<'_, Uuid, Userinfo>> {
|
||||
self.registered.get(uuid)
|
||||
}
|
||||
pub fn _is_authenticated(&self, token: &String) -> bool {
|
||||
pub fn is_authenticated(&self, token: &String) -> bool {
|
||||
self.authenticated.contains_key(token)
|
||||
}
|
||||
pub fn _is_registered(&self, uuid: &Uuid) -> bool {
|
||||
|
|
@ -148,4 +150,21 @@ impl UManager {
|
|||
self.authenticated.remove(&token);
|
||||
}
|
||||
}
|
||||
// End of User manager
|
||||
// End of User manager
|
||||
|
||||
pub async fn check_auth(
|
||||
Token(token): Token,
|
||||
State(state): State<AppState>,
|
||||
) -> Response {
|
||||
|
||||
match token {
|
||||
Some(token) => {
|
||||
if state.user_manager.is_authenticated(&token) {
|
||||
(StatusCode::OK, "ok".to_string()).into_response()
|
||||
} else {
|
||||
(StatusCode::UNAUTHORIZED, "unauthorized".to_string()).into_response()
|
||||
}
|
||||
},
|
||||
None => (StatusCode::BAD_REQUEST, "bad request".to_string()).into_response(),
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue