From e80af275f7d0e96874b79d845c99f4d8dbefafa0 Mon Sep 17 00:00:00 2001 From: Daniel Balk <67603460+Daniel-Balk@users.noreply.github.com> Date: Mon, 3 Apr 2023 19:55:11 +0200 Subject: [PATCH] audit log (I forgot) --- Moonlight/App/Services/LogServices/AuditLogService.cs | 7 +++++-- Moonlight/App/Services/UserService.cs | 10 ++++++++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/Moonlight/App/Services/LogServices/AuditLogService.cs b/Moonlight/App/Services/LogServices/AuditLogService.cs index ac9c8845..4b0fdf87 100644 --- a/Moonlight/App/Services/LogServices/AuditLogService.cs +++ b/Moonlight/App/Services/LogServices/AuditLogService.cs @@ -39,13 +39,16 @@ public class AuditLogService return Task.CompletedTask; } - public Task LogSystem(AuditLogType type, params object[] data) + public Task LogSystem(AuditLogType type, Action data) { + var al = new AuditLogParameters(); + data(al); + var entry = new AuditLogEntry() { Type = type, System = true, - JsonData = data.Length == 0 ? "" : JsonConvert.SerializeObject(data) + JsonData = al.Build() }; Repository.Add(entry); diff --git a/Moonlight/App/Services/UserService.cs b/Moonlight/App/Services/UserService.cs index c70ae8e9..d26be75d 100644 --- a/Moonlight/App/Services/UserService.cs +++ b/Moonlight/App/Services/UserService.cs @@ -158,7 +158,10 @@ public class UserService if (isSystemAction) { - await AuditLogService.LogSystem(AuditLogType.ChangePassword, user.Email); + await AuditLogService.LogSystem(AuditLogType.ChangePassword, x=> + { + x.Add(user.Email); + }); } else { @@ -188,7 +191,10 @@ public class UserService if (BCrypt.Net.BCrypt.Verify(password, user.Password)) { - await AuditLogService.LogSystem(AuditLogType.Login, user.Email); + await AuditLogService.LogSystem(AuditLogType.Login, x => + { + x.Add(user.Email); + }); return user; }