add logging

This commit is contained in:
philipp 2023-03-04 11:20:12 +01:00
parent 2cc9b12674
commit 23f3c142c1
7 changed files with 112 additions and 2 deletions

90
Cargo.lock generated
View File

@ -612,6 +612,40 @@ dependencies = [
"cfg-if 1.0.0", "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]] [[package]]
name = "event-listener" name = "event-listener"
version = "2.5.3" version = "2.5.3"
@ -958,6 +992,12 @@ dependencies = [
"libc", "libc",
] ]
[[package]]
name = "hermit-abi"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fed44880c466736ef9a5c5b5facefb5ed0785676d0c02d612db14e54f0d84286"
[[package]] [[package]]
name = "hex" name = "hex"
version = "0.4.3" version = "0.4.3"
@ -1022,6 +1062,12 @@ version = "1.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "02296996cb8796d7c6e3bc2d9211b7802812d36999a51bb754123ead7d37d026" checksum = "02296996cb8796d7c6e3bc2d9211b7802812d36999a51bb754123ead7d37d026"
[[package]]
name = "humantime"
version = "2.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4"
[[package]] [[package]]
name = "hyper" name = "hyper"
version = "0.14.24" version = "0.14.24"
@ -1152,6 +1198,16 @@ dependencies = [
"cfg-if 1.0.0", "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]] [[package]]
name = "iovec" name = "iovec"
version = "0.1.4" version = "0.1.4"
@ -1161,6 +1217,18 @@ dependencies = [
"libc", "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]] [[package]]
name = "itertools" name = "itertools"
version = "0.10.5" version = "0.10.5"
@ -1242,6 +1310,12 @@ dependencies = [
"cc", "cc",
] ]
[[package]]
name = "linux-raw-sys"
version = "0.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f051f77a7c8e6957c0696eac88f26b0117e54f52d3fc682ab19397a8812846a4"
[[package]] [[package]]
name = "lock_api" name = "lock_api"
version = "0.4.9" version = "0.4.9"
@ -2080,7 +2154,9 @@ name = "rot"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"chrono", "chrono",
"env_logger",
"hex", "hex",
"log",
"rocket", "rocket",
"rocket_dyn_templates", "rocket_dyn_templates",
"sea-orm", "sea-orm",
@ -2107,6 +2183,20 @@ dependencies = [
"serde_json", "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]] [[package]]
name = "rustls" name = "rustls"
version = "0.20.8" version = "0.20.8"

View File

@ -14,3 +14,5 @@ rocket_dyn_templates = { version = "0.1.0-rc.2", features= ["tera"] }
chrono = { version = "0.4", features = ["serde"]} chrono = { version = "0.4", features = ["serde"]}
sha3 = "0.10" sha3 = "0.10"
hex = "0.4" hex = "0.4"
log = "0.4"
env_logger = "0.10"

View File

@ -6,5 +6,6 @@ mod rest;
#[launch] #[launch]
async fn rocket() -> _ { async fn rocket() -> _ {
env_logger::init();
rest::start().await rest::start().await
} }

View File

@ -37,6 +37,7 @@ impl Model {
name: Set(name.clone().into()), name: Set(name.clone().into()),
..Default::default() ..Default::default()
}; };
log::info!("User {:?} created", user);
user.insert(db).await.unwrap() user.insert(db).await.unwrap()
} }
} }

View File

@ -103,17 +103,24 @@ async fn savename(
let entered_pw = hasher.finalize(); let entered_pw = hasher.finalize();
if hex::encode(entered_pw) == pw { 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())); cookies.add_private(Cookie::new("name", name.name.clone()));
return Flash::success(Redirect::to("/"), "Erfolgreich eingeloggt"); return Flash::success(Redirect::to("/"), "Erfolgreich eingeloggt");
} else { } else {
log::warn!("Somebody tried to login as {} with a WRONG pw", name.name);
return Flash::error(Redirect::to("/name"), "Falsches Passwort"); return Flash::error(Redirect::to("/name"), "Falsches Passwort");
} }
} }
None => { 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"); return Flash::error(Redirect::to("/name"), "Benutzer besitzt hat Passwort, du hast jedoch keines eingegeben. Bitte nochmal probieren");
} }
}, },
None => { None => {
log::info!("{} hat sich erfolgreich eingeloggt (ohne PW)", name.name);
cookies.add_private(Cookie::new("name", name.name.clone())); cookies.add_private(Cookie::new("name", name.name.clone()));
return Flash::success(Redirect::to("/"), "Name erfolgreich ausgewählt"); return Flash::success(Redirect::to("/"), "Name erfolgreich ausgewählt");
} }

View File

@ -28,10 +28,12 @@ async fn create(db: &State<DatabaseConnection>, day: Form<DayForm>) -> Redirect
.await .await
.unwrap(); .unwrap();
match day { match day {
Some(_) => { Some(day) => {
log::info!("{:?} got updated to {:?}", day, new_day);
new_day.update(db.inner()).await.unwrap(); //TODO: fixme new_day.update(db.inner()).await.unwrap(); //TODO: fixme
} }
None => { None => {
log::info!("{:?} got inserted", new_day);
new_day.insert(db.inner()).await.unwrap(); //TODO: fixme new_day.insert(db.inner()).await.unwrap(); //TODO: fixme
} }
} }

View File

@ -29,6 +29,7 @@ async fn register(
.expect("There's no trip on this date (yet)"); .expect("There's no trip on this date (yet)");
if !(day.open_registration || user.is_cox) { 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("/"); return Redirect::to("/");
} }
@ -41,6 +42,7 @@ async fn register(
..Default::default() ..Default::default()
}; };
log::info!("{} registered for {:?}", user.name, trip);
trip.insert(db.inner()).await.unwrap(); trip.insert(db.inner()).await.unwrap();
Redirect::to("/") Redirect::to("/")
@ -65,6 +67,7 @@ async fn delete(
.expect("There's no trip on this date (yet)"); .expect("There's no trip on this date (yet)");
if delete.user != user.id { 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( return Flash::error(
Redirect::to("/"), Redirect::to("/"),
"Du kannst nur deine eigenen Anmeldungen löschen!", "Du kannst nur deine eigenen Anmeldungen löschen!",
@ -76,8 +79,12 @@ async fn delete(
.await .await
.unwrap(); .unwrap();
match trip { 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) => { Some(trip) => {
log::info!("User {} deleted the registration for {:?}", user.name, trip);
trip::Entity::delete(trip::ActiveModel { trip::Entity::delete(trip::ActiveModel {
day: Set(trip.day), day: Set(trip.day),
user_id: Set(trip.user_id), user_id: Set(trip.user_id),