save
This commit is contained in:
parent
2bc387920c
commit
234e2ccaa3
18
src/error.rs
18
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<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()}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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"))}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue