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 base64;
|
||||
extern crate serde;
|
||||
extern crate jsonwebtoken;
|
||||
#[macro_use] extern crate lazy_static;
|
||||
|
||||
use std::net::SocketAddr;
|
||||
use std::convert::Infallible; // our main dispatcher basically never fails hence why we use this
|
||||
@ -79,26 +81,20 @@ async fn main_responder(request: Request<Body>) -> Result<Response<Body>, hyper:
|
||||
let (parts, mut body) = request.into_parts();
|
||||
let method = parts.method;
|
||||
let path = parts.uri.path();
|
||||
let headers = parts.headers;
|
||||
println!("{}: {}", method, path);
|
||||
|
||||
let params_res = http_params::parse_params(&mut body).await;
|
||||
|
||||
if let Ok(params) = params_res {
|
||||
let pool = Pool::new(&env::var("DATABASE_URL").unwrap());
|
||||
if let Ok(auth_result) = auth::wall_entry(headers, path, &pool, ¶ms).await {
|
||||
// Deal with permissions errors at this point
|
||||
match auth_result {
|
||||
OpenAuth | Good => route_dispatcher(&pool, &mut response, &method, path, params).await,
|
||||
NoKey | BadKey => {
|
||||
println!("\tAUTH: NoKey/BadKey");
|
||||
*response.status_mut() = StatusCode::UNAUTHORIZED
|
||||
},
|
||||
let mysql_pool = Pool::new(&env::var("DATABASE_URL").unwrap());
|
||||
match auth::wall_entry(path, &mysql_pool, ¶ms).await {
|
||||
OpenAuth | Good => route_dispatcher(&mysql_pool, &mut response, &method, path, params).await,
|
||||
NoKey | BadKey => *response.status_mut() = StatusCode::UNAUTHORIZED,
|
||||
ServerIssue(msg) => {
|
||||
println!("\tAUTH : 500 [{}]", msg);
|
||||
*response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR;
|
||||
}
|
||||
}
|
||||
else {
|
||||
*response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR;
|
||||
}
|
||||
}
|
||||
else {
|
||||
println!("\tPARSER: Parameter parsing failed");
|
||||
|
Loading…
Reference in New Issue
Block a user