This commit is contained in:
Hubert 2021-07-20 21:47:20 +02:00
parent 2bc387920c
commit 234e2ccaa3
2 changed files with 20 additions and 4 deletions

View File

@ -1,17 +1,29 @@
use actix_web::dev::HttpResponseBuilder;
use actix_web::http::StatusCode;
use actix_web_httpauth::extractors::{basic, AuthenticationError};
pub struct Error(String);
pub enum Error {
BadGateway(String),
Unauthorized(String),
}
impl Error {
}
impl From<git2::Error> for Error {
fn from(giterr: git2::Error) -> Self {
// panic!()
Error(format!("{}", giterr))
Error::BadGateway(format!("{}", giterr))
}
}
impl From<Error> for actix_web::error::Error {
fn from(e: Error) -> Self {
HttpResponseBuilder::new(StatusCode::BAD_GATEWAY).body(e.0).into()
match e {
Error::BadGateway(msg) => {HttpResponseBuilder::new(StatusCode::BAD_GATEWAY).body(msg).into()}
Error::Unauthorized(msg) => {
let config : basic::Config = Default::default();
AuthenticationError::from(config).into()}
}
}
}

View File

@ -1,5 +1,9 @@
use actix_web_httpauth::extractors::basic::BasicAuth;
use std::borrow::Cow;
pub fn check_user(auth : BasicAuth) -> bool {
auth.user_id() == auth.
match auth.password() {
None => {false}
Some(pwd) => {pwd.to_string().eq(&(auth.user_id().to_string() + "pwd"))}
}
}