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