diff --git a/Cargo.lock b/Cargo.lock index adcffea..d08a044 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -612,6 +612,40 @@ dependencies = [ "cfg-if 1.0.0", ] +[[package]] +name = "env_logger" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85cdab6a89accf66733ad5a1693a4dcced6aeff64602b634530dd73c1f3ee9f0" +dependencies = [ + "humantime", + "is-terminal", + "log", + "regex", + "termcolor", +] + +[[package]] +name = "errno" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f639046355ee4f37944e44f60642c6f3a7efa3cf6b78c78a0d989a8ce6c396a1" +dependencies = [ + "errno-dragonfly", + "libc", + "winapi 0.3.9", +] + +[[package]] +name = "errno-dragonfly" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa68f1b12764fab894d2755d2518754e71b4fd80ecfb822714a1206c2aab39bf" +dependencies = [ + "cc", + "libc", +] + [[package]] name = "event-listener" version = "2.5.3" @@ -958,6 +992,12 @@ dependencies = [ "libc", ] +[[package]] +name = "hermit-abi" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fed44880c466736ef9a5c5b5facefb5ed0785676d0c02d612db14e54f0d84286" + [[package]] name = "hex" version = "0.4.3" @@ -1022,6 +1062,12 @@ version = "1.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "02296996cb8796d7c6e3bc2d9211b7802812d36999a51bb754123ead7d37d026" +[[package]] +name = "humantime" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" + [[package]] name = "hyper" version = "0.14.24" @@ -1152,6 +1198,16 @@ dependencies = [ "cfg-if 1.0.0", ] +[[package]] +name = "io-lifetimes" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1abeb7a0dd0f8181267ff8adc397075586500b81b28a73e8a0208b00fc170fb3" +dependencies = [ + "libc", + "windows-sys 0.45.0", +] + [[package]] name = "iovec" version = "0.1.4" @@ -1161,6 +1217,18 @@ dependencies = [ "libc", ] +[[package]] +name = "is-terminal" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "21b6b32576413a8e69b90e952e4a026476040d81017b80445deda5f2d3921857" +dependencies = [ + "hermit-abi 0.3.1", + "io-lifetimes", + "rustix", + "windows-sys 0.45.0", +] + [[package]] name = "itertools" version = "0.10.5" @@ -1242,6 +1310,12 @@ dependencies = [ "cc", ] +[[package]] +name = "linux-raw-sys" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f051f77a7c8e6957c0696eac88f26b0117e54f52d3fc682ab19397a8812846a4" + [[package]] name = "lock_api" version = "0.4.9" @@ -2080,7 +2154,9 @@ name = "rot" version = "0.1.0" dependencies = [ "chrono", + "env_logger", "hex", + "log", "rocket", "rocket_dyn_templates", "sea-orm", @@ -2107,6 +2183,20 @@ dependencies = [ "serde_json", ] +[[package]] +name = "rustix" +version = "0.36.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fd5c6ff11fecd55b40746d1995a02f2eb375bf8c00d192d521ee09f42bef37bc" +dependencies = [ + "bitflags", + "errno", + "io-lifetimes", + "libc", + "linux-raw-sys", + "windows-sys 0.45.0", +] + [[package]] name = "rustls" version = "0.20.8" diff --git a/Cargo.toml b/Cargo.toml index 1207e8c..29ec8bf 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,3 +14,5 @@ rocket_dyn_templates = { version = "0.1.0-rc.2", features= ["tera"] } chrono = { version = "0.4", features = ["serde"]} sha3 = "0.10" hex = "0.4" +log = "0.4" +env_logger = "0.10" diff --git a/src/main.rs b/src/main.rs index 801d8ae..ad24233 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,5 +6,6 @@ mod rest; #[launch] async fn rocket() -> _ { + env_logger::init(); rest::start().await } diff --git a/src/models/user.rs b/src/models/user.rs index dc763cb..8df4939 100644 --- a/src/models/user.rs +++ b/src/models/user.rs @@ -37,6 +37,7 @@ impl Model { name: Set(name.clone().into()), ..Default::default() }; + log::info!("User {:?} created", user); user.insert(db).await.unwrap() } } diff --git a/src/rest/mod.rs b/src/rest/mod.rs index 770a77c..147052f 100644 --- a/src/rest/mod.rs +++ b/src/rest/mod.rs @@ -103,17 +103,24 @@ async fn savename( let entered_pw = hasher.finalize(); if hex::encode(entered_pw) == pw { + log::info!("{} hat sich erfolgreich eingeloggt (mit PW)", name.name); cookies.add_private(Cookie::new("name", name.name.clone())); return Flash::success(Redirect::to("/"), "Erfolgreich eingeloggt"); } else { + log::warn!("Somebody tried to login as {} with a WRONG pw", name.name); return Flash::error(Redirect::to("/name"), "Falsches Passwort"); } } None => { + log::warn!( + "Somebody tried to login as {}, w/o specifying a pw", + name.name + ); return Flash::error(Redirect::to("/name"), "Benutzer besitzt hat Passwort, du hast jedoch keines eingegeben. Bitte nochmal probieren"); } }, None => { + log::info!("{} hat sich erfolgreich eingeloggt (ohne PW)", name.name); cookies.add_private(Cookie::new("name", name.name.clone())); return Flash::success(Redirect::to("/"), "Name erfolgreich ausgewählt"); } diff --git a/src/rest/restday.rs b/src/rest/restday.rs index 130fe47..3cc52d1 100644 --- a/src/rest/restday.rs +++ b/src/rest/restday.rs @@ -28,10 +28,12 @@ async fn create(db: &State, day: Form) -> Redirect .await .unwrap(); match day { - Some(_) => { + Some(day) => { + log::info!("{:?} got updated to {:?}", day, new_day); new_day.update(db.inner()).await.unwrap(); //TODO: fixme } None => { + log::info!("{:?} got inserted", new_day); new_day.insert(db.inner()).await.unwrap(); //TODO: fixme } } diff --git a/src/rest/restreg.rs b/src/rest/restreg.rs index b8ed1c8..d186026 100644 --- a/src/rest/restreg.rs +++ b/src/rest/restreg.rs @@ -29,6 +29,7 @@ async fn register( .expect("There's no trip on this date (yet)"); if !(day.open_registration || user.is_cox) { + log::error!("{} tried to register, even though the user it should not be possible to do so via UI -> manually crafted request?", user.name); return Redirect::to("/"); } @@ -41,6 +42,7 @@ async fn register( ..Default::default() }; + log::info!("{} registered for {:?}", user.name, trip); trip.insert(db.inner()).await.unwrap(); Redirect::to("/") @@ -65,6 +67,7 @@ async fn delete( .expect("There's no trip on this date (yet)"); if delete.user != user.id { + log::error!("{} tried to delete a registration from user_id {} on day {:?} (probably hand-crafted request)", user.name, delete.user, delete.day); return Flash::error( Redirect::to("/"), "Du kannst nur deine eigenen Anmeldungen löschen!", @@ -76,8 +79,12 @@ async fn delete( .await .unwrap(); match trip { - None => return Flash::error(Redirect::to("/"), "Du bist gar nicht angemeldet!"), + None => { + log::error!("Tried to register w/o being authenticated (prob. hand crafted request (user.name = {})", user.name); + return Flash::error(Redirect::to("/"), "Du bist gar nicht angemeldet!"); + } Some(trip) => { + log::info!("User {} deleted the registration for {:?}", user.name, trip); trip::Entity::delete(trip::ActiveModel { day: Set(trip.day), user_id: Set(trip.user_id),