mirror of
https://gitlab.com/comunic/comunicapiv3
synced 2025-06-21 00:45:18 +00:00
Return keys listing in auth options
This commit is contained in:
@ -5,7 +5,7 @@
|
||||
use webauthn_rs::proto::Credential;
|
||||
|
||||
use crate::constants::database_tables_names::ADMIN_KEYS_TABLE;
|
||||
use crate::data::admin::AdminID;
|
||||
use crate::data::admin::{AdminID, AdminKey};
|
||||
use crate::data::error::Res;
|
||||
use crate::helpers::database;
|
||||
use crate::utils::date_utils::time;
|
||||
@ -16,6 +16,23 @@ pub fn add_key(id: AdminID, name: &str, key: Credential) -> Res {
|
||||
.add_admin_id("admin_id", id)
|
||||
.add_str("name", name)
|
||||
.add_u64("time_add", time())
|
||||
.add_str("security_key", &serde_json::to_string(&key)?)
|
||||
.add_str("credential", &serde_json::to_string(&key)?)
|
||||
.insert_drop_result()
|
||||
}
|
||||
|
||||
/// Get the list of keys of a given admin
|
||||
pub fn get_admin_keys(id: AdminID) -> Res<Vec<AdminKey>> {
|
||||
database::QueryInfo::new(ADMIN_KEYS_TABLE)
|
||||
.cond_admin_id("admin_id", id)
|
||||
.exec(db_to_admin_key)
|
||||
}
|
||||
|
||||
/// Turn database entry into an AdminKey structure
|
||||
fn db_to_admin_key(row: &database::RowResult) -> Res<AdminKey> {
|
||||
Ok(AdminKey {
|
||||
id: row.get_u64("id")?,
|
||||
admin_id: row.get_admin_id("admin_id")?,
|
||||
name: row.get_str("name")?,
|
||||
key: serde_json::from_str(&row.get_str("credential")?)?,
|
||||
})
|
||||
}
|
Reference in New Issue
Block a user