|
@ -39,13 +39,12 @@ pub struct User { |
|
|
|
|
|
|
|
|
/// Local methods
|
|
|
/// Local methods
|
|
|
impl User { |
|
|
impl User { |
|
|
pub fn new(mail: String, key: String, password: String) -> Self { |
|
|
pub fn new(mail: String) -> Self { |
|
|
let now = Utc::now().naive_utc(); |
|
|
let now = Utc::now().naive_utc(); |
|
|
let email = mail.to_lowercase(); |
|
|
let email = mail.to_lowercase(); |
|
|
|
|
|
|
|
|
let iterations = CONFIG.password_iterations; |
|
|
let iterations = CONFIG.password_iterations; |
|
|
let salt = crypto::get_random_64(); |
|
|
let salt = crypto::get_random_64(); |
|
|
let password_hash = crypto::hash_password(password.as_bytes(), &salt, iterations as u32); |
|
|
|
|
|
|
|
|
|
|
|
Self { |
|
|
Self { |
|
|
uuid: Uuid::new_v4().to_string(), |
|
|
uuid: Uuid::new_v4().to_string(), |
|
@ -53,9 +52,9 @@ impl User { |
|
|
updated_at: now, |
|
|
updated_at: now, |
|
|
name: email.clone(), |
|
|
name: email.clone(), |
|
|
email, |
|
|
email, |
|
|
key, |
|
|
key: String::new(), |
|
|
|
|
|
|
|
|
password_hash, |
|
|
password_hash: Vec::new(), |
|
|
salt, |
|
|
salt, |
|
|
password_iterations: iterations, |
|
|
password_iterations: iterations, |
|
|
|
|
|
|
|
@ -73,10 +72,6 @@ impl User { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
pub fn new_invited(mail: String) -> Self { |
|
|
|
|
|
Self::new(mail,"".to_string(),"".to_string()) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
pub fn check_valid_password(&self, password: &str) -> bool { |
|
|
pub fn check_valid_password(&self, password: &str) -> bool { |
|
|
crypto::verify_password_hash(password.as_bytes(), |
|
|
crypto::verify_password_hash(password.as_bytes(), |
|
|
&self.salt, |
|
|
&self.salt, |
|
|