1 #[macro_use] pub extern crate strum_macros;
2 #[macro_use] pub extern crate lazy_static;
3 #[macro_use] pub extern crate failure;
4 #[macro_use] pub extern crate diesel;
5 pub extern crate dotenv;
6 pub extern crate chrono;
7 pub extern crate serde;
8 pub extern crate serde_json;
9 pub extern crate actix;
10 pub extern crate actix_web;
11 pub extern crate rand;
12 pub extern crate strum;
13 pub extern crate jsonwebtoken;
14 pub extern crate bcrypt;
15 pub extern crate regex;
26 use chrono::{DateTime, NaiveDateTime, Utc};
38 db_url: env::var("DATABASE_URL")
39 .expect("DATABASE_URL must be set"),
40 hostname: env::var("HOSTNAME").unwrap_or("rrr".to_string()),
41 jwt_secret: env::var("JWT_SECRET").unwrap_or("changeme".to_string()),
44 fn api_endpoint(&self) -> String {
45 format!("{}/api/v1", self.hostname)
49 pub fn to_datetime_utc(ndt: NaiveDateTime) -> DateTime<Utc> {
50 DateTime::<Utc>::from_utc(ndt, Utc)
53 pub fn naive_now() -> NaiveDateTime {
54 chrono::prelude::Utc::now().naive_utc()
57 pub fn naive_from_unix(time: i64) -> NaiveDateTime {
58 NaiveDateTime::from_timestamp(time, 0)
61 pub fn is_email_regex(test: &str) -> bool {
62 EMAIL_REGEX.is_match(test)
65 pub fn remove_slurs(test: &str) -> String {
66 SLUR_REGEX.replace_all(test, "*removed*").to_string()
69 pub fn has_slurs(test: &str) -> bool {
70 SLUR_REGEX.is_match(test)
75 use {Settings, is_email_regex, remove_slurs, has_slurs};
78 assert_eq!(Settings::get().api_endpoint(), "rrr/api/v1");
81 #[test] fn test_email() {
82 assert!(is_email_regex("gush@gmail.com"));
83 assert!(!is_email_regex("nada_neutho"));
86 #[test] fn test_slur_filter() {
87 let test = "coons test dindu ladyboy tranny. This is a bunch of other safe text.".to_string();
88 let slur_free = "No slurs here";
89 assert_eq!(remove_slurs(&test), "*removed* test *removed* *removed* *removed*. This is a bunch of other safe text.".to_string());
90 assert!(has_slurs(&test));
91 assert!(!has_slurs(slur_free));
97 static ref EMAIL_REGEX: Regex = Regex::new(r"^[a-zA-Z0-9.!#$%&’*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$").unwrap();
98 static ref SLUR_REGEX: Regex = Regex::new(r"(fag(g|got|tard)?|maricos?|cock\s?sucker(s|ing)?|\bnig(\b|g?(a|er)?s?)\b|dindu(s?)|mudslime?s?|kikes?|mongoloids?|towel\s*heads?|\bspi(c|k)s?\b|\bchinks?|niglets?|beaners?|\bnips?\b|\bcoons?\b|jungle\s*bunn(y|ies?)|jigg?aboo?s?|\bpakis?\b|rag\s*heads?|gooks?|cunts?|bitch(es|ing|y)?|puss(y|ies?)|twats?|feminazis?|whor(es?|ing)|\bslut(s|t?y)?|\btrann?(y|ies?)|ladyboy(s?))").unwrap();