user from basic auth

This commit is contained in:
Hubert
2021-07-21 06:05:54 +02:00
parent 234e2ccaa3
commit 381347e66a
3 changed files with 7 additions and 9 deletions

View File

@@ -1,7 +1,7 @@
use std::path::Path;
use actix_web::web;
use actix_web_httpauth::extractors::basic::BasicAuth;
use actix_web_httpauth::extractors::basic;
use actix_web::get;
use askama_actix::Template;
@@ -60,9 +60,10 @@ pub async fn git_main(
web::Path((ownername, reponame)): web::Path<(String, String)>,
web::Query(GitWebQ{commit : commitnameopt, path : pathopt, branch : branchopt}) : web::Query<GitWebQ>,
gitust : web::Data<Gitust>,
auth : Option<BasicAuth>,
auth : Option<basic::BasicAuth>,
//auth : BasicAuth,
) -> Result<GitMainTemplate<Vec<Entry>, Vec<(String, String)>>, error::Error> {
// let authtorization = auth.ok_or(error::Error::Unauthorized("safe repo".to_string()))?;
let rootname = match pathopt {
None => {"".to_string()}
Some(s) => {
@@ -82,7 +83,8 @@ pub async fn git_main(
};
let owner = Owner { name : ownername};
let repo = Repository {name : reponame, owner};
let user = User { name : "Hubert".to_string()};
// let user = User { name : "Hubert".to_string()};
let user = auth.map(|auth| User{name : auth.user_id().to_string()});
// il faut ajouter le commit/branch dans la query
let path = rootname.split("/").map_accum("/git/".to_string() + &repo.owner.name + "/" + &repo.name, |str_ref, b| {
let href = b + "/" + str_ref;
@@ -104,5 +106,5 @@ pub async fn git_main(
}
}
}
Ok(GitMainTemplate { repo, browse : entries, root : path, user_opt : Some(user)})
Ok(GitMainTemplate { repo, browse : entries, root : path, user_opt : user})
}