1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
use crate::{service::manager::PulseManager, utils::check_auth::check_auth};
use actix_web::web::Data;
use actix_web::{post, HttpResponse};
use actix_web::{Responder, Result};
use actix_web_httpauth::extractors::basic::BasicAuth;
use serde_json::json;
use std::sync::Arc;

#[post("/login")]
pub async fn login(
    manager: Data<Arc<PulseManager>>,
    auth: Option<BasicAuth>,
) -> Result<impl Responder> {
    if !check_auth(&auth, &manager.settings) {
        return Ok(HttpResponse::Unauthorized().body("Unauthorized"));
    }

    Ok(HttpResponse::Ok().json(json!({"status": "ok"})))
}