Compare commits
No commits in common. "e3008262fcd3a9e90d2adff127b1806742fa7b7e" and "6d87adb2e6dae1950730c0fcdcb1b244513c120a" have entirely different histories.
e3008262fc
...
6d87adb2e6
|
@ -1,32 +1,19 @@
|
|||
use actix_session::Session;
|
||||
use actix_web::Error;
|
||||
use actix_web_httpauth::extractors::basic::BasicAuth;
|
||||
|
||||
pub trait AuthValidator {
|
||||
fn check_user(&self, name : &String, pwd : &String) -> bool;
|
||||
fn check_user(&self, name : &String, pwd : &String) -> Option<User>;
|
||||
|
||||
fn check_basic(&self, basic : &BasicAuth) -> Option<User> {
|
||||
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()))
|
||||
basic.password().and_then(|pwd| self.check_user(&basic.user_id().to_string(), &pwd.to_string()))
|
||||
}
|
||||
|
||||
fn check_session(&self, session : &Session) -> Option<User> {
|
||||
let result = session.get::<String>("user");
|
||||
match result {
|
||||
Ok(username) => {username.map(|u| User(u))}
|
||||
Err(e) => {
|
||||
println!("{}", e);
|
||||
None
|
||||
}
|
||||
Err(e) => {None}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -34,8 +21,12 @@ pub trait AuthValidator {
|
|||
pub struct TestValidator;
|
||||
|
||||
impl AuthValidator for TestValidator {
|
||||
fn check_user(&self, name: &String, pwd: &String) -> bool {
|
||||
pwd.eq(&(name.clone() + "pwd"))
|
||||
fn check_user(&self, name: &String, pwd: &String) -> Option<User> {
|
||||
if pwd.eq(&(name.clone() + "pwd")) {
|
||||
Some(User(name.clone()))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue