From 840a5e9e6f077d0c7cf42d6e8a7089f41fb1ab0e Mon Sep 17 00:00:00 2001 From: KunoiSayami <46131041+KunoiSayami@users.noreply.github.com> Date: Thu, 22 Jul 2021 00:31:18 +0800 Subject: feat(core): Update cookie ttl while visit website * chore: Bump version --- src/datastructures.rs | 9 ++------- src/main.rs | 16 +++++++++------- 2 files changed, 11 insertions(+), 14 deletions(-) (limited to 'src') diff --git a/src/datastructures.rs b/src/datastructures.rs index e004514..0551fcf 100644 --- a/src/datastructures.rs +++ b/src/datastructures.rs @@ -372,12 +372,7 @@ impl ProtectSettings { if !self.protect_enabled { return false; } - let ret = self.repos.iter().any(|x| x.eq(repo)); - if self.protect_white_list_mode { - !ret - } else { - ret - } + self.protect_white_list_mode != self.repos.iter().any(|x| x.eq(repo)) } #[cfg(test)] @@ -415,7 +410,7 @@ impl FormData { } } - pub fn get_string_argon2_hash(s: &str) -> Result { + pub fn gen_string_argon2_hash(s: &str) -> Result { let passwd = s.as_bytes(); let salt = SaltString::generate(&mut OsRng); diff --git a/src/main.rs b/src/main.rs index 00b52a6..46f088f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -89,7 +89,7 @@ impl IOModule { writeln!( &mut self.writer, "Set-Cookie: cgit_auth={}; Domain={}; Max-Age={}; HttpOnly{}", - cookie_value, domain, cfg.cookie_ttl, cookie_suffix + cookie_value, domain, cfg.cookie_ttl * 10, cookie_suffix )?; } else { writeln!(&mut self.writer, "Status: 403 Forbidden")?; @@ -105,12 +105,11 @@ impl IOModule { async fn cmd_authenticate_cookie(matches: &ArgMatches<'_>, cfg: Config) -> Result { let cookies = matches.value_of("http-cookie").unwrap_or(""); let repo = matches.value_of("repo").unwrap_or(""); - let current_url = matches.value_of("current-url").unwrap_or(""); + /*let current_url = matches.value_of("current-url").unwrap_or("");*/ let mut bypass = false; - // TODO: bypass root not working properly if we select sort mode - if cfg.bypass_root && current_url.eq("/") && repo.is_empty() { + if cfg.bypass_root /*&& current_url.eq("/")*/ && repo.is_empty() { bypass = true; } @@ -148,8 +147,11 @@ async fn cmd_authenticate_cookie(matches: &ArgMatches<'_>, cfg: Config) -> Resul .get::<_, String>(format!("cgit_auth_{}", cookie.get_key())) .await { - // TODO: Extend cookie ttl in each authenticate request - //log::debug!("Cookie is valid"); + conn.expire::<_, bool>( + format!("cgit_auth_{}", cookie.get_key()), + cfg.cookie_ttl as usize, + ) + .await?; if cookie.eq_body(r.as_str()) { if repo.is_empty() { return Ok(true); @@ -282,7 +284,7 @@ async fn cmd_add_user(matches: &ArgMatches<'_>, cfg: Config) -> Result<()> { sqlx::query(r#"INSERT INTO "accounts" VALUES (?, ?, ?) "#) .bind(user) - .bind(FormData::get_string_argon2_hash(&passwd)?) + .bind(FormData::gen_string_argon2_hash(&passwd)?) .bind(&uid) .execute(&mut conn) .await?; -- cgit v1.3.1