user-service 0.4.1

A user management microservice.
Documentation
use lazy_static::lazy_static;
use regex::Regex;
use time::Date;

pub fn email(email: &str) -> bool {
    if email.len() > 64 {
        return false;
    }

    lazy_static! {
        static ref RE: Regex =
            Regex::new(r"^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$").unwrap();
    }
    RE.is_match(email)
}

pub fn password(password: &str) -> bool {
    if password.len() < 8 || password.len() > 64 {
        return false;
    }

    true
}

pub fn first_name(first_name: &str) -> bool {
    name(first_name)
}

pub fn last_name(last_name: &str) -> bool {
    name(last_name)
}

fn name(name: &str) -> bool {
    lazy_static! {
        static ref RE: Regex = Regex::new(r"^[a-zA-Z]{2,32}$").unwrap();
    }
    RE.is_match(name)
}

pub fn birthday(birthday: &Date) -> bool {
    birthday >= &Date::from_ordinal_date(1900, 1).unwrap()
}

pub fn token_name(token_name: &str) -> bool {
    lazy_static! {
        static ref RE: Regex = Regex::new(r"^[a-zA-Z0-9 ]{1,64}$").unwrap();
    }
    RE.is_match(token_name)
}