add more logs
This commit is contained in:
		@@ -6,6 +6,7 @@ use rocket::{post, FromForm};
 | 
			
		||||
use rocket_dyn_templates::{tera::Context, Template};
 | 
			
		||||
use sqlx::SqlitePool;
 | 
			
		||||
 | 
			
		||||
use crate::model::log::Log;
 | 
			
		||||
use crate::model::mail::Mail;
 | 
			
		||||
use crate::model::role::Role;
 | 
			
		||||
use crate::model::user::AdminUser;
 | 
			
		||||
@@ -34,7 +35,8 @@ async fn index(
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#[get("/mail/fee")]
 | 
			
		||||
async fn fee(db: &State<SqlitePool>, _admin: AdminUser, config: &State<Config>) -> &'static str {
 | 
			
		||||
async fn fee(db: &State<SqlitePool>, admin: AdminUser, config: &State<Config>) -> &'static str {
 | 
			
		||||
    Log::create(db, format!("{admin:?} trying to send fee")).await;
 | 
			
		||||
    Mail::fees(db, config.smtp_pw.clone()).await;
 | 
			
		||||
    "SUCC"
 | 
			
		||||
}
 | 
			
		||||
@@ -42,9 +44,10 @@ async fn fee(db: &State<SqlitePool>, _admin: AdminUser, config: &State<Config>)
 | 
			
		||||
#[get("/mail/fee-final")]
 | 
			
		||||
async fn fee_final(
 | 
			
		||||
    db: &State<SqlitePool>,
 | 
			
		||||
    _admin: AdminUser,
 | 
			
		||||
    admin: AdminUser,
 | 
			
		||||
    config: &State<Config>,
 | 
			
		||||
) -> &'static str {
 | 
			
		||||
    Log::create(db, format!("{admin:?} trying to send fee_final")).await;
 | 
			
		||||
    Mail::fees_final(db, config.smtp_pw.clone()).await;
 | 
			
		||||
    "SUCC"
 | 
			
		||||
}
 | 
			
		||||
@@ -62,12 +65,15 @@ async fn update(
 | 
			
		||||
    db: &State<SqlitePool>,
 | 
			
		||||
    data: Form<MailToSend<'_>>,
 | 
			
		||||
    config: &State<Config>,
 | 
			
		||||
    _admin: AdminUser,
 | 
			
		||||
    admin: AdminUser,
 | 
			
		||||
) -> Flash<Redirect> {
 | 
			
		||||
    let d = data.into_inner();
 | 
			
		||||
    Log::create(db, format!("{admin:?} trying to send this mail: {d:?}")).await;
 | 
			
		||||
    if Mail::send(db, d, config.smtp_pw.clone()).await {
 | 
			
		||||
        Log::create(db, "Mail successfully sent".into()).await;
 | 
			
		||||
        Flash::success(Redirect::to("/admin/mail"), "Mail versendet")
 | 
			
		||||
    } else {
 | 
			
		||||
        Log::create(db, "Error sending the mail".into()).await;
 | 
			
		||||
        Flash::error(Redirect::to("/admin/mail"), "Fehler")
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -2,6 +2,7 @@ use std::collections::HashMap;
 | 
			
		||||
 | 
			
		||||
use crate::model::{
 | 
			
		||||
    family::Family,
 | 
			
		||||
    log::Log,
 | 
			
		||||
    logbook::Logbook,
 | 
			
		||||
    role::Role,
 | 
			
		||||
    user::{AdminUser, User, UserWithRoles, VorstandUser},
 | 
			
		||||
@@ -163,10 +164,15 @@ async fn scheckbuch(
 | 
			
		||||
#[get("/user/fees/paid?<user_ids>")]
 | 
			
		||||
async fn fees_paid(
 | 
			
		||||
    db: &State<SqlitePool>,
 | 
			
		||||
    _admin: AdminUser,
 | 
			
		||||
    admin: AdminUser,
 | 
			
		||||
    user_ids: Vec<i32>,
 | 
			
		||||
    referer: Referer,
 | 
			
		||||
) -> Flash<Redirect> {
 | 
			
		||||
    Log::create(
 | 
			
		||||
        db,
 | 
			
		||||
        format!("{admin:?} set fees paid for user_ids: {user_ids:?}"),
 | 
			
		||||
    )
 | 
			
		||||
    .await;
 | 
			
		||||
    let mut res = String::new();
 | 
			
		||||
    for user_id in user_ids {
 | 
			
		||||
        let user = User::find_by_id(db, user_id).await.unwrap();
 | 
			
		||||
@@ -204,8 +210,9 @@ async fn resetpw(db: &State<SqlitePool>, _admin: AdminUser, user: i32) -> Flash<
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#[get("/user/<user>/delete")]
 | 
			
		||||
async fn delete(db: &State<SqlitePool>, _admin: AdminUser, user: i32) -> Flash<Redirect> {
 | 
			
		||||
async fn delete(db: &State<SqlitePool>, admin: AdminUser, user: i32) -> Flash<Redirect> {
 | 
			
		||||
    let user = User::find_by_id(db, user).await;
 | 
			
		||||
    Log::create(db, format!("{admin:?} deleted user: {user:?}")).await;
 | 
			
		||||
    match user {
 | 
			
		||||
        Some(user) => {
 | 
			
		||||
            user.delete(db).await;
 | 
			
		||||
@@ -239,9 +246,14 @@ pub struct UserEditForm {
 | 
			
		||||
async fn update(
 | 
			
		||||
    db: &State<SqlitePool>,
 | 
			
		||||
    data: Form<UserEditForm>,
 | 
			
		||||
    _admin: AdminUser,
 | 
			
		||||
    admin: AdminUser,
 | 
			
		||||
) -> Flash<Redirect> {
 | 
			
		||||
    let user = User::find_by_id(db, data.id).await;
 | 
			
		||||
    Log::create(
 | 
			
		||||
        db,
 | 
			
		||||
        format!("{admin:?} updated user from {user:?} to {data:?}"),
 | 
			
		||||
    )
 | 
			
		||||
    .await;
 | 
			
		||||
    let Some(user) = user else {
 | 
			
		||||
        return Flash::error(
 | 
			
		||||
            Redirect::to("/admin/user"),
 | 
			
		||||
@@ -254,7 +266,7 @@ async fn update(
 | 
			
		||||
    Flash::success(Redirect::to("/admin/user"), "Successfully updated user")
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#[derive(FromForm)]
 | 
			
		||||
#[derive(FromForm, Debug)]
 | 
			
		||||
struct UserAddForm<'r> {
 | 
			
		||||
    name: &'r str,
 | 
			
		||||
}
 | 
			
		||||
@@ -263,8 +275,9 @@ struct UserAddForm<'r> {
 | 
			
		||||
async fn create(
 | 
			
		||||
    db: &State<SqlitePool>,
 | 
			
		||||
    data: Form<UserAddForm<'_>>,
 | 
			
		||||
    _admin: AdminUser,
 | 
			
		||||
    admin: AdminUser,
 | 
			
		||||
) -> Flash<Redirect> {
 | 
			
		||||
    Log::create(db, format!("{admin:?} created new user: {data:?}")).await;
 | 
			
		||||
    if User::create(db, data.name).await {
 | 
			
		||||
        Flash::success(Redirect::to("/admin/user"), "Successfully created user")
 | 
			
		||||
    } else {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user