mirror of
https://git.verdigado.com/NB-Public/simple-wkd.git
synced 2024-12-06 14:52:41 +01:00
Initial commit
This commit is contained in:
commit
9c9f4793be
7 changed files with 2935 additions and 0 deletions
31
src/confirmation.rs
Normal file
31
src/confirmation.rs
Normal file
|
@ -0,0 +1,31 @@
|
|||
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);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue