Improved logging, UI tweaks.

main
Josef Rokos 1 year ago
parent 2119c2e56b
commit 676951e809

2
Cargo.lock generated

@ -2963,7 +2963,7 @@ dependencies = [
[[package]] [[package]]
name = "rezervator" name = "rezervator"
version = "0.1.0" version = "1.0.0"
dependencies = [ dependencies = [
"actix-files", "actix-files",
"actix-multipart", "actix-multipart",

@ -1,6 +1,6 @@
[package] [package]
name = "rezervator" name = "rezervator"
version = "0.1.0" version = "1.0.0"
edition = "2021" edition = "2021"
[lib] [lib]
@ -88,7 +88,7 @@ browserquery = "defaults"
# Set by cargo-leptos watch when building with that tool. Controls whether autoreload JS will be included in the head # Set by cargo-leptos watch when building with that tool. Controls whether autoreload JS will be included in the head
watch = false watch = false
# The environment Leptos will run in, usually either "DEV" or "PROD" # The environment Leptos will run in, usually either "DEV" or "PROD"
env = "DEV" env = "PROD"
# The features to use when compiling the bin target # The features to use when compiling the bin target
# #
# Optional. Can be over-ridden with the command line parameter --bin-features # Optional. Can be over-ridden with the command line parameter --bin-features

@ -7,8 +7,12 @@ div.header_banner {
color: white; color: white;
} }
div.header_banner_text {
padding: 10px;
}
h1.header_banner { h1.header_banner {
font-size: xxx-large; font-size: x-large;
color: white; color: white;
text-shadow: -3px -3px 0 #000, 3px -3px 0 #000, -3px 3px 0 #000, 3px 3px 0 #000; text-shadow: -3px -3px 0 #000, 3px -3px 0 #000, -3px 3px 0 #000, 3px 3px 0 #000;
} }
@ -17,4 +21,8 @@ h1.header_banner {
div.header_banner { div.header_banner {
height: 200px; height: 200px;
} }
h1.header_banner {
font-size: xxx-large;
}
} }

@ -23,3 +23,6 @@ path = "Maildir"
#password = "password" #password = "password"
#tls = true #tls = true
#accept_all_certs = true #accept_all_certs = true
[logging]
severity = "debug"

@ -14,6 +14,7 @@ cfg_if! { if #[cfg(feature = "ssr")] {
use std::str::FromStr; use std::str::FromStr;
use std::collections::HashMap; use std::collections::HashMap;
use log::warn; use log::warn;
use log::info;
use crate::backend::data::{ReservationSum, ReservationState, ResWithProperty, Customer, Message, MessageType, ChartData, ResAllView}; use crate::backend::data::{ReservationSum, ReservationState, ResWithProperty, Customer, Message, MessageType, ChartData, ResAllView};
use crate::backend::get_pool; use crate::backend::get_pool;
use crate::backend::get_mailing; use crate::backend::get_mailing;
@ -239,6 +240,8 @@ pub async fn get_public_form_data(day: NaiveDate) -> Result<ApiResponse<Vec<Publ
let props = get_props(Some("active = true".to_string())).await?; let props = get_props(Some("active = true".to_string())).await?;
let reservations = reservations_for_day(&day).await?; let reservations = reservations_for_day(&day).await?;
info!("Loading public form data");
Ok(ApiResponse::Data(props.into_iter().map(|p| PublicFormData { Ok(ApiResponse::Data(props.into_iter().map(|p| PublicFormData {
property: p, property: p,
hours: hours.clone(), hours: hours.clone(),
@ -344,6 +347,8 @@ pub async fn create_reservation(reservation: CrReservation, pow: String) -> Resu
warn!("Notification not send: {}", e); warn!("Notification not send: {}", e);
} }
info!("Reservation created");
Ok(ApiResponse::Data(reservation.date())) Ok(ApiResponse::Data(reservation.date()))
} }

@ -134,6 +134,8 @@ pub async fn logout() -> Result<(), ServerFnError> {
let session = extract::<Session>().await?; let session = extract::<Session>().await?;
session.clear(); session.clear();
info!("User logged out");
redirect("/login"); redirect("/login");
Ok(()) Ok(())
} }
@ -150,6 +152,7 @@ pub async fn admin_check() -> Result<bool, ServerFnError> {
#[server] #[server]
pub async fn get_user() -> Result<Option<User>, ServerFnError> { pub async fn get_user() -> Result<Option<User>, ServerFnError> {
info!("Get user");
Ok(logged_in_user().await) Ok(logged_in_user().await)
} }
@ -231,6 +234,8 @@ pub async fn change_pwd(new_pw: PwdChange) -> Result<ApiResponse<()>, ServerFnEr
.execute(&pool) .execute(&pool)
.await?; .await?;
info!("Password changed for user: {}", new_pw.login());
Ok(ApiResponse::Data(())) Ok(ApiResponse::Data(()))
} }

@ -107,6 +107,18 @@ impl Mailing {
} }
} }
#[cfg(feature = "ssr")]
#[derive(Deserialize)]
pub struct Logging {
severity: String
}
#[cfg(feature = "ssr")]
impl Logging {
pub fn severity(&self) -> &str {
&self.severity
}
}
#[cfg(feature = "ssr")] #[cfg(feature = "ssr")]
#[derive(Deserialize)] #[derive(Deserialize)]
@ -114,7 +126,8 @@ pub struct Configuration {
session: Session, session: Session,
network: Network, network: Network,
database: Database, database: Database,
mailing: Mailing mailing: Mailing,
logging: Logging
} }
#[cfg(feature = "ssr")] #[cfg(feature = "ssr")]
@ -131,6 +144,9 @@ impl Configuration {
pub fn mailing(&self) -> &Mailing { pub fn mailing(&self) -> &Mailing {
&self.mailing &self.mailing
} }
pub fn logging(&self) -> &Logging {
&self.logging
}
} }
#[cfg(feature = "ssr")] #[cfg(feature = "ssr")]

@ -2,6 +2,7 @@ use std::error::Error;
use std::fmt::{Debug, Display, Formatter}; use std::fmt::{Debug, Display, Formatter};
use chrono::ParseError; use chrono::ParseError;
use leptos::ServerFnError; use leptos::ServerFnError;
use log::error;
#[derive(Clone, Debug, Eq, PartialEq, Ord, PartialOrd)] #[derive(Clone, Debug, Eq, PartialEq, Ord, PartialOrd)]
pub enum AppError { pub enum AppError {
@ -28,6 +29,10 @@ impl AppError {
} }
} }
fn log_error(error: &dyn ToString) {
error!("Application error: {}", error.to_string());
}
impl Display for AppError { impl Display for AppError {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.as_string()) write!(f, "{}", self.as_string())
@ -38,6 +43,7 @@ impl Error for AppError {}
impl From<ServerFnError> for AppError { impl From<ServerFnError> for AppError {
fn from(value: ServerFnError) -> Self { fn from(value: ServerFnError) -> Self {
log_error(&value);
AppError::ServerError(value.to_string()) AppError::ServerError(value.to_string())
} }
} }
@ -45,12 +51,14 @@ impl From<ServerFnError> for AppError {
#[cfg(feature = "ssr")] #[cfg(feature = "ssr")]
impl From<sqlx::Error> for AppError { impl From<sqlx::Error> for AppError {
fn from(value: sqlx::Error) -> Self { fn from(value: sqlx::Error) -> Self {
log_error(&value);
AppError::FatalError(value.to_string()) AppError::FatalError(value.to_string())
} }
} }
impl From<ParseError> for AppError { impl From<ParseError> for AppError {
fn from(_value: ParseError) -> Self { fn from(value: ParseError) -> Self {
log_error(&value);
AppError::HourParseError AppError::HourParseError
} }
} }
@ -58,6 +66,7 @@ impl From<ParseError> for AppError {
#[cfg(feature = "ssr")] #[cfg(feature = "ssr")]
impl From<lettre::address::AddressError> for AppError { impl From<lettre::address::AddressError> for AppError {
fn from(value: lettre::address::AddressError) -> Self { fn from(value: lettre::address::AddressError) -> Self {
log_error(&value);
AppError::MailAddrParseErr(value.to_string()) AppError::MailAddrParseErr(value.to_string())
} }
} }
@ -65,6 +74,7 @@ impl From<lettre::address::AddressError> for AppError {
#[cfg(feature = "ssr")] #[cfg(feature = "ssr")]
impl From<lettre::error::Error> for AppError { impl From<lettre::error::Error> for AppError {
fn from(value: lettre::error::Error) -> Self { fn from(value: lettre::error::Error) -> Self {
log_error(&value);
AppError::MailSendError(value.to_string()) AppError::MailSendError(value.to_string())
} }
} }
@ -72,6 +82,7 @@ impl From<lettre::error::Error> for AppError {
#[cfg(feature = "ssr")] #[cfg(feature = "ssr")]
impl From<lettre::transport::smtp::Error> for AppError { impl From<lettre::transport::smtp::Error> for AppError {
fn from(value: lettre::transport::smtp::Error) -> Self { fn from(value: lettre::transport::smtp::Error) -> Self {
log_error(&value);
AppError::MailSendError(value.to_string()) AppError::MailSendError(value.to_string())
} }
} }
@ -79,6 +90,7 @@ impl From<lettre::transport::smtp::Error> for AppError {
#[cfg(feature = "ssr")] #[cfg(feature = "ssr")]
impl From<lettre::transport::file::Error> for AppError { impl From<lettre::transport::file::Error> for AppError {
fn from(value: lettre::transport::file::Error) -> Self { fn from(value: lettre::transport::file::Error) -> Self {
log_error(&value);
AppError::MailSendError(value.to_string()) AppError::MailSendError(value.to_string())
} }
} }
@ -86,6 +98,7 @@ impl From<lettre::transport::file::Error> for AppError {
#[cfg(feature = "ssr")] #[cfg(feature = "ssr")]
impl From<std::io::Error> for AppError { impl From<std::io::Error> for AppError {
fn from(value: std::io::Error) -> Self { fn from(value: std::io::Error) -> Self {
log_error(&value);
AppError::FileIOError(value.to_string()) AppError::FileIOError(value.to_string())
} }
} }

@ -142,7 +142,8 @@ lazy_static! {
("Update text", "Upravit text"), ("Update text", "Upravit text"),
("Update title", "Upravit titulek"), ("Update title", "Upravit titulek"),
("Are you sure you want to delete banner?", "Opravdu chcete smazat banner?"), ("Are you sure you want to delete banner?", "Opravdu chcete smazat banner?"),
("Delete banner", "Smazat banner") ("Delete banner", "Smazat banner"),
("Appearance", "Vzhled")
])), ])),
("sk", HashMap::from( [ ("sk", HashMap::from( [
("Dashboard", "Prehlad"), ("Dashboard", "Prehlad"),

@ -42,12 +42,12 @@ async fn main() -> std::io::Result<()> {
Pow::init_random().expect("Cannot init captcha"); Pow::init_random().expect("Cannot init captcha");
let cfg_path = matches.opt_str("c").unwrap_or("config.toml".to_string()); let cfg_path = matches.opt_str("c").unwrap_or("config.toml".to_string());
let srv_conf = load_config(&cfg_path);
env_logger::Builder::from_env(Env::default().default_filter_or("debug")).init(); env_logger::Builder::from_env(Env::default().default_filter_or(srv_conf.logging().severity())).init();
info!("Starting server"); info!("Starting server");
let conf = get_configuration(None).await.unwrap(); let conf = get_configuration(None).await.unwrap();
let srv_conf = load_config(&cfg_path);
// Generate the list of routes in your Leptos App // Generate the list of routes in your Leptos App
let routes = generate_route_list(|| view! { <App/> }); let routes = generate_route_list(|| view! { <App/> });
let key = Key::from(srv_conf.session().key()); let key = Key::from(srv_conf.session().key());

@ -104,8 +104,8 @@ pub fn appearance() -> impl IntoView {
{trl("Delete")} {trl("Delete")}
</button> </button>
<br/><br/> <br/><br/>
<div> <div inner_html={app.text.unwrap_or("<< TEXT >>".to_string())}>
{app.text.unwrap_or("<< TEXT >>".to_string())}
</div> </div>
<a class="dropdown-item" href="javascript:void(0);" on:click=move |_| text_edit.show()> <a class="dropdown-item" href="javascript:void(0);" on:click=move |_| text_edit.show()>
<i class="bx bx-edit-alt me-1"></i> {trl("Edit text")}</a> <i class="bx bx-edit-alt me-1"></i> {trl("Edit text")}</a>

@ -133,8 +133,8 @@ pub fn Public() -> impl IntoView {
</div> </div>
</Show> </Show>
<div> <div>
<div> <div class="header_banner_text" inner_html={app.text.unwrap_or("".to_string())}>
{app.text.unwrap_or("".to_string())}
</div> </div>
</div> </div>
</div> </div>

Loading…
Cancel
Save