GeneIT/geneit_backend/src/constants.rs

64 lines
1.8 KiB
Rust
Raw Normal View History

use std::time::Duration;
2023-05-24 12:38:18 +00:00
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub struct SizeConstraint {
min: usize,
max: usize,
}
impl SizeConstraint {
pub fn new(min: usize, max: usize) -> Self {
Self { min, max }
}
2023-05-24 14:19:46 +00:00
pub fn validate(&self, val: &str) -> bool {
let len = val.trim().len();
len >= self.min && len <= self.max
}
2023-05-24 12:38:18 +00:00
}
#[derive(Debug, Clone, serde::Serialize)]
pub struct StaticConstraints {
pub mail_len: SizeConstraint,
pub user_name_len: SizeConstraint,
pub password_len: SizeConstraint,
2023-06-16 15:51:51 +00:00
pub family_name_len: SizeConstraint,
2023-06-27 16:52:49 +00:00
pub invitation_code_len: SizeConstraint,
2023-05-24 12:38:18 +00:00
}
impl Default for StaticConstraints {
fn default() -> Self {
Self {
mail_len: SizeConstraint::new(5, 255),
user_name_len: SizeConstraint::new(3, 30),
password_len: SizeConstraint::new(8, 255),
2023-06-16 15:51:51 +00:00
family_name_len: SizeConstraint::new(3, 30),
2023-06-27 16:52:49 +00:00
invitation_code_len: SizeConstraint::new(
FAMILY_INVITATION_CODE_LEN,
FAMILY_INVITATION_CODE_LEN,
),
2023-05-24 12:38:18 +00:00
}
}
}
/// Password reset token duration
pub const PASSWORD_RESET_TOKEN_DURATION: Duration = Duration::from_secs(3600 * 24);
2023-06-02 09:49:18 +00:00
2023-06-06 08:02:41 +00:00
/// Account deletion token duration
pub const ACCOUNT_DELETE_TOKEN_DURATION: Duration = Duration::from_secs(3600 * 12);
2023-06-02 09:49:18 +00:00
/// OpenID state duration
pub const OPEN_ID_STATE_DURATION: Duration = Duration::from_secs(3600);
2023-06-16 15:51:51 +00:00
2023-06-16 16:40:21 +00:00
/// Auth token duration
pub const AUTH_TOKEN_DURATION: Duration = Duration::from_secs(3600 * 24);
/// Minimum interval before heartbeat update
pub const AUTH_TOKEN_HB_MIN_INTERVAL: Duration = Duration::from_secs(60);
/// Auth token max inactivity period
pub const AUTH_TOKEN_MAX_INACTIVITY: Duration = Duration::from_secs(3600);
2023-06-16 15:51:51 +00:00
/// Length of family invitation code
pub const FAMILY_INVITATION_CODE_LEN: usize = 7;