Browse Source
Implement better user status API, in the future we'll probably want a way to disable users.
We should migrate from the empty password hash to a separate column then.
pull/460/head
Daniel García
6 years ago
No known key found for this signature in database
GPG Key ID: FC8A7D14C3CD543A
2 changed files with
17 additions and
4 deletions
-
src/db/models/user.rs
-
src/static/templates/admin/page.hbs
|
@ -37,6 +37,12 @@ pub struct User { |
|
|
pub client_kdf_iter: i32, |
|
|
pub client_kdf_iter: i32, |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
enum UserStatus { |
|
|
|
|
|
Enabled = 0, |
|
|
|
|
|
Invited = 1, |
|
|
|
|
|
_Disabled = 2, |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
/// Local methods
|
|
|
/// Local methods
|
|
|
impl User { |
|
|
impl User { |
|
|
pub const CLIENT_KDF_TYPE_DEFAULT: i32 = 0; // PBKDF2: 0
|
|
|
pub const CLIENT_KDF_TYPE_DEFAULT: i32 = 0; // PBKDF2: 0
|
|
@ -119,8 +125,15 @@ impl User { |
|
|
let orgs_json: Vec<Value> = orgs.iter().map(|c| c.to_json(&conn)).collect(); |
|
|
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(); |
|
|
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!({ |
|
|
json!({ |
|
|
"_Enabled": !self.password_hash.is_empty(), |
|
|
"_Status": status as i32, |
|
|
"Id": self.uuid, |
|
|
"Id": self.uuid, |
|
|
"Name": self.name, |
|
|
"Name": self.name, |
|
|
"Email": self.email, |
|
|
"Email": self.email, |
|
|
|
@ -13,9 +13,9 @@ |
|
|
{{#if TwoFactorEnabled}} |
|
|
{{#if TwoFactorEnabled}} |
|
|
<span class="badge badge-success ml-2">2FA</span> |
|
|
<span class="badge badge-success ml-2">2FA</span> |
|
|
{{/if}} |
|
|
{{/if}} |
|
|
{{#unless _Enabled}} |
|
|
{{#case _Status 1}} |
|
|
<span class="badge badge-warning ml-2">Disabled</span> |
|
|
<span class="badge badge-warning ml-2">Invited</span> |
|
|
{{/unless}} |
|
|
{{/case}} |
|
|
<span class="d-block">{{Email}}</span> |
|
|
<span class="d-block">{{Email}}</span> |
|
|
</div> |
|
|
</div> |
|
|
<div class="col"> |
|
|
<div class="col"> |
|
|