You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

28 lines
804 B

  1. use actix_web_httpauth::extractors::basic::BasicAuth;
  2. use crate::AppConfig;
  3. use crate::routes::validate_basic_auth;
  4. use actix_web::{dev::ServiceRequest, web, Error};
  5. pub async fn validator(
  6. req: ServiceRequest,
  7. credentials: BasicAuth,
  8. ) -> Result<ServiceRequest, Error> {
  9. println!("{}", credentials.user_id());
  10. println!("{:?}", credentials.password());
  11. // verify credentials from db
  12. let config = req.app_data::<AppConfig>().expect("Error getting config");
  13. let valid =
  14. web::block(move || validate_basic_auth(credentials, &config)).await?;
  15. if valid {
  16. debug!("Success");
  17. Ok(req)
  18. } else {
  19. Err(crate::errors::DomainError::new_password_error(
  20. "Wrong password or account does not exist".to_string(),
  21. ).into())
  22. }
  23. }