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:
21
src/helpers/admin_account_key_helper.rs
Normal file
21
src/helpers/admin_account_key_helper.rs
Normal 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()
|
||||
}
|
@@ -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))
|
||||
}
|
@@ -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
|
||||
|
@@ -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;
|
Reference in New Issue
Block a user