1
0
mirror of https://gitlab.com/comunic/comunicapiv3 synced 2025-09-19 03:18:46 +00:00

Can register a new key

This commit is contained in:
2021-05-14 10:58:11 +02:00
parent 70860ab184
commit 3838cf3e03
9 changed files with 67 additions and 6 deletions

View File

@@ -0,0 +1,21 @@
//! # Admin account key helper
//!
//! @author Pierre Hubert
use webauthn_rs::proto::Credential;
use crate::constants::database_tables_names::ADMIN_KEYS_TABLE;
use crate::data::admin::AdminID;
use crate::data::error::Res;
use crate::helpers::database;
use crate::utils::date_utils::time;
/// Save a new key in the database
pub fn add_key(id: AdminID, name: &str, key: Credential) -> Res {
database::InsertQuery::new(ADMIN_KEYS_TABLE)
.add_admin_id("admin_id", id)
.add_str("name", name)
.add_u64("time_add", time())
.add_str("security_key", &serde_json::to_string(&key)?)
.insert_drop_result()
}

View File

@@ -31,4 +31,12 @@ pub fn set(admin: AdminID, key: RegistrationState) -> Res {
cache?.insert(admin, key);
Ok(())
}
pub fn get(admin: AdminID) -> Res<Option<RegistrationState>> {
let cache = unsafe {
CACHE.as_ref().unwrap().lock()
};
Ok(cache?.remove(&admin))
}

View File

@@ -692,6 +692,11 @@ impl InsertQuery {
self
}
pub fn add_admin_id(mut self, key: &str, value: AdminID) -> InsertQuery {
self.values.insert(key.to_string(), Value::from(value.id()));
self
}
pub fn add_group_id(mut self, key: &str, value: &GroupID) -> InsertQuery {
self.values.insert(key.to_string(), Value::from(value.id()));
self

View File

@@ -23,5 +23,6 @@ pub mod independent_push_notifications_service_helper;
pub mod firebase_notifications_helper;
pub mod forez_presence_helper;
pub mod admin_account_helper;
pub mod admin_account_key_helper;
pub mod admin_access_token_helper;
pub mod admin_key_registration_challenges_helper;