From 9af4fa56e174de927c43cdf326db1e52d2e44104 Mon Sep 17 00:00:00 2001 From: Hubert Date: Wed, 21 Jul 2021 07:03:27 +0200 Subject: [PATCH] save --- src/webutils/auth.rs | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/webutils/auth.rs b/src/webutils/auth.rs index b918f1e..03d158b 100644 --- a/src/webutils/auth.rs +++ b/src/webutils/auth.rs @@ -1,6 +1,21 @@ use actix_web_httpauth::extractors::basic::BasicAuth; use std::borrow::Cow; -pub fn check_user(name : String, pwd : String) -> bool { - pwd.eq(&(name + "pwd")) //stub! +pub trait AuthValidator { + fn check_user(&self, name : &String, pwd : &String) -> bool; + + fn check_basic(&self, basic : BasicAuth) -> bool { + match basic.password() { + None => {false} + Some(pwd) => {self.check_user(&basic.user_id().to_string(), &pwd.to_string())} + } + } +} + +pub struct TestValidator; + +impl AuthValidator for TestValidator { + fn check_user(&self, name: &String, pwd: &String) -> bool { + pwd.eq(&(name.clone() + "pwd")) //stub! + } } \ No newline at end of file