aboutsummaryrefslogtreecommitdiff
path: root/src/db/models
diff options
context:
space:
mode:
authorEmil Madsen <[email protected]>2019-05-20 19:53:18 +0200
committerEmil Madsen <[email protected]>2019-05-20 19:53:18 +0200
commit85c8a01f4a0f51efb2432396743878477529b72f (patch)
treed4c52fc8abc730221494bedfaf60b67b2e480183 /src/db/models
parent42af7c6dab113388a0db4fae0c196bae14761bc1 (diff)
parent08a445e2acb911b09ed0e3b56b03f905635fe5c6 (diff)
downloadvaultwarden-85c8a01f4a0f51efb2432396743878477529b72f.tar.gz
vaultwarden-85c8a01f4a0f51efb2432396743878477529b72f.zip
Merge branch 'master' of github.com:Skeen/bitwarden_rs
Diffstat (limited to 'src/db/models')
-rw-r--r--src/db/models/cipher.rs2
-rw-r--r--src/db/models/two_factor.rs15
-rw-r--r--src/db/models/user.rs31
3 files changed, 28 insertions, 20 deletions
diff --git a/src/db/models/cipher.rs b/src/db/models/cipher.rs
index 47d2784a..21cabb90 100644
--- a/src/db/models/cipher.rs
+++ b/src/db/models/cipher.rs
@@ -72,9 +72,7 @@ use crate::error::MapResult;
/// Database methods
impl Cipher {
pub fn to_json(&self, host: &str, user_uuid: &str, conn: &DbConn) -> Value {
- use super::Attachment;
use crate::util::format_date;
- use serde_json;
let attachments = Attachment::find_by_cipher(&self.uuid, conn);
let attachments_json: Vec<Value> = attachments.iter().map(|c| c.to_json(host)).collect();
diff --git a/src/db/models/two_factor.rs b/src/db/models/two_factor.rs
index 0772ef99..fc48313d 100644
--- a/src/db/models/two_factor.rs
+++ b/src/db/models/two_factor.rs
@@ -42,21 +42,6 @@ impl TwoFactor {
}
}
- pub fn check_totp_code(&self, totp_code: u64) -> bool {
- let totp_secret = self.data.as_bytes();
-
- use data_encoding::BASE32;
- use oath::{totp_raw_now, HashType};
-
- let decoded_secret = match BASE32.decode(totp_secret) {
- Ok(s) => s,
- Err(_) => return false,
- };
-
- let generated = totp_raw_now(&decoded_secret, 6, 0, 30, &HashType::SHA1);
- generated == totp_code
- }
-
pub fn to_json(&self) -> Value {
json!({
"Enabled": self.enabled,
diff --git a/src/db/models/user.rs b/src/db/models/user.rs
index c447a922..150a97b0 100644
--- a/src/db/models/user.rs
+++ b/src/db/models/user.rs
@@ -37,6 +37,12 @@ pub struct User {
pub client_kdf_iter: i32,
}
+enum UserStatus {
+ Enabled = 0,
+ Invited = 1,
+ _Disabled = 2,
+}
+
/// Local methods
impl User {
pub const CLIENT_KDF_TYPE_DEFAULT: i32 = 0; // PBKDF2: 0
@@ -113,14 +119,19 @@ use crate::error::MapResult;
/// Database methods
impl User {
pub fn to_json(&self, conn: &DbConn) -> Value {
- use super::{TwoFactor, UserOrganization};
-
let orgs = UserOrganization::find_by_user(&self.uuid, conn);
let orgs_json: Vec<Value> = orgs.iter().map(|c| c.to_json(&conn)).collect();
let twofactor_enabled = !TwoFactor::find_by_user(&self.uuid, conn).is_empty();
+ // TODO: Might want to save the status field in the DB
+ let status = if self.password_hash.is_empty() {
+ UserStatus::Invited
+ } else {
+ UserStatus::Enabled
+ };
+
json!({
- "_Enabled": !self.password_hash.is_empty(),
+ "_Status": status as i32,
"Id": self.uuid,
"Name": self.name,
"Email": self.email,
@@ -178,6 +189,20 @@ impl User {
}
}
+ pub fn update_all_revisions(conn: &DbConn) -> EmptyResult {
+ let updated_at = Utc::now().naive_utc();
+
+ crate::util::retry(
+ || {
+ diesel::update(users::table)
+ .set(users::updated_at.eq(updated_at))
+ .execute(&**conn)
+ },
+ 10,
+ )
+ .map_res("Error updating revision date for all users")
+ }
+
pub fn update_revision(&mut self, conn: &DbConn) -> EmptyResult {
self.updated_at = Utc::now().naive_utc();