change validator api
This commit is contained in:
parent
abc1f367bb
commit
e3008262fc
|
@ -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<User>;
|
||||
fn check_user(&self, name : &String, pwd : &String) -> bool;
|
||||
|
||||
fn check_basic(&self, basic : &BasicAuth) -> Option<User> {
|
||||
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<User> {
|
||||
|
@ -23,12 +34,8 @@ pub trait AuthValidator {
|
|||
pub struct TestValidator;
|
||||
|
||||
impl AuthValidator for TestValidator {
|
||||
fn check_user(&self, name: &String, pwd: &String) -> Option<User> {
|
||||
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"))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue