diff --git a/db.sqlite b/db.sqlite index 23949f0..ccfb4fa 100644 Binary files a/db.sqlite and b/db.sqlite differ diff --git a/db.txt b/db.txt index 0e49bad..5e4e1cc 100644 --- a/db.txt +++ b/db.txt @@ -1,4 +1,4 @@ CREATE TABLE IF NOT EXISTS "day" ( "day" text NOT NULL PRIMARY KEY, "planned_amount_cox" integer NOT NULL DEFAULT 0, "planned_starting_time" text, "open_registration" boolean NOT NULL DEFAULT TRUE ); -CREATE TABLE IF NOT EXISTS "user" ( "id" integer NOT NULL PRIMARY KEY AUTOINCREMENT, "name" text NOT NULL UNIQUE, "pw" text, "is_cox" boolean NOT NULL DEFAULT FALSE, "is_admin" boolean NOT NULL DEFAULT FALSE ); +CREATE TABLE IF NOT EXISTS "user" ( "id" integer NOT NULL PRIMARY KEY AUTOINCREMENT, "name" text NOT NULL UNIQUE, "pw" text, "is_cox" boolean NOT NULL DEFAULT FALSE, "add_different_user" boolean NOT NULL DEFAULT FALSE, "is_admin" boolean NOT NULL DEFAULT FALSE ); CREATE TABLE IF NOT EXISTS "trip" ( "id" integer NOT NULL PRIMARY KEY AUTOINCREMENT, "day" text NOT NULL, "user_id" integer NOT NULL, "cox_id" integer, "begin" text, "created" text NOT NULL DEFAULT CURRENT_TIMESTAMP, FOREIGN KEY ("day") REFERENCES "day" ("day"), FOREIGN KEY ("user_id") REFERENCES "user" ("id"), FOREIGN KEY ("cox_id") REFERENCES "trip" ("id") ); create unique index UNIQ_trip on trip("day", "user_id", IFNULL(cox_id, ''), IFNULL(begin,'')); diff --git a/src/models/user.rs b/src/models/user.rs index 52a30ed..b11a8ee 100644 --- a/src/models/user.rs +++ b/src/models/user.rs @@ -16,6 +16,7 @@ pub struct Model { pub name: String, pub pw: Option, pub is_cox: bool, + pub add_different_user: bool, pub is_admin: bool, } diff --git a/src/rest/restreg.rs b/src/rest/restreg.rs index d6c686b..579b9aa 100644 --- a/src/rest/restreg.rs +++ b/src/rest/restreg.rs @@ -38,6 +38,8 @@ async fn register( ); } + let user = user::Model::find_or_create_user(®ister.name, db.inner()).await; + if let Some(cox_id) = register.cox_id { let trip = trip::Entity::find_by_id(cox_id) .one(db.inner()) @@ -57,8 +59,6 @@ async fn register( } } - let user = user::Model::find_or_create_user(®ister.name, db.inner()).await; - let day = format!("{}", day.day.format("%Y-%m-%d")); let trip = trip::ActiveModel { day: Set(day.clone()), diff --git a/src/rest/restuser.rs b/src/rest/restuser.rs index 6c45829..2121bd2 100644 --- a/src/rest/restuser.rs +++ b/src/rest/restuser.rs @@ -16,6 +16,7 @@ async fn index(db: &State, user: user::AdminUser) -> Templat struct UserEditForm { pw: Option, is_cox: bool, + add_different_user: bool, is_admin: bool, } @@ -30,6 +31,7 @@ async fn update( id: Set(id), is_cox: Set(data.is_cox), is_admin: Set(data.is_admin), + add_different_user: Set(data.add_different_user), ..Default::default() }; if let Some(pw) = &data.pw { diff --git a/templates/index.html.tera b/templates/index.html.tera index ff71aa9..81dcd37 100644 --- a/templates/index.html.tera +++ b/templates/index.html.tera @@ -76,9 +76,11 @@ {% set cox_left = day.planned_amount_cox - amount_cox %}
Es {{ cox_left | pluralize(singular="wird", plural="werden")}} noch {{ cox_left }} Steuerperson{{ cox_left | pluralize(plural="en")}} gesucht!
{% endif %} + {% set_global user_registered = false %} Abfahrtszeit: {{ day.planned_starting_time }} Uhr
{{ default_trips | length }} angemeldete Person{{ default_trips | length | pluralize(plural="en") }}: {{ cox | length }} Steuerperson{{ cox | length | pluralize(plural="en") }} ({% for c in cox %}{{ c.user.name }} {% if c.user.name == user.name %} + {% set_global user_registered = true %}
@@ -91,6 +93,7 @@
  • {{ r.user.name }} (angemeldet seit {{ r.trip.created | date(format="%d.%m. %H:%M", timezone="Europe/Vienna") }}) {% if r.user.name == user.name %} + {% set_global user_registered = true %} @@ -103,31 +106,40 @@ {% if day.open_registration or user.is_cox %} -
    - + - - - -
    -
    - - -
    -
    - -
    -
    - -
    + {% if not user_registered or user.add_different_user %} +
    + + +
    + + +
    +
    + {% if user.add_different_user %} + + + {% else %} + + {% endif %} +
    +
    + +
    +
    +
    +
    + {% else %} + {% endif %} {% else %} Anmeldung an diesem Tag leider nicht möglich (zB bei USI Kursen) {% endif %} {% endif %} {% for trip in indep_trips %} + {% set_global user_registered = false %} {% if trip.trip.begin %} {{trip.user.name}} @ {{trip.trip.begin}} - {% set rowers = indep_trips | filter(attribute="trip.cox_id", value=trip.trip.id) %} + {% set rowers = indep_trips | filter(attribute="trip.cox_id", value=trip.trip.id) | sort(attribute="trip.created")%} {% if trip.user.name == user.name and rowers | length == 0 %} + {% set_global user_registered = true %}
    @@ -140,6 +152,7 @@
  • {{ r.user.name }} (angemeldet seit {{ r.trip.created | date(format="%d.%m. %H:%M", timezone="Europe/Vienna") }}) {% if r.user.name == user.name %} + {% set_global user_registered = true %} @@ -150,6 +163,7 @@
  • {% endfor %} + {% if not user_registered or user.add_different_user %}
    + @@ -158,8 +172,13 @@
    - - + + {% if user.add_different_user %} + + + {% else %} + + {% endif %}
    @@ -167,6 +186,7 @@
    + {% endif %} {% endif %} {% endfor %} diff --git a/templates/user/index.html.tera b/templates/user/index.html.tera index 740621d..39ec0a0 100644 --- a/templates/user/index.html.tera +++ b/templates/user/index.html.tera @@ -6,6 +6,7 @@ Name Pw + Add Different User Cox Admin Action @@ -23,6 +24,9 @@ {% endif %} + +