Skip to content
Snippets Groups Projects
Commit de9a97a7 authored by Phil Höfer's avatar Phil Höfer
Browse files

Implement Authenthication

parent 6e877715
No related branches found
No related tags found
No related merge requests found
Pipeline #9789 passed
...@@ -57,6 +57,21 @@ fn main() -> Result<(), io::Error> { ...@@ -57,6 +57,21 @@ fn main() -> Result<(), io::Error> {
// request.url(), // request.url(),
// request.headers() // request.headers()
// ); // );
match config.get("auth") {
Some(toml::Value::String(server_auth)) => {
match get_authkey(request.url().clone()) {
Ok(client_auth) => {
if client_auth != server_auth.clone() {
println!("invalid auth:{}, server auth: {}", client_auth, server_auth);
request.respond(Response::from_string(""));
continue;
}
},
_ => {}
}
},
_ => {}
}
let query = get_query(request.url()); let query = get_query(request.url());
//println!("got query:{}", query.clone().unwrap()); //println!("got query:{}", query.clone().unwrap());
match query { match query {
...@@ -95,6 +110,18 @@ fn get_query(request_url: &str) -> Result<String, url::ParseError> { ...@@ -95,6 +110,18 @@ fn get_query(request_url: &str) -> Result<String, url::ParseError> {
} }
Ok(String::from_str("").unwrap()) Ok(String::from_str("").unwrap())
} }
fn get_authkey(request_url: &str) -> Result<String, url::ParseError> {
let parsed_url = request_url.split_once('?').map_or(request_url, |(_, after)| after);
//println!("parsed_url:{}", parsed_url);
let query_pairs = url::form_urlencoded::parse(parsed_url.as_bytes());
for (key, value) in query_pairs {
//println!("key:{}, value: {}", key, value);
if key == "auth" {
return Ok(value.into_owned());
}
}
Ok(String::from_str("").unwrap())
}
fn build_markov_chain(file_path: &str) -> Result<MarkovChain, io::Error> { fn build_markov_chain(file_path: &str) -> Result<MarkovChain, io::Error> {
let file = File::open(file_path)?; let file = File::open(file_path)?;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment