allow guests to see + upload ergo entries; show ergo menu item for guests

This commit is contained in:
philipp 2023-11-03 14:20:58 +01:00
parent 9331b2001d
commit 95e1ea3028
2 changed files with 12 additions and 16 deletions

View File

@ -67,11 +67,7 @@ async fn reset(db: &State<SqlitePool>, _user: AdminUser) -> Flash<Redirect> {
} }
#[get("/")] #[get("/")]
async fn index( async fn index(db: &State<SqlitePool>, user: User, flash: Option<FlashMessage<'_>>) -> Template {
db: &State<SqlitePool>,
user: NonGuestUser,
flash: Option<FlashMessage<'_>>,
) -> Template {
let users = User::ergo(db).await; let users = User::ergo(db).await;
let thirty = sqlx::query_as!( let thirty = sqlx::query_as!(
@ -94,7 +90,7 @@ async fn index(
if let Some(msg) = flash { if let Some(msg) = flash {
context.insert("flash", &msg.into_inner()); context.insert("flash", &msg.into_inner());
} }
context.insert("loggedin_user", &user.user); context.insert("loggedin_user", &user);
context.insert("users", &users); context.insert("users", &users);
context.insert("thirty", &thirty); context.insert("thirty", &thirty);
context.insert("dozen", &dozen); context.insert("dozen", &dozen);
@ -113,7 +109,7 @@ pub struct ErgoToAdd<'a> {
async fn new_thirty( async fn new_thirty(
db: &State<SqlitePool>, db: &State<SqlitePool>,
mut data: Form<ErgoToAdd<'_>>, mut data: Form<ErgoToAdd<'_>>,
created_by: NonGuestUser, created_by: User,
) -> Flash<Redirect> { ) -> Flash<Redirect> {
let user = User::find_by_id(db, data.user as i32).await.unwrap(); let user = User::find_by_id(db, data.user as i32).await.unwrap();
@ -139,10 +135,7 @@ async fn new_thirty(
Log::create( Log::create(
db, db,
format!( format!("{} created thirty-ergo entry: {data:?}", created_by.name),
"{} created thirty-ergo entry: {data:?}",
created_by.user.name
),
) )
.await; .await;
@ -153,7 +146,7 @@ async fn new_thirty(
async fn new_dozen( async fn new_dozen(
db: &State<SqlitePool>, db: &State<SqlitePool>,
mut data: Form<ErgoToAdd<'_>>, mut data: Form<ErgoToAdd<'_>>,
created_by: NonGuestUser, created_by: User,
) -> Flash<Redirect> { ) -> Flash<Redirect> {
let user = User::find_by_id(db, data.user as i32).await.unwrap(); let user = User::find_by_id(db, data.user as i32).await.unwrap();
@ -179,10 +172,7 @@ async fn new_dozen(
Log::create( Log::create(
db, db,
format!( format!("{} created dozen-ergo entry: {data:?}", created_by.name),
"{} created dozen-ergo entry: {data:?}",
created_by.user.name
),
) )
.await; .await;

View File

@ -78,6 +78,12 @@
</a> </a>
</div> </div>
</div> </div>
{% else %}
{% if loggedin_user.weight and loggedin_user.sex and loggedin_user.dob %}
<a href="/ergo">
Ergo
</a>
{% endif %}
{% endif %} {% if loggedin_user.is_admin %} {% endif %} {% if loggedin_user.is_admin %}
<a <a
href="/admin/user" href="/admin/user"