Compare commits
7 Commits
465a42acac
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 1add5c2a2a | |||
| 567f31dd3d | |||
| eec485dced | |||
| b48b689aeb | |||
| 9f57cbaa71 | |||
|
|
284a853344 | ||
| 328a8e3e35 |
104
src/tera/ergo.rs
104
src/tera/ergo.rs
@@ -1,6 +1,6 @@
|
|||||||
use std::env;
|
use std::env;
|
||||||
|
|
||||||
use chrono::Utc;
|
use chrono::{Datelike, Utc};
|
||||||
use rocket::{
|
use rocket::{
|
||||||
form::Form,
|
form::Form,
|
||||||
fs::TempFile,
|
fs::TempFile,
|
||||||
@@ -17,6 +17,7 @@ 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,
|
||||||
@@ -145,47 +146,61 @@ 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 it@rudernlinz.at");
|
return Flash::error(Redirect::to("/ergo"), "Du hast deine Daten schon eingegeben. Wenn du sie updaten willst, melde dich bitte bei info@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
|
||||||
// user.add_role(db, &ergo).await.unwrap();
|
sqlx::query!(
|
||||||
//
|
"INSERT INTO user_role(user_id, role_id) VALUES (?, ?)",
|
||||||
// Flash::success(
|
user.id,
|
||||||
// Redirect::to("/ergo"),
|
ergo.id
|
||||||
// "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> {
|
||||||
@@ -358,10 +373,7 @@ async fn new_dozen(
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn routes() -> Vec<Route> {
|
pub fn routes() -> Vec<Route> {
|
||||||
routes![
|
routes![index, new_thirty, new_dozen, send, reset, update, new_user]
|
||||||
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">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" style="text-decoration: underline">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