0
0
Fork 0
mirror of https://git.verdigado.com/NB-Public/simple-wkd.git synced 2024-10-30 09:05:52 +01:00
simple-wkd/src/confirmation.rs

32 lines
1 KiB
Rust
Raw Normal View History

2023-04-13 18:56:32 +02:00
use crate::management::{delete_key, Action, Pending};
use crate::utils::{get_email_from_cert, parse_pem};
use crate::PENDING;
use crate::{pending_path, PATH, VARIANT};
use std::fs;
use std::path::Path;
pub fn confirm_action(token: &str) {
let pending_path = pending_path!().join(token);
let key: Pending = serde_json::from_str(&fs::read_to_string(&pending_path).unwrap()).unwrap();
match key.action() {
Action::Add => {
let cert = parse_pem(key.data());
let domain = get_email_from_cert(&cert)
.split('@')
.last()
.unwrap()
.to_owned();
sequoia_net::wkd::insert(PATH, domain, VARIANT, &cert).unwrap();
}
Action::Delete => delete_key(key.data()),
}
fs::remove_file(&pending_path).unwrap();
}
pub fn send_confirmation_email(email: &str, action: Action, token: &str) {
println!("Email sent to {}", email);
println!("Action: {:?}", action);
println!("Token: {}", token);
}