always use your own name for registrations; except if the user has the add_different_user permission

This commit is contained in:
philipp 2023-03-23 11:13:19 +01:00
parent de35247c76
commit cde862f97f
7 changed files with 49 additions and 22 deletions

BIN
db.sqlite

Binary file not shown.

2
db.txt
View File

@ -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 "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 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,'')); create unique index UNIQ_trip on trip("day", "user_id", IFNULL(cox_id, ''), IFNULL(begin,''));

View File

@ -16,6 +16,7 @@ pub struct Model {
pub name: String, pub name: String,
pub pw: Option<String>, pub pw: Option<String>,
pub is_cox: bool, pub is_cox: bool,
pub add_different_user: bool,
pub is_admin: bool, pub is_admin: bool,
} }

View File

@ -38,6 +38,8 @@ async fn register(
); );
} }
let user = user::Model::find_or_create_user(&register.name, db.inner()).await;
if let Some(cox_id) = register.cox_id { if let Some(cox_id) = register.cox_id {
let trip = trip::Entity::find_by_id(cox_id) let trip = trip::Entity::find_by_id(cox_id)
.one(db.inner()) .one(db.inner())
@ -57,8 +59,6 @@ async fn register(
} }
} }
let user = user::Model::find_or_create_user(&register.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.clone()), day: Set(day.clone()),

View File

@ -16,6 +16,7 @@ async fn index(db: &State<DatabaseConnection>, user: user::AdminUser) -> Templat
struct UserEditForm { struct UserEditForm {
pw: Option<String>, pw: Option<String>,
is_cox: bool, is_cox: bool,
add_different_user: bool,
is_admin: bool, is_admin: bool,
} }
@ -30,6 +31,7 @@ async fn update(
id: Set(id), id: Set(id),
is_cox: Set(data.is_cox), is_cox: Set(data.is_cox),
is_admin: Set(data.is_admin), is_admin: Set(data.is_admin),
add_different_user: Set(data.add_different_user),
..Default::default() ..Default::default()
}; };
if let Some(pw) = &data.pw { if let Some(pw) = &data.pw {

View File

@ -76,9 +76,11 @@
{% set cox_left = day.planned_amount_cox - amount_cox %} {% set cox_left = day.planned_amount_cox - amount_cox %}
<div class="block text-red">Es {{ cox_left | pluralize(singular="wird", plural="werden")}} noch {{ cox_left }} Steuerperson{{ cox_left | pluralize(plural="en")}} gesucht!</div> <div class="block text-red">Es {{ cox_left | pluralize(singular="wird", plural="werden")}} noch {{ cox_left }} Steuerperson{{ cox_left | pluralize(plural="en")}} gesucht!</div>
{% endif %} {% endif %}
{% set_global user_registered = false %}
<strong class="block mt-1">Abfahrtszeit: {{ day.planned_starting_time }} Uhr</strong> <strong class="block mt-1">Abfahrtszeit: {{ day.planned_starting_time }} Uhr</strong>
<div style="max-width: 75%">{{ 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 %} <div style="max-width: 75%">{{ 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 %}
<form method="post" action="/register"> <form method="post" action="/register">
<input type="hidden" name="_method" value="delete" /> <input type="hidden" name="_method" value="delete" />
<input type="hidden" name="id" value="{{ c.trip.id }}" /> <input type="hidden" name="id" value="{{ c.trip.id }}" />
@ -91,6 +93,7 @@
<li> <li>
{{ r.user.name }} (angemeldet seit {{ r.trip.created | date(format="%d.%m. %H:%M", timezone="Europe/Vienna") }}) {{ r.user.name }} (angemeldet seit {{ r.trip.created | date(format="%d.%m. %H:%M", timezone="Europe/Vienna") }})
{% if r.user.name == user.name %} {% if r.user.name == user.name %}
{% set_global user_registered = true %}
<form method="post" action="/register"> <form method="post" action="/register">
<input type="hidden" name="_method" value="delete" /> <input type="hidden" name="_method" value="delete" />
<input type="hidden" name="id" value="{{ r.trip.id }}" /> <input type="hidden" name="id" value="{{ r.trip.id }}" />
@ -103,6 +106,7 @@
</ol> </ol>
{% if day.open_registration or user.is_cox %} {% if day.open_registration or user.is_cox %}
{% if not user_registered or user.add_different_user %}
<details class="text-right" style="margin-top: -6rem;"> <details class="text-right" style="margin-top: -6rem;">
<summary class="button">&plus;</summary> <summary class="button">&plus;</summary>
<form method="post" class="text-left" action="/register"> <form method="post" class="text-left" action="/register">
@ -110,8 +114,12 @@
<input type="hidden" name="day" value="{{ day_string }}" /> <input type="hidden" name="day" value="{{ day_string }}" />
<div class="row content-align-bottom"> <div class="row content-align-bottom">
<div class="six columns"> <div class="six columns">
{% if user.add_different_user %}
<label for="name">Name</label> <label for="name">Name</label>
<input class="u-full-width" type="text" id="name" name="name" value="{{ user.name }}" /> <input class="u-full-width" type="text" id="name" name="name" value="{{ user.name }}" />
{% else %}
<input class="u-full-width" type="hidden" id="name" name="name" value="{{ user.name }}" />
{% endif %}
</div> </div>
<div class="six columns"> <div class="six columns">
<input class="button-primary" type="submit" value="Speichern"> <input class="button-primary" type="submit" value="Speichern">
@ -119,15 +127,19 @@
</div> </div>
</form> </form>
</details> </details>
{% else %}
{% endif %}
{% else %} {% else %}
Anmeldung an diesem Tag leider nicht möglich (zB bei USI Kursen) Anmeldung an diesem Tag leider nicht möglich (zB bei USI Kursen)
{% endif %} {% endif %}
{% endif %} {% endif %}
{% for trip in indep_trips %} {% for trip in indep_trips %}
{% set_global user_registered = false %}
{% if trip.trip.begin %} {% if trip.trip.begin %}
{{trip.user.name}} @ {{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 %} {% if trip.user.name == user.name and rowers | length == 0 %}
{% set_global user_registered = true %}
<form method="post" action="/register"> <form method="post" action="/register">
<input type="hidden" name="_method" value="delete" /> <input type="hidden" name="_method" value="delete" />
<input type="hidden" name="id" value="{{ trip.trip.id }}" /> <input type="hidden" name="id" value="{{ trip.trip.id }}" />
@ -140,6 +152,7 @@
<li> <li>
{{ r.user.name }} (angemeldet seit {{ r.trip.created | date(format="%d.%m. %H:%M", timezone="Europe/Vienna") }}) {{ r.user.name }} (angemeldet seit {{ r.trip.created | date(format="%d.%m. %H:%M", timezone="Europe/Vienna") }})
{% if r.user.name == user.name %} {% if r.user.name == user.name %}
{% set_global user_registered = true %}
<form method="post" action="/register"> <form method="post" action="/register">
<input type="hidden" name="_method" value="delete" /> <input type="hidden" name="_method" value="delete" />
<input type="hidden" name="id" value="{{ r.trip.id }}" /> <input type="hidden" name="id" value="{{ r.trip.id }}" />
@ -150,6 +163,7 @@
</li> </li>
{% endfor %} {% endfor %}
</ol> </ol>
{% if not user_registered or user.add_different_user %}
<details class="text-right"> <details class="text-right">
<summary class="button">&plus;</summary> <summary class="button">&plus;</summary>
<form method="post" class="text-left" action="/register"> <form method="post" class="text-left" action="/register">
@ -158,8 +172,13 @@
<input type="hidden" name="cox_id" value="{{ trip.trip.id }}" /> <input type="hidden" name="cox_id" value="{{ trip.trip.id }}" />
<div class="row content-align-bottom"> <div class="row content-align-bottom">
<div class="six columns"> <div class="six columns">
{% if user.add_different_user %}
<label for="name">Name</label> <label for="name">Name</label>
<input class="u-full-width" type="text" id="name" name="name" value="{{ user.name }}" /> <input class="u-full-width" type="text" id="name" name="name" value="{{ user.name }}" />
{% else %}
<input class="u-full-width" type="hidden" id="name" name="name" value="{{ user.name }}" />
{% endif %}
</div> </div>
<div class="six columns"> <div class="six columns">
<input class="button-primary" type="submit" value="Speichern"> <input class="button-primary" type="submit" value="Speichern">
@ -168,6 +187,7 @@
</form> </form>
</details> </details>
{% endif %} {% endif %}
{% endif %}
{% endfor %} {% endfor %}

View File

@ -6,6 +6,7 @@
<tr> <tr>
<th>Name</th> <th>Name</th>
<th>Pw</th> <th>Pw</th>
<th>Add Different User</th>
<th>Cox</th> <th>Cox</th>
<th>Admin</th> <th>Admin</th>
<th>Action</th> <th>Action</th>
@ -23,6 +24,9 @@
{% endif %} {% endif %}
<input type="password" name="pw" /> <input type="password" name="pw" />
</td> </td>
<td>
<input type="checkbox" name="add_different_user" {% if user.add_different_user %} checked="true"{% endif %}
</td>
<td> <td>
<input type="checkbox" name="is_cox" {% if user.is_cox %} checked="true"{% endif %} <input type="checkbox" name="is_cox" {% if user.is_cox %} checked="true"{% endif %}
</td> </td>