diff --git a/src/webutils/auth.rs b/src/webutils/auth.rs index 89d5efa..752a201 100644 --- a/src/webutils/auth.rs +++ b/src/webutils/auth.rs @@ -2,10 +2,21 @@ use actix_session::Session; use actix_web_httpauth::extractors::basic::BasicAuth; pub trait AuthValidator { - fn check_user(&self, name : &String, pwd : &String) -> Option; + fn check_user(&self, name : &String, pwd : &String) -> bool; fn check_basic(&self, basic : &BasicAuth) -> Option { - basic.password().and_then(|pwd| self.check_user(&basic.user_id().to_string(), &pwd.to_string())) + match basic.password() { + Option::Some(pwd) => { + let username = basic.user_id().to_string(); + if self.check_user(&username, &pwd.to_string()) { + Some(User(username)) + } else { + None + } + } + Option::None => {None} + } + //basic.password().and_then(|pwd| self.check_user(&basic.user_id().to_string(), &pwd.to_string())) } fn check_session(&self, session : &Session) -> Option { @@ -23,12 +34,8 @@ pub trait AuthValidator { pub struct TestValidator; impl AuthValidator for TestValidator { - fn check_user(&self, name: &String, pwd: &String) -> Option { - if pwd.eq(&(name.clone() + "pwd")) { - Some(User(name.clone())) - } else { - None - } + fn check_user(&self, name: &String, pwd: &String) -> bool { + pwd.eq(&(name.clone() + "pwd")) } }