#[allow(deprecated)]
use reinhardt_conf::Settings;
use std::time::Duration;
#[non_exhaustive]
#[derive(Debug, Clone)]
pub struct SessionConfig {
pub cookie_name: String,
pub ttl: Duration,
pub secure: bool,
pub http_only: bool,
pub same_site: Option<String>,
pub domain: Option<String>,
pub path: String,
}
impl SessionConfig {
pub fn new(cookie_name: String, ttl: Duration) -> Self {
Self {
cookie_name,
ttl,
secure: true,
http_only: true,
same_site: Some("Lax".to_string()),
domain: None,
path: "/".to_string(),
}
}
pub fn with_secure(mut self) -> Self {
self.secure = true;
self
}
pub fn with_http_only(mut self, http_only: bool) -> Self {
self.http_only = http_only;
self
}
pub fn with_same_site(mut self, same_site: String) -> Self {
self.same_site = Some(same_site);
self
}
pub fn with_domain(mut self, domain: String) -> Self {
self.domain = Some(domain);
self
}
pub fn with_path(mut self, path: String) -> Self {
self.path = path;
self
}
#[allow(deprecated)] pub fn from_settings(settings: &Settings) -> Self {
Self {
secure: settings.core.security.session_cookie_secure,
..Self::default()
}
}
}
impl Default for SessionConfig {
fn default() -> Self {
Self::new("sessionid".to_string(), Duration::from_secs(3600))
}
}