proper error message if already registered
This commit is contained in:
parent
ff78b64dfd
commit
6ea1585d7c
@ -21,7 +21,7 @@ async fn register(
|
|||||||
db: &State<DatabaseConnection>,
|
db: &State<DatabaseConnection>,
|
||||||
register: Form<RegisterForm>,
|
register: Form<RegisterForm>,
|
||||||
user: user::Model,
|
user: user::Model,
|
||||||
) -> Redirect {
|
) -> Flash<Redirect> {
|
||||||
let day = day::Entity::find_by_id(*register.day)
|
let day = day::Entity::find_by_id(*register.day)
|
||||||
.one(db.inner())
|
.one(db.inner())
|
||||||
.await
|
.await
|
||||||
@ -30,22 +30,35 @@ async fn register(
|
|||||||
|
|
||||||
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);
|
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 Flash::error(
|
||||||
|
Redirect::to("/"),
|
||||||
|
"Don't (try to ;)) abuse this system! Incident has been reported...",
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
let user = user::Model::find_or_create_user(®ister.name, db.inner()).await;
|
let user = user::Model::find_or_create_user(®ister.name, db.inner()).await;
|
||||||
|
|
||||||
let day = format!("{}", day.day.format("%Y-%m-%d"));
|
let day = format!("{}", day.day.format("%Y-%m-%d"));
|
||||||
let trip = trip::ActiveModel {
|
let trip = trip::ActiveModel {
|
||||||
day: Set(day),
|
day: Set(day.clone()),
|
||||||
user_id: Set(user.id),
|
user_id: Set(user.id),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
|
|
||||||
log::info!("{} registered for {:?}", user.name, trip);
|
match trip.insert(db.inner()).await {
|
||||||
trip.insert(db.inner()).await.unwrap();
|
Ok(_) => {
|
||||||
|
log::info!("{} registered for {:?}", user.name, day);
|
||||||
Redirect::to("/")
|
Flash::success(Redirect::to("/"), "Erfolgreich angemeldet!")
|
||||||
|
}
|
||||||
|
Err(_) => {
|
||||||
|
log::warn!(
|
||||||
|
"{} tried to register for {:?}, but is already registered",
|
||||||
|
user.name,
|
||||||
|
day
|
||||||
|
);
|
||||||
|
Flash::error(Redirect::to("/"), "Du bist bereits angemeldet")
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(FromForm)]
|
#[derive(FromForm)]
|
||||||
|
Loading…
Reference in New Issue
Block a user