feat: added access token verification
This commit is contained in:
parent
29ea2629b8
commit
1a6466fdfb
|
@ -1,5 +1,6 @@
|
|||
use crate::api::{data::*, handlers, State};
|
||||
use actix_web::{get, post, web, HttpResponse, Responder};
|
||||
use actix_web_httpauth::extractors::bearer::BearerAuth;
|
||||
use log::error;
|
||||
|
||||
// #[post("/backup/create")]
|
||||
|
@ -21,8 +22,13 @@ use log::error;
|
|||
#[post("/backup/preset")]
|
||||
async fn backup_preset_post(
|
||||
data: web::Data<State>,
|
||||
auth: BearerAuth,
|
||||
body: web::Json<BackupPreset>,
|
||||
) -> impl Responder {
|
||||
if auth.token() != data.token {
|
||||
return HttpResponse::Unauthorized().finish();
|
||||
}
|
||||
|
||||
match handlers::backup_preset_post(&data.pool, body.into_inner()).await {
|
||||
Ok(resp) => match resp {
|
||||
BackupPresetPostResponse::Success => HttpResponse::Ok().finish(),
|
||||
|
@ -36,7 +42,11 @@ async fn backup_preset_post(
|
|||
}
|
||||
|
||||
#[get("/backup/preset")]
|
||||
async fn backup_preset_get(data: web::Data<State>) -> impl Responder {
|
||||
async fn backup_preset_get(data: web::Data<State>, auth: BearerAuth) -> impl Responder {
|
||||
if auth.token() != data.token {
|
||||
return HttpResponse::Unauthorized().finish();
|
||||
}
|
||||
|
||||
match handlers::backup_preset_get(&data.pool).await {
|
||||
Ok(resp) => HttpResponse::Ok().json(&resp),
|
||||
Err(e) => {
|
||||
|
|
Loading…
Reference in New Issue