0
0
Fork 0
mirror of https://git.verdigado.com/NB-Public/simple-wkd.git synced 2024-10-30 01:25:53 +01:00

Improve logging

This commit is contained in:
Delta1925 2023-04-18 23:53:15 +02:00
parent 7cef05a7f9
commit 7434766800
No known key found for this signature in database
GPG key ID: 1C21ACE44193CB25
2 changed files with 6 additions and 3 deletions

View file

@ -10,7 +10,7 @@ use crate::errors::SpecialErrors;
use crate::management::{clean_stale, store_pending_addition, store_pending_deletion, Action}; use crate::management::{clean_stale, store_pending_addition, store_pending_deletion, Action};
use crate::settings::{ROOT_FOLDER, SETTINGS}; use crate::settings::{ROOT_FOLDER, SETTINGS};
use crate::utils::{ use crate::utils::{
gen_random_token, get_email_from_cert, is_email_allowed, parse_pem, read_file, return_outcome, gen_random_token, get_email_from_cert, is_email_allowed, parse_pem, read_file, return_outcome, key_exists,
}; };
use actix_files::Files; use actix_files::Files;
@ -102,6 +102,7 @@ async fn index(req: HttpRequest) -> Result<HttpResponse, CompatErr> {
async fn submit(pem: web::Form<Key>) -> Result<HttpResponse, CompatErr> { async fn submit(pem: web::Form<Key>) -> Result<HttpResponse, CompatErr> {
let cert = parse_pem(&pem.key)?; let cert = parse_pem(&pem.key)?;
let email = get_email_from_cert(&cert)?; let email = get_email_from_cert(&cert)?;
debug!("Handling user {} request to add a key...", email);
is_email_allowed(&email)?; is_email_allowed(&email)?;
let token = gen_random_token(); let token = gen_random_token();
store_pending_addition(pem.key.clone(), &email, &token)?; store_pending_addition(pem.key.clone(), &email, &token)?;
@ -113,6 +114,7 @@ async fn submit(pem: web::Form<Key>) -> Result<HttpResponse, CompatErr> {
#[get("/api/confirm")] #[get("/api/confirm")]
async fn confirm(token: web::Query<Token>) -> Result<HttpResponse, CompatErr> { async fn confirm(token: web::Query<Token>) -> Result<HttpResponse, CompatErr> {
debug!("Handling token {}...", token.token);
let (action, email) = confirm_action(&token.token)?; let (action, email) = confirm_action(&token.token)?;
info!("User {} confirmed to {} his key successfully!", email, action.to_string().to_lowercase()); info!("User {} confirmed to {} his key successfully!", email, action.to_string().to_lowercase());
match action { match action {
@ -123,6 +125,8 @@ async fn confirm(token: web::Query<Token>) -> Result<HttpResponse, CompatErr> {
#[get("/api/delete")] #[get("/api/delete")]
async fn delete(email: web::Query<Email>) -> Result<HttpResponse, CompatErr> { async fn delete(email: web::Query<Email>) -> Result<HttpResponse, CompatErr> {
debug!("Handling user {} request to add a key...", email.email);
key_exists(&email.email)?;
let token = gen_random_token(); let token = gen_random_token();
store_pending_deletion(email.email.clone(), &token)?; store_pending_deletion(email.email.clone(), &token)?;
debug!("Sending email to {} to add a key... (Request token: {})", email.email, token); debug!("Sending email to {} to add a key... (Request token: {})", email.email, token);

View file

@ -1,6 +1,6 @@
use crate::log_err; use crate::log_err;
use crate::settings::{ERROR_TEXT, ROOT_FOLDER}; use crate::settings::{ERROR_TEXT, ROOT_FOLDER};
use crate::utils::{get_user_file_path, key_exists, pending_path, read_file}; use crate::utils::{get_user_file_path, pending_path, read_file};
use anyhow::Result; use anyhow::Result;
use chrono::Utc; use chrono::Utc;
@ -67,7 +67,6 @@ pub fn store_pending_addition(pem: String, _email: &str, token: &str) -> Result<
} }
pub fn store_pending_deletion(email: String, token: &str) -> Result<()> { pub fn store_pending_deletion(email: String, token: &str) -> Result<()> {
key_exists(&email)?;
let pending = Pending::build_delete(email); let pending = Pending::build_delete(email);
store_pending(&pending, token)?; store_pending(&pending, token)?;
Ok(()) Ok(())