now hanlding server issues with auth(since those sometimes happen)
also renamed some vars to be more clear
This commit is contained in:
parent
47b4b7e35f
commit
02e6c4145e
@ -6,6 +6,8 @@ extern crate getrandom;
|
|||||||
extern crate bcrypt;
|
extern crate bcrypt;
|
||||||
extern crate base64;
|
extern crate base64;
|
||||||
extern crate serde;
|
extern crate serde;
|
||||||
|
extern crate jsonwebtoken;
|
||||||
|
#[macro_use] extern crate lazy_static;
|
||||||
|
|
||||||
use std::net::SocketAddr;
|
use std::net::SocketAddr;
|
||||||
use std::convert::Infallible; // our main dispatcher basically never fails hence why we use this
|
use std::convert::Infallible; // our main dispatcher basically never fails hence why we use this
|
||||||
@ -79,27 +81,21 @@ async fn main_responder(request: Request<Body>) -> Result<Response<Body>, hyper:
|
|||||||
let (parts, mut body) = request.into_parts();
|
let (parts, mut body) = request.into_parts();
|
||||||
let method = parts.method;
|
let method = parts.method;
|
||||||
let path = parts.uri.path();
|
let path = parts.uri.path();
|
||||||
let headers = parts.headers;
|
|
||||||
println!("{}: {}", method, path);
|
println!("{}: {}", method, path);
|
||||||
|
|
||||||
let params_res = http_params::parse_params(&mut body).await;
|
let params_res = http_params::parse_params(&mut body).await;
|
||||||
|
|
||||||
if let Ok(params) = params_res {
|
if let Ok(params) = params_res {
|
||||||
let pool = Pool::new(&env::var("DATABASE_URL").unwrap());
|
let mysql_pool = Pool::new(&env::var("DATABASE_URL").unwrap());
|
||||||
if let Ok(auth_result) = auth::wall_entry(headers, path, &pool, ¶ms).await {
|
match auth::wall_entry(path, &mysql_pool, ¶ms).await {
|
||||||
// Deal with permissions errors at this point
|
OpenAuth | Good => route_dispatcher(&mysql_pool, &mut response, &method, path, params).await,
|
||||||
match auth_result {
|
NoKey | BadKey => *response.status_mut() = StatusCode::UNAUTHORIZED,
|
||||||
OpenAuth | Good => route_dispatcher(&pool, &mut response, &method, path, params).await,
|
ServerIssue(msg) => {
|
||||||
NoKey | BadKey => {
|
println!("\tAUTH : 500 [{}]", msg);
|
||||||
println!("\tAUTH: NoKey/BadKey");
|
|
||||||
*response.status_mut() = StatusCode::UNAUTHORIZED
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
*response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR;
|
*response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
println!("\tPARSER: Parameter parsing failed");
|
println!("\tPARSER: Parameter parsing failed");
|
||||||
*response.status_mut() = StatusCode::BAD_REQUEST;
|
*response.status_mut() = StatusCode::BAD_REQUEST;
|
||||||
|
Loading…
Reference in New Issue
Block a user