Additional audit logs
This commit is contained in:
@@ -17,11 +17,7 @@ namespace FoodsharingSiegen.Contracts.Entity
|
||||
/// The save profile audit type
|
||||
/// </summary>
|
||||
SaveProfile = 10,
|
||||
|
||||
/// <summary>
|
||||
/// The set own password audit type
|
||||
/// </summary>
|
||||
SetOwnPassword = 20,
|
||||
|
||||
|
||||
#region Usermanagement
|
||||
|
||||
|
||||
@@ -20,8 +20,6 @@ namespace FoodsharingSiegen.Server.Data
|
||||
{
|
||||
case AuditType.SaveProfile:
|
||||
return "hat das eigene Profil gespeichert.";
|
||||
case AuditType.SetOwnPassword:
|
||||
return "hat das eigene Passwort geändert.";
|
||||
case AuditType.CreateUser:
|
||||
return $"hat den User {audit.Data1} erstellt.";
|
||||
case AuditType.UpdateUser:
|
||||
|
||||
@@ -11,6 +11,8 @@ namespace FoodsharingSiegen.Server.Data.Service
|
||||
/// <seealso cref="ServiceBase"/>
|
||||
public class UserService : ServiceBase
|
||||
{
|
||||
private AuditService AuditService { get; }
|
||||
|
||||
#region Setup/Teardown
|
||||
|
||||
/// <summary>
|
||||
@@ -18,7 +20,8 @@ namespace FoodsharingSiegen.Server.Data.Service
|
||||
/// </summary>
|
||||
/// <param name="context">The context</param>
|
||||
/// <param name="authService"></param>
|
||||
public UserService(FsContext context, AuthService authService) : base(context, authService) { }
|
||||
/// <param name="auditService"></param>
|
||||
public UserService(FsContext context, AuthService authService, AuditService auditService) : base(context, authService) => AuditService = auditService;
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -46,6 +49,8 @@ namespace FoodsharingSiegen.Server.Data.Service
|
||||
var saveResult = await Context.SaveChangesAsync();
|
||||
if (saveResult == 0) return new OperationResult<User>(new Exception("Fehler bei der Registrierung"));
|
||||
|
||||
await AuditService.Insert(AuditType.CreateUser, user.Mail);
|
||||
|
||||
return new OperationResult<User>(user);
|
||||
}
|
||||
catch (Exception e)
|
||||
@@ -100,6 +105,10 @@ namespace FoodsharingSiegen.Server.Data.Service
|
||||
var saveR = await Context.SaveChangesAsync();
|
||||
|
||||
if(saveR < 1) return new OperationResult(new Exception("Fehler beim Speichern"));
|
||||
|
||||
var auditData = CurrentUser?.Id == user.Id ? "sich selbst" : user.Mail;
|
||||
await AuditService.Insert(AuditType.SetUserPassword, auditData);
|
||||
|
||||
return new OperationResult();
|
||||
}
|
||||
catch (Exception e)
|
||||
@@ -146,6 +155,7 @@ namespace FoodsharingSiegen.Server.Data.Service
|
||||
var saveR = await Context.SaveChangesAsync();
|
||||
|
||||
if(saveR < 1) return new OperationResult(new Exception("Fehler beim Speichern"));
|
||||
await AuditService.Insert(AuditType.UpdateUser, user.Mail);
|
||||
return new OperationResult();
|
||||
}
|
||||
catch (Exception e)
|
||||
|
||||
Reference in New Issue
Block a user