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-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 {
|
2021-05-14 11:12:41 +02:00
|
|
|
pub fn new(admin: &Admin, keys: &Vec<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(),
|
|
|
|
keys: keys.iter().map(|k| AuthKey { id: k.id, name: k.name.to_string() }).collect(),
|
2021-05-09 16:29:59 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|