From 38d8197a485d493e6fc6d35d5199ba02b27e98c0 Mon Sep 17 00:00:00 2001 From: philipp Date: Tue, 14 Mar 2023 17:05:20 +0100 Subject: [PATCH] don't allow registration for own events --- src/rest/restreg.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/rest/restreg.rs b/src/rest/restreg.rs index 9a77381..5f80ae2 100644 --- a/src/rest/restreg.rs +++ b/src/rest/restreg.rs @@ -38,6 +38,25 @@ async fn register( ); } + if let Some(cox_id) = register.cox_id { + let trip = trip::Entity::find_by_id(cox_id) + .one(db.inner()) + .await + .unwrap() + .unwrap(); + if trip.user_id == user.id { + log::warn!( + "{} tried to register for his own trip ({})", + user.name, + trip.id + ); + return Flash::error( + Redirect::to("/"), + "Du kannst an deinen eigenen Ausfahrten nicht teilnehmen...", + ); + } + } + let user = user::Model::find_or_create_user(®ister.name, db.inner()).await; let day = format!("{}", day.day.format("%Y-%m-%d"));