2024-11-22 13:13:04 +08:00
|
|
|
pub mod auth;
|
2024-11-25 03:36:24 +08:00
|
|
|
pub mod configure;
|
|
|
|
pub mod install;
|
2024-11-21 01:04:59 +08:00
|
|
|
pub mod person;
|
2024-11-25 03:36:24 +08:00
|
|
|
use rocket::http::Status;
|
|
|
|
use rocket::request::{FromRequest, Outcome, Request};
|
2024-11-22 13:13:04 +08:00
|
|
|
use rocket::routes;
|
2024-11-21 01:04:59 +08:00
|
|
|
|
2024-11-25 03:36:24 +08:00
|
|
|
pub struct Token(String);
|
|
|
|
|
|
|
|
#[rocket::async_trait]
|
|
|
|
impl<'r> FromRequest<'r> for Token {
|
|
|
|
type Error = ();
|
|
|
|
|
|
|
|
async fn from_request(request: &'r Request<'_>) -> Outcome<Self, Self::Error> {
|
|
|
|
let token = request
|
|
|
|
.headers()
|
|
|
|
.get_one("Authorization")
|
|
|
|
.map(|value| value.replace("Bearer ", ""));
|
|
|
|
|
|
|
|
match token {
|
|
|
|
Some(token) => Outcome::Success(Token(token)),
|
|
|
|
None => Outcome::Success(Token("".to_string())),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub struct SystemToken(String);
|
|
|
|
|
|
|
|
#[rocket::async_trait]
|
|
|
|
impl<'r> FromRequest<'r> for SystemToken {
|
|
|
|
type Error = ();
|
|
|
|
|
|
|
|
async fn from_request(request: &'r Request<'_>) -> Outcome<Self, Self::Error> {
|
|
|
|
let token = request
|
|
|
|
.headers()
|
|
|
|
.get_one("Authorization")
|
|
|
|
.map(|value| value.replace("Bearer ", ""));
|
|
|
|
|
|
|
|
match token {
|
|
|
|
Some(token) => {
|
|
|
|
if token == "system" {
|
|
|
|
Outcome::Success(SystemToken(token))
|
|
|
|
} else {
|
|
|
|
Outcome::Error((Status::Unauthorized, ()))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
None => Outcome::Error((Status::Unauthorized, ())),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-11-22 13:13:04 +08:00
|
|
|
pub fn jwt_routes() -> Vec<rocket::Route> {
|
|
|
|
routes![auth::token::token_system]
|
2024-11-21 19:07:42 +08:00
|
|
|
}
|