audit log (I forgot)

This commit is contained in:
Daniel Balk
2023-04-03 19:55:11 +02:00
parent 5b807a667d
commit e80af275f7
2 changed files with 13 additions and 4 deletions

View File

@@ -39,13 +39,16 @@ public class AuditLogService
return Task.CompletedTask; return Task.CompletedTask;
} }
public Task LogSystem(AuditLogType type, params object[] data) public Task LogSystem(AuditLogType type, Action<AuditLogParameters> data)
{ {
var al = new AuditLogParameters();
data(al);
var entry = new AuditLogEntry() var entry = new AuditLogEntry()
{ {
Type = type, Type = type,
System = true, System = true,
JsonData = data.Length == 0 ? "" : JsonConvert.SerializeObject(data) JsonData = al.Build()
}; };
Repository.Add(entry); Repository.Add(entry);

View File

@@ -158,7 +158,10 @@ public class UserService
if (isSystemAction) if (isSystemAction)
{ {
await AuditLogService.LogSystem(AuditLogType.ChangePassword, user.Email); await AuditLogService.LogSystem(AuditLogType.ChangePassword, x=>
{
x.Add<User>(user.Email);
});
} }
else else
{ {
@@ -188,7 +191,10 @@ public class UserService
if (BCrypt.Net.BCrypt.Verify(password, user.Password)) if (BCrypt.Net.BCrypt.Verify(password, user.Password))
{ {
await AuditLogService.LogSystem(AuditLogType.Login, user.Email); await AuditLogService.LogSystem(AuditLogType.Login, x =>
{
x.Add<User>(user.Email);
});
return user; return user;
} }