From 06db56e40820ec0067d18840648ee786163a3862 Mon Sep 17 00:00:00 2001 From: jikstra Date: Sun, 25 Apr 2021 17:48:09 +0200 Subject: Implement a raw rendering mode for recursive folder download - Raw mode only displays file/folders and is more focused on computer processing - Display a banner in footer to recursively download the current folder with wget --- src/auth.rs | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'src/auth.rs') diff --git a/src/auth.rs b/src/auth.rs index 0d97f11..43aca17 100644 --- a/src/auth.rs +++ b/src/auth.rs @@ -42,7 +42,7 @@ pub struct RequiredAuth { } /// Return `true` if `basic_auth` is matches any of `required_auth` -pub fn match_auth(basic_auth: BasicAuthParams, required_auth: &[RequiredAuth]) -> bool { +pub fn match_auth(basic_auth: &BasicAuthParams, required_auth: &[RequiredAuth]) -> bool { required_auth .iter() .any(|RequiredAuth { username, password }| { @@ -74,6 +74,9 @@ pub fn get_hash(text: &str) -> Vec { hasher.update(text); hasher.finalize().to_vec() } +pub struct CurrentUser { + pub name: String, +} fn handle_auth(req: &HttpRequest) -> Result<(), ContextualError> { let required_auth = &req.app_data::().unwrap().auth; @@ -85,7 +88,12 @@ fn handle_auth(req: &HttpRequest) -> Result<(), ContextualError> { match BasicAuthParams::try_from_request(req) { Ok(cred) => match match_auth(cred, required_auth) { - true => Ok(()), + true => { + req.extensions_mut().insert(CurrentUser { + name: cred_params.username, + }); + Ok(()) + }, false => Err(ContextualError::InvalidHttpCredentials), }, Err(_) => Err(ContextualError::RequireHttpCredentials), @@ -173,7 +181,7 @@ mod tests { ) { assert_eq!( match_auth( - BasicAuthParams { + &BasicAuthParams { username: param_username.to_owned(), password: param_password.to_owned(), }, @@ -214,7 +222,7 @@ mod tests { password: &str, ) { assert!(match_auth( - BasicAuthParams { + &BasicAuthParams { username: username.to_owned(), password: password.to_owned(), }, @@ -225,7 +233,7 @@ mod tests { #[rstest] fn test_multiple_auth_wrong_username(account_sample: Vec) { assert_eq!(match_auth( - BasicAuthParams { + &BasicAuthParams { username: "unregistered user".to_owned(), password: "pwd0".to_owned(), }, @@ -248,7 +256,7 @@ mod tests { password: &str, ) { assert_eq!(match_auth( - BasicAuthParams { + &BasicAuthParams { username: username.to_owned(), password: password.to_owned(), }, -- cgit v1.2.3 From b94bb361e30e90656edfce5f9a63d41452ba100f Mon Sep 17 00:00:00 2001 From: jikstra Date: Thu, 2 Sep 2021 15:33:58 +0200 Subject: Fix rebase --- src/auth.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/auth.rs') diff --git a/src/auth.rs b/src/auth.rs index 43aca17..efdeefb 100644 --- a/src/auth.rs +++ b/src/auth.rs @@ -87,10 +87,10 @@ fn handle_auth(req: &HttpRequest) -> Result<(), ContextualError> { } match BasicAuthParams::try_from_request(req) { - Ok(cred) => match match_auth(cred, required_auth) { + Ok(cred) => match match_auth(&cred, required_auth) { true => { req.extensions_mut().insert(CurrentUser { - name: cred_params.username, + name: cred.username }); Ok(()) }, -- cgit v1.2.3 From 680b0d001d58a32b0caac3263103dbd9ddb5fe84 Mon Sep 17 00:00:00 2001 From: jikstra Date: Thu, 2 Sep 2021 15:50:35 +0200 Subject: cargo fmt & cargo clippy --- src/auth.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/auth.rs') diff --git a/src/auth.rs b/src/auth.rs index efdeefb..82b407c 100644 --- a/src/auth.rs +++ b/src/auth.rs @@ -90,10 +90,10 @@ fn handle_auth(req: &HttpRequest) -> Result<(), ContextualError> { Ok(cred) => match match_auth(&cred, required_auth) { true => { req.extensions_mut().insert(CurrentUser { - name: cred.username + name: cred.username, }); Ok(()) - }, + } false => Err(ContextualError::InvalidHttpCredentials), }, Err(_) => Err(ContextualError::RequireHttpCredentials), -- cgit v1.2.3