mirror of
https://forge.pointfixe.fr/hubert/gitust.git
synced 2026-02-04 16:17:30 +01:00
Compare commits
20 Commits
234e2ccaa3
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 6beae6629f | |||
|
|
ba19d67f66 | ||
|
|
f9bc5b2e39 | ||
|
|
dbba11a416 | ||
|
|
edf6f9f81a | ||
|
|
5f6f7b7efe | ||
|
|
1f4d08aff1 | ||
|
|
f71e8ff1b3 | ||
|
|
4134982739 | ||
|
|
1e7c773c19 | ||
|
|
9832f30360 | ||
|
|
22836e1f3a | ||
|
|
90ea298a61 | ||
|
|
e3008262fc | ||
|
|
abc1f367bb | ||
| 6d87adb2e6 | |||
| aa131d009f | |||
|
|
9af4fa56e1 | ||
|
|
90bc6d6d4f | ||
|
|
381347e66a |
12
src/error.rs
12
src/error.rs
@@ -12,18 +12,20 @@ impl Error {
|
|||||||
|
|
||||||
impl From<git2::Error> for Error {
|
impl From<git2::Error> for Error {
|
||||||
fn from(giterr: git2::Error) -> Self {
|
fn from(giterr: git2::Error) -> Self {
|
||||||
// panic!()
|
|
||||||
Error::BadGateway(format!("{}", giterr))
|
Error::BadGateway(format!("{}", giterr))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<std::io::Error> for Error {
|
||||||
|
fn from(ioerr: std::io::Error) -> Self {
|
||||||
|
Error::BadGateway(format!("{}", ioerr))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl From<Error> for actix_web::error::Error {
|
impl From<Error> for actix_web::error::Error {
|
||||||
fn from(e: Error) -> Self {
|
fn from(e: Error) -> Self {
|
||||||
match e {
|
match e {
|
||||||
Error::BadGateway(msg) => {HttpResponseBuilder::new(StatusCode::BAD_GATEWAY).body(msg).into()}
|
Error::BadGateway(msg) => {HttpResponseBuilder::new(StatusCode::BAD_GATEWAY).body(msg).into()}
|
||||||
Error::Unauthorized(msg) => {
|
Error::Unauthorized(realm) => {AuthenticationError::from(basic::Config::default().realm(realm)).into()}}
|
||||||
let config : basic::Config = Default::default();
|
|
||||||
AuthenticationError::from(config).into()}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
pub struct Gitust {
|
pub struct Gitust {
|
||||||
pub repo_root_path : String,
|
pub repo_root_path : String,
|
||||||
|
pub session_key : String,
|
||||||
}
|
}
|
||||||
@@ -14,15 +14,19 @@ use tokio::process::{Child, Command};
|
|||||||
|
|
||||||
use crate::gitust::Gitust;
|
use crate::gitust::Gitust;
|
||||||
use crate::reader::ToStream;
|
use crate::reader::ToStream;
|
||||||
|
use crate::error;
|
||||||
|
use crate::webutils::auth;
|
||||||
|
|
||||||
//#[get("/git/{owner}/{repo}.git/{path:.*}")]
|
//#[get("/git/{owner}/{repo}.git/{path:.*}")]
|
||||||
pub async fn git_proto(
|
pub async fn git_proto<T : auth::AuthValidator>(
|
||||||
mut payload : web::Payload,
|
mut payload : web::Payload,
|
||||||
web::Path((owner, reponame, path)): web::Path<(String, String, String)>,
|
web::Path((owner, reponame, path)): web::Path<(String, String, String)>,
|
||||||
mut req: HttpRequest,
|
mut req: HttpRequest,
|
||||||
gitust : web::Data<Gitust>,
|
gitust : web::Data<Gitust>,
|
||||||
auth : BasicAuth,
|
authenticator : web::Data<T>,
|
||||||
) -> io::Result<HttpResponse>{
|
auth : Option<BasicAuth>,
|
||||||
|
) -> Result<HttpResponse, error::Error>{
|
||||||
|
let user = auth.and_then(|a| authenticator.check_basic(&a)).ok_or(error::Error::Unauthorized("git_proto".to_string()))?;
|
||||||
//println!("enter git_proto");
|
//println!("enter git_proto");
|
||||||
let mut cmd = Command::new("git");
|
let mut cmd = Command::new("git");
|
||||||
cmd.arg("http-backend");
|
cmd.arg("http-backend");
|
||||||
@@ -31,7 +35,7 @@ pub async fn git_proto(
|
|||||||
cmd.env("REQUEST_METHOD", req.method().as_str());
|
cmd.env("REQUEST_METHOD", req.method().as_str());
|
||||||
cmd.env("GIT_PROJECT_ROOT", &gitust.repo_root_path);
|
cmd.env("GIT_PROJECT_ROOT", &gitust.repo_root_path);
|
||||||
cmd.env("PATH_INFO", format!("/{}/{}.git/{}",owner, reponame, path));
|
cmd.env("PATH_INFO", format!("/{}/{}.git/{}",owner, reponame, path));
|
||||||
cmd.env("REMOTE_USER", auth.user_id().to_string());
|
cmd.env("REMOTE_USER", user.get_name());
|
||||||
//cmd.env("REMOTE_ADDR", req.remote_addr().to_string());
|
//cmd.env("REMOTE_ADDR", req.remote_addr().to_string());
|
||||||
cmd.env("QUERY_STRING", req.query_string());
|
cmd.env("QUERY_STRING", req.query_string());
|
||||||
cmd.env("CONTENT_TYPE", header(&req, header::CONTENT_TYPE));
|
cmd.env("CONTENT_TYPE", header(&req, header::CONTENT_TYPE));
|
||||||
|
|||||||
@@ -78,4 +78,28 @@ impl GitRepo {
|
|||||||
return Ok(res);
|
return Ok(res);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn get_revisions_nbr(&self) -> u32 {
|
||||||
|
let mut res = 0;
|
||||||
|
let mut revwalk = self.git2.revwalk().expect("revisions walk is not defined");
|
||||||
|
revwalk.push_head(); // todo : voir ce qu'il faut réellement pousser si on veux avoir TOUS les commits (genre par exemple si le HEAD n'est pas fils de tous les commits)
|
||||||
|
for _ in revwalk{
|
||||||
|
res = res + 1;
|
||||||
|
}
|
||||||
|
res
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_branches_nbr(&self) -> u32 {
|
||||||
|
let mut res = 0;
|
||||||
|
for _ in self.git2.branches(Some(BranchType::Local)){
|
||||||
|
res = res + 1;
|
||||||
|
}
|
||||||
|
res
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_tags_nbr(&self) -> u32 {
|
||||||
|
let mut res = 0;
|
||||||
|
self.git2.tag_foreach(|_,_| {res = res + 1;true});
|
||||||
|
res
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
50
src/main.rs
50
src/main.rs
@@ -9,14 +9,14 @@ use actix_files::Files;
|
|||||||
use actix_session::{CookieSession, Session};
|
use actix_session::{CookieSession, Session};
|
||||||
use actix_web::{App, Error, get, HttpMessage, HttpRequest, HttpResponse, HttpServer, post, Responder};
|
use actix_web::{App, Error, get, HttpMessage, HttpRequest, HttpResponse, HttpServer, post, Responder};
|
||||||
use actix_web::client::PayloadError;
|
use actix_web::client::PayloadError;
|
||||||
use actix_web::dev::ServiceRequest;
|
use actix_web::dev::{ServiceRequest, Service};
|
||||||
use actix_web::http::{header, StatusCode};
|
use actix_web::http::{header, StatusCode};
|
||||||
use actix_web::http::header::Header;
|
use actix_web::http::header::Header;
|
||||||
use actix_web::http::header::IntoHeaderValue;
|
use actix_web::http::header::IntoHeaderValue;
|
||||||
use actix_web::middleware::Logger;
|
use actix_web::middleware::Logger;
|
||||||
use actix_web::web as webx;
|
use actix_web::web as webx;
|
||||||
use actix_web::web::{Buf, Bytes};
|
use actix_web::web::{Buf, Bytes};
|
||||||
use actix_web_httpauth::extractors::AuthenticationError;
|
use actix_web_httpauth::extractors::{AuthenticationError, AuthExtractor};
|
||||||
use actix_web_httpauth::extractors::basic::{BasicAuth, Config};
|
use actix_web_httpauth::extractors::basic::{BasicAuth, Config};
|
||||||
use actix_web_httpauth::headers::authorization::{Authorization, Basic};
|
use actix_web_httpauth::headers::authorization::{Authorization, Basic};
|
||||||
use actix_web_httpauth::middleware::HttpAuthentication;
|
use actix_web_httpauth::middleware::HttpAuthentication;
|
||||||
@@ -34,12 +34,15 @@ use gitutils::gitfile::GitFile;
|
|||||||
use gitutils::gitproto;
|
use gitutils::gitproto;
|
||||||
use gitutils::gitrepo::GitRepo;
|
use gitutils::gitrepo::GitRepo;
|
||||||
use web::repo;
|
use web::repo;
|
||||||
|
use webutils::auth;
|
||||||
|
|
||||||
use crate::git::GitBrowseEntry;
|
use crate::git::GitBrowseEntry;
|
||||||
use crate::gitust::Gitust;
|
use crate::gitust::Gitust;
|
||||||
use crate::ite::SuperIterator;
|
use crate::ite::SuperIterator;
|
||||||
use crate::reader::ToStream;
|
use crate::reader::ToStream;
|
||||||
use crate::writer::Writer;
|
use crate::writer::Writer;
|
||||||
|
use crate::web::repo::GitWebQ;
|
||||||
|
use crate::webutils::auth::{TestValidator, AuthValidator, User};
|
||||||
|
|
||||||
mod git;
|
mod git;
|
||||||
mod ite;
|
mod ite;
|
||||||
@@ -149,25 +152,55 @@ fn validate_credentials(user_id: &str, user_password: Option<&str>) -> Result<bo
|
|||||||
return Err(std::io::Error::new(std::io::ErrorKind::Other, "Authentication failed!"));
|
return Err(std::io::Error::new(std::io::ErrorKind::Other, "Authentication failed!"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Deserialize)]
|
||||||
|
struct LoginQ {
|
||||||
|
login: Option<bool>,
|
||||||
|
}
|
||||||
|
|
||||||
#[actix_web::main]
|
#[actix_web::main]
|
||||||
async fn main() -> std::io::Result<()> {
|
async fn main() -> std::io::Result<()> {
|
||||||
std::env::set_var("RUST_LOG", "actix_web=info");
|
std::env::set_var("RUST_LOG", "actix_web=info");
|
||||||
env_logger::from_env(Env::default().default_filter_or("info")).init();
|
env_logger::from_env(Env::default().default_filter_or("info")).init();
|
||||||
HttpServer::new(|| {
|
HttpServer::new(|| {
|
||||||
let auth = HttpAuthentication::basic(basic_auth_validator);
|
let auth = HttpAuthentication::basic(basic_auth_validator);
|
||||||
|
let gitust = Gitust {
|
||||||
|
repo_root_path: "/home/hubert/gitust".to_string(),
|
||||||
|
session_key: "oWe0ait9bi2Ohyiod2eeXirao1Oochie".to_string(),
|
||||||
|
};
|
||||||
|
let session_key = (&gitust.session_key).as_bytes();
|
||||||
App::new()
|
App::new()
|
||||||
.data(Gitust {
|
|
||||||
repo_root_path: "/home/hubert/gitust".to_string(),
|
|
||||||
})
|
|
||||||
.wrap(Logger::default())
|
.wrap(Logger::default())
|
||||||
// .wrap(Logger::new("%a %{User-Agent}i"))
|
// .wrap(Logger::new("%a %{User-Agent}i"))
|
||||||
.wrap(CookieSession::signed(&[0; 32]).secure(false))
|
.wrap(CookieSession::signed(session_key).secure(false))
|
||||||
|
.data(gitust)
|
||||||
|
.data(auth::TestValidator)
|
||||||
.service(hello)
|
.service(hello)
|
||||||
.service(echo)
|
.service(echo)
|
||||||
.service(hello_test)
|
.service(hello_test)
|
||||||
.service(index)
|
.service(index)
|
||||||
.service(askama)
|
.service(askama)
|
||||||
.service(repo::git_main)
|
.service(
|
||||||
|
webx::resource("/git/{owner}/{repo}.git")
|
||||||
|
.wrap_fn(|req, serv| {
|
||||||
|
let query : Result<webx::Query<LoginQ>, _> = webx::Query::from_query(req.query_string());
|
||||||
|
let authFut = BasicAuth::from_service_request(&req);
|
||||||
|
let resFut = serv.call(req);
|
||||||
|
async {
|
||||||
|
let webx::Query(LoginQ{login}) = query?;
|
||||||
|
match login {
|
||||||
|
Some(true) => {
|
||||||
|
let auth = authFut.await?;
|
||||||
|
match TestValidator.check_basic(&auth) {
|
||||||
|
None => {Err(AuthenticationError::from(Config::default().realm("auth")).into())}
|
||||||
|
Some(_) => {resFut.await}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => {resFut.await}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.route(webx::get().to(repo::git_main::<auth::TestValidator>))
|
||||||
|
)
|
||||||
.service(hello_session)
|
.service(hello_session)
|
||||||
.service(chunk)
|
.service(chunk)
|
||||||
//.service(git_proto)
|
//.service(git_proto)
|
||||||
@@ -183,8 +216,7 @@ async fn main() -> std::io::Result<()> {
|
|||||||
)
|
)
|
||||||
.service(
|
.service(
|
||||||
webx::resource("/git/{user}/{repo}.git/{path:.*}")
|
webx::resource("/git/{user}/{repo}.git/{path:.*}")
|
||||||
// .wrap(auth)
|
.route(webx::route().to(gitproto::git_proto::<auth::TestValidator>))
|
||||||
.route(webx::route().to(gitproto::git_proto))
|
|
||||||
)
|
)
|
||||||
.service(
|
.service(
|
||||||
Files::new("/static", "static")
|
Files::new("/static", "static")
|
||||||
|
|||||||
120
src/web/repo.rs
120
src/web/repo.rs
@@ -1,7 +1,8 @@
|
|||||||
|
use crate::auth::AuthValidator;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
|
||||||
use actix_web::web;
|
use actix_web::web;
|
||||||
use actix_web_httpauth::extractors::basic::BasicAuth;
|
use actix_web_httpauth::extractors::basic;
|
||||||
|
|
||||||
use actix_web::get;
|
use actix_web::get;
|
||||||
use askama_actix::Template;
|
use askama_actix::Template;
|
||||||
@@ -16,6 +17,7 @@ use crate::gitutils::gitdir::GitDir;
|
|||||||
use crate::gitutils::gitfile::GitFile;
|
use crate::gitutils::gitfile::GitFile;
|
||||||
use crate::gitutils::gitrepo::GitRepo;
|
use crate::gitutils::gitrepo::GitRepo;
|
||||||
use crate::ite::SuperIterator;
|
use crate::ite::SuperIterator;
|
||||||
|
use std::fmt::{Display, Formatter};
|
||||||
|
|
||||||
struct User {
|
struct User {
|
||||||
name : String,
|
name : String,
|
||||||
@@ -37,56 +39,122 @@ pub enum Entry {
|
|||||||
|
|
||||||
#[derive(Template)]
|
#[derive(Template)]
|
||||||
#[template(path = "git.html")]
|
#[template(path = "git.html")]
|
||||||
pub struct GitMainTemplate<TS, ROOT>
|
pub struct GitMainTemplate<TS, BREADCRUMB>
|
||||||
where for <'a> &'a TS : IntoIterator<Item = &'a Entry>,
|
where for <'a> &'a TS : IntoIterator<Item = &'a Entry>,
|
||||||
for <'a> &'a ROOT : IntoIterator<Item = &'a (String, String)>,
|
for <'a> &'a BREADCRUMB: IntoIterator<Item = &'a (String, String)>,
|
||||||
{
|
{
|
||||||
repo : Repository,
|
repo : Repository,
|
||||||
browse : TS,
|
browse : TS,
|
||||||
root : ROOT,
|
query : GitWebQ,
|
||||||
|
breadcrumb: BREADCRUMB,
|
||||||
user_opt : Option<User>,
|
user_opt : Option<User>,
|
||||||
|
revisions_nbr : u32,
|
||||||
|
branches_nbr : u32,
|
||||||
|
tags_nbr : u32,
|
||||||
|
size : String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Clone, Deserialize)]
|
||||||
pub struct GitWebQ {
|
pub struct GitWebQ {
|
||||||
commit: Option<String>,
|
commit: Option<String>,
|
||||||
path: Option<String>,
|
path: Option<String>,
|
||||||
branch: Option<String>,
|
branch: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[get("/git/{owner}/{repo}.git")]
|
impl GitWebQ {
|
||||||
pub async fn git_main(
|
fn clone_with_commit(&self, commit : Option<String>) -> GitWebQ {
|
||||||
|
let mut res = self.clone();
|
||||||
|
res.commit = commit;
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
fn clone_with_path(&self, path : Option<String>) -> GitWebQ {
|
||||||
|
let mut res = self.clone();
|
||||||
|
res.path = path;
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
fn clone_with_branch(&self, branch : Option<String>) -> GitWebQ {
|
||||||
|
let mut res = self.clone();
|
||||||
|
res.branch = branch;
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
fn root_query(&self) -> GitWebQ {
|
||||||
|
self.clone_with_path(None)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn add_path(&self, name : &&String) -> GitWebQ {
|
||||||
|
match &self.path {
|
||||||
|
None => {self.clone_with_path(Some(name.to_string()))}
|
||||||
|
Some(path) => {if path.ends_with("/") {
|
||||||
|
self.clone_with_path(Some(path.clone() + name))
|
||||||
|
} else {
|
||||||
|
self.clone_with_path(Some(path.clone() + "/" + name))
|
||||||
|
}}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Display for GitWebQ{
|
||||||
|
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||||
|
write!(f, "?{}{}{}",
|
||||||
|
match &self.commit {
|
||||||
|
None => {"".to_string()}
|
||||||
|
Some(c) => {format!("commit={}", c)}
|
||||||
|
},
|
||||||
|
match &self.path {
|
||||||
|
None => {"".to_string()}
|
||||||
|
Some(p) => {format!("&path={}", p)}
|
||||||
|
},
|
||||||
|
match &self.branch {
|
||||||
|
None => {"".to_string()}
|
||||||
|
Some(b) => {format!("&branch={}", b)}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//#[get("/git/{owner}/{repo}.git")]
|
||||||
|
pub async fn git_main<T : AuthValidator>(
|
||||||
web::Path((ownername, reponame)): web::Path<(String, String)>,
|
web::Path((ownername, reponame)): web::Path<(String, String)>,
|
||||||
web::Query(GitWebQ{commit : commitnameopt, path : pathopt, branch : branchopt}) : web::Query<GitWebQ>,
|
query : web::Query<GitWebQ>,
|
||||||
gitust : web::Data<Gitust>,
|
gitust : web::Data<Gitust>,
|
||||||
auth : Option<BasicAuth>,
|
auth : Option<basic::BasicAuth>,
|
||||||
|
validator : web::Data<T>,
|
||||||
//auth : BasicAuth,
|
//auth : BasicAuth,
|
||||||
) -> Result<GitMainTemplate<Vec<Entry>, Vec<(String, String)>>, error::Error> {
|
) -> Result<GitMainTemplate<Vec<Entry>, Vec<(String, String)>>, error::Error> {
|
||||||
let rootname = match pathopt {
|
// let authtorization = auth.ok_or(error::Error::Unauthorized("safe repo".to_string()))?;
|
||||||
|
//let authorization = auth.and_then(|cred| validator.check_basic(&cred)).ok_or(error::Error::Unauthorized("safe repo".to_string()))?;
|
||||||
|
let web::Query(query_struct) = query;
|
||||||
|
// let GitWebQ{commit : commitnameopt, path : pathopt, branch : branchopt} = query_struct;
|
||||||
|
let rootname = match &query_struct.path {
|
||||||
None => {"".to_string()}
|
None => {"".to_string()}
|
||||||
Some(s) => {
|
Some(s) => {
|
||||||
if s.starts_with("/") {
|
if s.starts_with("/") {
|
||||||
(&s[1..]).to_string()
|
(&s[1..]).to_string()
|
||||||
} else {
|
} else {
|
||||||
s
|
s.clone()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let commit = match commitnameopt {
|
let commit = match &query_struct.commit {
|
||||||
None => {match branchopt {
|
None => {match &query_struct.branch {
|
||||||
None => {GitRef::Head}
|
None => {GitRef::Head}
|
||||||
Some(s) => {GitRef::Branch(s)}
|
Some(s) => {GitRef::Branch(s.clone())}
|
||||||
}}
|
}}
|
||||||
Some(s) => {GitRef::Commit(s)}
|
Some(s) => {GitRef::Commit(s.clone())}
|
||||||
};
|
};
|
||||||
let owner = Owner { name : ownername};
|
let owner = Owner { name : ownername};
|
||||||
let repo = Repository {name : reponame, owner};
|
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
|
// 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 path = rootname.split("/").map_accum(query_struct.clone_with_path(Some("".to_string())), |direname, b| {
|
||||||
let href = b + "/" + str_ref;
|
let newpath = (&b.path).as_ref().map(|path| {path.clone() + "/" + direname});
|
||||||
((str_ref.to_string(), href.clone()), href)
|
let newb = b.clone_with_path(newpath);
|
||||||
|
((direname.to_string(), format!("{}", newb)), newb)
|
||||||
}).collect();
|
}).collect();
|
||||||
let gitrepo = GitRepo::new(format!("{}/{}/{}.git", &gitust.repo_root_path, &repo.owner.name, &repo.name).as_str())?;
|
let gitrepo = GitRepo::new(format!("{}/{}/{}.git", &gitust.repo_root_path, &repo.owner.name, &repo.name).as_str())?;
|
||||||
let root = gitrepo.get_tree(&commit, Path::new(rootname.as_str()))?;
|
let root = gitrepo.get_tree(&commit, Path::new(rootname.as_str()))?;
|
||||||
@@ -104,5 +172,17 @@ pub async fn git_main(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(GitMainTemplate { repo, browse : entries, root : path, user_opt : Some(user)})
|
Ok(GitMainTemplate {
|
||||||
|
repo,
|
||||||
|
browse : entries,
|
||||||
|
query : query_struct,
|
||||||
|
breadcrumb: path,
|
||||||
|
user_opt : user,
|
||||||
|
revisions_nbr : gitrepo.get_revisions_nbr(),
|
||||||
|
branches_nbr : gitrepo.get_branches_nbr(),
|
||||||
|
tags_nbr : gitrepo.get_tags_nbr(),
|
||||||
|
size : "16 KiB".to_string(),
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,48 @@
|
|||||||
|
use actix_session::Session;
|
||||||
use actix_web_httpauth::extractors::basic::BasicAuth;
|
use actix_web_httpauth::extractors::basic::BasicAuth;
|
||||||
use std::borrow::Cow;
|
|
||||||
|
|
||||||
pub fn check_user(auth : BasicAuth) -> bool {
|
pub trait AuthValidator {
|
||||||
match auth.password() {
|
fn check_user(&self, name : &String, pwd : &String) -> bool;
|
||||||
None => {false}
|
|
||||||
Some(pwd) => {pwd.to_string().eq(&(auth.user_id().to_string() + "pwd"))}
|
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()))
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct TestValidator;
|
||||||
|
|
||||||
|
impl AuthValidator for TestValidator {
|
||||||
|
fn check_user(&self, name: &String, pwd: &String) -> bool {
|
||||||
|
pwd.eq(&(name.clone() + "pwd"))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct User(String);
|
||||||
|
|
||||||
|
impl User {
|
||||||
|
pub fn get_name(&self) -> String {
|
||||||
|
self.0.clone()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1 +1,2 @@
|
|||||||
pub mod auth;
|
pub mod auth;
|
||||||
|
pub mod user;
|
||||||
0
src/webutils/user.rs
Normal file
0
src/webutils/user.rs
Normal file
@@ -26,7 +26,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{% when None %}
|
{% when None %}
|
||||||
<a href="#" class="w3-bar-item w3-button w3-right"><i class="fa fa-sign-in"></i> Log in</a>
|
<a href="?login=true" class="w3-bar-item w3-button w3-right"><i class="fa fa-sign-in"></i> Log in</a>
|
||||||
{% endmatch %}
|
{% endmatch %}
|
||||||
</div>
|
</div>
|
||||||
{% block content %}{% endblock %}
|
{% block content %}{% endblock %}
|
||||||
|
|||||||
@@ -26,16 +26,16 @@
|
|||||||
|
|
||||||
<div class="w3-panel w3-border w3-cell-row">
|
<div class="w3-panel w3-border w3-cell-row">
|
||||||
<div class="w3-center w3-cell">
|
<div class="w3-center w3-cell">
|
||||||
<i class="fa fa-history"></i> 112 revisions
|
<i class="fa fa-history"></i> {{ revisions_nbr }} revisions
|
||||||
</div>
|
</div>
|
||||||
<div class="w3-center w3-cell">
|
<div class="w3-center w3-cell">
|
||||||
<i class="fa fa-code-branch"></i> 10 branches
|
<i class="fa fa-code-branch"></i> {{ branches_nbr }} branches
|
||||||
</div>
|
</div>
|
||||||
<div class="w3-center w3-cell">
|
<div class="w3-center w3-cell">
|
||||||
<i class="fa fa-tag"></i> 5 tags
|
<i class="fa fa-tag"></i> {{ tags_nbr }} tags
|
||||||
</div>
|
</div>
|
||||||
<div class="w3-center w3-cell">
|
<div class="w3-center w3-cell">
|
||||||
<i class="fa fa-database"></i> 10 KiB
|
<i class="fa fa-database"></i> {{ size }}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -60,8 +60,8 @@
|
|||||||
<div class="w3-cell-row">
|
<div class="w3-cell-row">
|
||||||
<div class="w3-cell">
|
<div class="w3-cell">
|
||||||
<ul class="breadcrumb">
|
<ul class="breadcrumb">
|
||||||
<li><a href="#">{{repo.name}}</a></li>
|
<li><a href="{{query.root_query()}}">{{repo.name}}.git</a></li>
|
||||||
{% for (dir, prev) in root %}
|
{% for (dir, prev) in breadcrumb %}
|
||||||
<li><a href="{{prev}}">{{dir}}</a></li>
|
<li><a href="{{prev}}">{{dir}}</a></li>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</ul>
|
</ul>
|
||||||
@@ -77,7 +77,7 @@
|
|||||||
{% for entry in browse %}
|
{% for entry in browse %}
|
||||||
{% match entry %}
|
{% match entry %}
|
||||||
{% when Entry::Dir with (name) %}
|
{% when Entry::Dir with (name) %}
|
||||||
<li><i class="fa fa-folder"></i> {{ name }}</li>
|
<li><i class="fa fa-folder"></i> <a href="{{query.add_path(name)}}">{{ name }}</a></li>
|
||||||
{% when Entry::File with (name) %}
|
{% when Entry::File with (name) %}
|
||||||
<li><i class="fa fa-file"></i> {{ name }}</li>
|
<li><i class="fa fa-file"></i> {{ name }}</li>
|
||||||
{% endmatch %}
|
{% endmatch %}
|
||||||
|
|||||||
Reference in New Issue
Block a user