Can perform local authentication

This commit is contained in:
2023-09-02 18:44:16 +02:00
parent bb31954b22
commit 849bf0cdfb
7 changed files with 93 additions and 2 deletions

View File

@ -0,0 +1,31 @@
use crate::app_config::AppConfig;
use crate::extractors::auth_extractor::AuthChecker;
use crate::extractors::local_auth_extractor::LocalAuthEnabled;
use actix_web::{web, HttpResponse, Responder};
#[derive(serde::Deserialize)]
pub struct LocalAuthReq {
username: String,
password: String,
}
/// Perform local authentication
pub async fn local_auth(
local_auth_enabled: LocalAuthEnabled,
req: web::Json<LocalAuthReq>,
auth: AuthChecker,
) -> impl Responder {
if !*local_auth_enabled {
log::error!("Local auth attempt while this authentication method is disabled!");
return HttpResponse::UnprocessableEntity().json("Local authentication is disabled!");
}
if !AppConfig::get().check_local_login(&req.username, &req.password) {
log::error!("Local auth attempt with invalid credentials!");
return HttpResponse::Unauthorized().json("Invalid credentials!");
}
auth.authenticate(&req.username);
HttpResponse::Accepted().json("Welcome")
}

View File

@ -1 +1,2 @@
pub mod auth_controller;
pub mod server_controller;