1
0
mirror of https://gitlab.com/comunic/comunicapiv3 synced 2025-03-13 01:12:37 +00:00
comunicapiv3/src/api_data/admin/admin_auth_options.rs

37 lines
757 B
Rust
Raw Normal View History

2021-05-09 16:29:59 +02:00
//! # Admin auth options API structure
//!
//! @author Pierre Hubert
use serde::Serialize;
2021-05-14 11:12:41 +02:00
use crate::data::admin::{Admin, AdminKey};
#[derive(Serialize)]
struct AuthKey {
name: String,
id: u64,
2021-07-11 17:54:15 +02:00
password: bool,
2021-05-14 11:12:41 +02:00
}
2021-05-09 16:29:59 +02:00
#[derive(Serialize)]
pub struct AdminAuthOptions {
2021-05-11 17:45:26 +02:00
reset_token: bool,
2021-05-14 11:12:41 +02:00
keys: Vec<AuthKey>,
2021-05-09 16:29:59 +02:00
}
impl AdminAuthOptions {
2022-08-24 20:08:29 +02:00
pub fn new(admin: &Admin, keys: &[AdminKey]) -> Self {
2021-05-09 16:29:59 +02:00
Self {
2021-05-14 11:12:41 +02:00
reset_token: admin.reset_token.is_some(),
2023-05-31 19:10:05 +02:00
keys: keys
.iter()
.map(|k| AuthKey {
id: k.id,
name: k.name.to_string(),
password: k.password.is_some(),
})
.collect(),
2021-05-09 16:29:59 +02:00
}
}
2023-05-31 19:10:05 +02:00
}