diff --git a/src/error.rs b/src/error.rs index 4546c64..b98795f 100644 --- a/src/error.rs +++ b/src/error.rs @@ -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 for Error { fn from(giterr: git2::Error) -> Self { // panic!() - Error(format!("{}", giterr)) + Error::BadGateway(format!("{}", giterr)) } } impl From 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()} + } } } \ No newline at end of file diff --git a/src/webutils/auth.rs b/src/webutils/auth.rs index 7277437..d185f19 100644 --- a/src/webutils/auth.rs +++ b/src/webutils/auth.rs @@ -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"))} + } } \ No newline at end of file