Compare commits
2 Commits
6d87adb2e6
...
e3008262fc
Author | SHA1 | Date |
---|---|---|
hubert | e3008262fc | |
hubert | abc1f367bb |
|
@ -1,19 +1,32 @@
|
|||
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) -> 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> {
|
||||
let result = session.get::<String>("user");
|
||||
match result {
|
||||
Ok(username) => {username.map(|u| User(u))}
|
||||
Err(e) => {None}
|
||||
Err(e) => {
|
||||
println!("{}", e);
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -21,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