session lifetime

This commit is contained in:
Mateusz Gruszczyński
2026-07-22 23:49:16 +02:00
parent e998a38e49
commit 3ed74b1eac
20 changed files with 262 additions and 74 deletions
+14
View File
@@ -14,6 +14,8 @@ pub struct Config {
pub registration_enabled: bool,
pub account_confirmation_required: bool,
pub frontend_log_level: String,
pub anonymous_access_token_ttl_days: i64,
pub user_session_ttl_days: i64,
}
impl Config {
@@ -25,6 +27,8 @@ impl Config {
let upload_max_size_mb: usize =
env_var("UPLOAD_MAX_SIZE_MB", "20").parse()?;
let anonymous_access_token_ttl_days = env_positive_i64("ANONYMOUS_ACCESS_TOKEN_TTL_DAYS", 7)?;
let user_session_ttl_days = env_positive_i64("USER_SESSION_TTL_DAYS", 30)?;
if upload_max_size_mb == 0 {
return Err("UPLOAD_MAX_SIZE_MB must be greater than 0".into());
@@ -60,6 +64,8 @@ impl Config {
registration_enabled: env_bool("REGISTRATION_ENABLED", false)?,
account_confirmation_required: env_bool("ACCOUNT_CONFIRMATION_REQUIRED", false)?,
frontend_log_level: env_log_level("FRONTEND_LOG_LEVEL", "warn")?,
anonymous_access_token_ttl_days,
user_session_ttl_days,
})
}
}
@@ -86,3 +92,11 @@ fn env_log_level(name: &str, default: &str) -> Result<String, Box<dyn std::error
_ => Err(format!("{name} must be one of: off, error, warn, info, debug").into()),
}
}
fn env_positive_i64(name: &str, default: i64) -> Result<i64, Box<dyn std::error::Error>> {
let value: i64 = env_var(name, &default.to_string()).parse()?;
if value <= 0 {
return Err(format!("{name} must be greater than 0").into());
}
Ok(value)
}