Compare commits
1 Commits
main
...
465a42acac
| Author | SHA1 | Date | |
|---|---|---|---|
| 465a42acac |
104
src/tera/ergo.rs
104
src/tera/ergo.rs
@@ -1,6 +1,6 @@
|
|||||||
use std::env;
|
use std::env;
|
||||||
|
|
||||||
use chrono::{Datelike, Utc};
|
use chrono::Utc;
|
||||||
use rocket::{
|
use rocket::{
|
||||||
form::Form,
|
form::Form,
|
||||||
fs::TempFile,
|
fs::TempFile,
|
||||||
@@ -17,7 +17,6 @@ use sqlx::SqlitePool;
|
|||||||
use tera::Context;
|
use tera::Context;
|
||||||
|
|
||||||
use crate::model::{
|
use crate::model::{
|
||||||
activity::ActivityBuilder,
|
|
||||||
log::Log,
|
log::Log,
|
||||||
notification::Notification,
|
notification::Notification,
|
||||||
role::Role,
|
role::Role,
|
||||||
@@ -146,61 +145,47 @@ pub struct UserAdd {
|
|||||||
sex: String,
|
sex: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[post("/set-data", data = "<data>")]
|
//#[post("/set-data", data = "<data>")]
|
||||||
async fn new_user(db: &State<SqlitePool>, data: Form<UserAdd>, user: User) -> Flash<Redirect> {
|
//async fn new_user(db: &State<SqlitePool>, data: Form<UserAdd>, user: User) -> Flash<Redirect> {
|
||||||
if user.has_role(db, "ergo").await {
|
// if user.has_role(db, "ergo").await {
|
||||||
return Flash::error(Redirect::to("/ergo"), "Du hast deine Daten schon eingegeben. Wenn du sie updaten willst, melde dich bitte bei info@rudernlinz.at");
|
// return Flash::error(Redirect::to("/ergo"), "Du hast deine Daten schon eingegeben. Wenn du sie updaten willst, melde dich bitte bei it@rudernlinz.at");
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
// check data
|
// // check data
|
||||||
if data.birthyear < 1900 || data.birthyear > chrono::Utc::now().year() - 5 {
|
// if data.birthyear < 1900 || data.birthyear > chrono::Utc::now().year() - 5 {
|
||||||
return Flash::error(Redirect::to("/ergo"), "Bitte überprüfe dein Geburtsjahr...");
|
// return Flash::error(Redirect::to("/ergo"), "Bitte überprüfe dein Geburtsjahr...");
|
||||||
}
|
// }
|
||||||
if data.weight < 20 || data.weight > 200 {
|
// if data.weight < 20 || data.weight > 200 {
|
||||||
return Flash::error(Redirect::to("/ergo"), "Bitte überprüfe dein Gewicht...");
|
// return Flash::error(Redirect::to("/ergo"), "Bitte überprüfe dein Gewicht...");
|
||||||
}
|
// }
|
||||||
if &data.sex != "f" && &data.sex != "m" {
|
// if &data.sex != "f" && &data.sex != "m" {
|
||||||
return Flash::error(Redirect::to("/ergo"), "Bitte überprüfe dein Geschlecht...");
|
// return Flash::error(Redirect::to("/ergo"), "Bitte überprüfe dein Geschlecht...");
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
// set data
|
// // set data
|
||||||
user.update_ergo(db, data.birthyear, data.weight, &data.sex)
|
// user.update_ergo(db, data.birthyear, data.weight, &data.sex)
|
||||||
.await;
|
// .await;
|
||||||
|
//
|
||||||
// inform all other `ergo` users
|
// // inform all other `ergo` users
|
||||||
let ergo = Role::find_by_name(db, "ergo").await.unwrap();
|
// let ergo = Role::find_by_name(db, "ergo").await.unwrap();
|
||||||
Notification::create_for_role(
|
// Notification::create_for_role(
|
||||||
db,
|
// db,
|
||||||
&ergo,
|
// &ergo,
|
||||||
&format!("{} nimmt heuer an der Ergochallenge teil 💪", user.name),
|
// &format!("{} nimmt heuer an der Ergochallenge teil 💪", user.name),
|
||||||
"Ergo Challenge",
|
// "Ergo Challenge",
|
||||||
None,
|
// None,
|
||||||
None,
|
// None,
|
||||||
)
|
// )
|
||||||
.await;
|
// .await;
|
||||||
|
//
|
||||||
// add to `ergo` group
|
// // add to `ergo` group
|
||||||
sqlx::query!(
|
// user.add_role(db, &ergo).await.unwrap();
|
||||||
"INSERT INTO user_role(user_id, role_id) VALUES (?, ?)",
|
//
|
||||||
user.id,
|
// Flash::success(
|
||||||
ergo.id
|
// Redirect::to("/ergo"),
|
||||||
)
|
// "Du hast deine Daten erfolgreich eingegeben. Viel Spaß beim Schwitzen :-)",
|
||||||
.execute(db.inner())
|
// )
|
||||||
.await
|
//}
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
ActivityBuilder::new(&format!(
|
|
||||||
"{user} nimmt an der Ergo-Challenge teil und hat gerade die Daten eingegeben."
|
|
||||||
))
|
|
||||||
.user(&user)
|
|
||||||
.save(db)
|
|
||||||
.await;
|
|
||||||
|
|
||||||
Flash::success(
|
|
||||||
Redirect::to("/ergo"),
|
|
||||||
"Du hast deine Daten erfolgreich eingegeben. Viel Spaß beim Schwitzen :-)",
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(FromForm, Debug)]
|
#[derive(FromForm, Debug)]
|
||||||
pub struct ErgoToAdd<'a> {
|
pub struct ErgoToAdd<'a> {
|
||||||
@@ -373,7 +358,10 @@ async fn new_dozen(
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn routes() -> Vec<Route> {
|
pub fn routes() -> Vec<Route> {
|
||||||
routes![index, new_thirty, new_dozen, send, reset, update, new_user]
|
routes![
|
||||||
|
index, new_thirty, new_dozen, send, reset, update,
|
||||||
|
// new_user
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|||||||
@@ -15,7 +15,7 @@
|
|||||||
class="link-primary">Überblick der Challenges</a>
|
class="link-primary">Überblick der Challenges</a>
|
||||||
</li>
|
</li>
|
||||||
<li class="py-1">
|
<li class="py-1">
|
||||||
Eintragung ist jederzeit möglich, wenn du sie auch an die offizielle Liste schicken willst, kannst du das <a href="https://data.ergochallenge.at/" target="_blank" style="text-decoration: underline">hier</a> machen
|
Eintragung ist jederzeit möglich, wenn du sie auch an die offizielle Liste schicken willst, kannst du das <a href="https://data.ergochallenge.at/" target="_blank">hier</a> machen
|
||||||
<li class="py-1">
|
<li class="py-1">
|
||||||
<a href="https://data.ergochallenge.at"
|
<a href="https://data.ergochallenge.at"
|
||||||
target="_blank"
|
target="_blank"
|
||||||
|
|||||||
Reference in New Issue
Block a user