GeneIT/geneit_backend/src/constants.rs

39 lines
955 B
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,
}
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),
}
}
}
/// Password reset token duration
pub const PASSWORD_RESET_TOKEN_DURATION: Duration = Duration::from_secs(3600 * 24);