Can log actions in JSON format
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2025-10-28 11:43:07 +01:00
parent a128e4a597
commit 2a729d4153
12 changed files with 261 additions and 117 deletions

View File

@@ -111,7 +111,7 @@ pub async fn login_route(
// Check if user session must be closed
if let Some(true) = query.logout {
if let Some(id) = id {
logger.log(Action::Signout);
logger.log(Action::SignOut);
id.logout();
}
success = Some("Goodbye!".to_string());
@@ -155,14 +155,20 @@ pub async fn login_route(
match response {
LoginResult::Success(user) => {
let status = if user.need_reset_password {
logger.log(Action::UserNeedNewPasswordOnLogin(&user));
logger.log(Action::UserNeedNewPasswordOnLogin {
user: user.loggable(),
});
SessionStatus::NeedNewPassword
} else if user.has_two_factor() && !user.can_bypass_two_factors_for_ip(remote_ip.0)
{
logger.log(Action::UserNeed2FAOnLogin(&user));
logger.log(Action::UserNeed2FAOnLogin {
user: user.loggable(),
});
SessionStatus::Need2FA
} else {
logger.log(Action::UserSuccessfullyAuthenticated(&user));
logger.log(Action::UserSuccessfullyAuthenticated {
user: user.loggable(),
});
SessionStatus::SignedIn
};
@@ -172,7 +178,7 @@ pub async fn login_route(
LoginResult::AccountDisabled => {
log::warn!("Failed login for username {} : account is disabled", &login);
logger.log(Action::TryLoginWithDisabledAccount(&login));
logger.log(Action::TryLoginWithDisabledAccount { login: &login });
danger = Some("Your account is disabled!".to_string());
}
@@ -181,7 +187,7 @@ pub async fn login_route(
"Failed login for username {} : attempted to use local auth, but it is forbidden",
&login
);
logger.log(Action::TryLocalLoginFromUnauthorizedAccount(&login));
logger.log(Action::TryLocalLoginFromUnauthorizedAccount { login: &login });
danger = Some("You cannot login from local auth with your account!".to_string());
}
@@ -191,7 +197,7 @@ pub async fn login_route(
c => {
log::warn!("Failed login for ip {remote_ip:?} / username {login}: {c:?}");
logger.log(Action::FailedLoginWithBadCredentials(&login));
logger.log(Action::FailedLoginWithBadCredentials { login: &login });
danger = Some("Login failed.".to_string());
bruteforce
@@ -272,7 +278,7 @@ pub async fn reset_password_route(
danger = Some("Failed to change password!".to_string());
} else {
SessionIdentity(id.as_ref()).set_status(&http_req, SessionStatus::SignedIn);
logger.log(Action::UserChangedPasswordOnLogin(&user_id));
logger.log(Action::UserChangedPasswordOnLogin { user_id: &user_id });
return redirect_user(query.redirect.get());
}
}
@@ -395,7 +401,7 @@ pub async fn login_with_otp(
{
logger.log(Action::OTPLoginAttempt {
success: false,
user: &user,
user: user.loggable(),
});
danger = Some("Specified code is invalid!".to_string());
} else {
@@ -412,7 +418,7 @@ pub async fn login_with_otp(
session.set_status(&http_req, SessionStatus::SignedIn);
logger.log(Action::OTPLoginAttempt {
success: true,
user: &user,
user: user.loggable(),
});
return redirect_user(query.redirect.get());
}