Switched to serilog as logging system
This commit is contained in:
@@ -5,7 +5,6 @@ using Moonlight.App.Exceptions;
|
||||
using Moonlight.App.Helpers;
|
||||
using Moonlight.App.Models.Misc;
|
||||
using Moonlight.App.Repositories;
|
||||
using Moonlight.App.Services.LogServices;
|
||||
using Moonlight.App.Services.Mail;
|
||||
using Moonlight.App.Services.Sessions;
|
||||
|
||||
@@ -15,8 +14,6 @@ public class UserService
|
||||
{
|
||||
private readonly UserRepository UserRepository;
|
||||
private readonly TotpService TotpService;
|
||||
private readonly SecurityLogService SecurityLogService;
|
||||
private readonly AuditLogService AuditLogService;
|
||||
private readonly MailService MailService;
|
||||
private readonly IdentityService IdentityService;
|
||||
private readonly IpLocateService IpLocateService;
|
||||
@@ -27,9 +24,7 @@ public class UserService
|
||||
public UserService(
|
||||
UserRepository userRepository,
|
||||
TotpService totpService,
|
||||
ConfigService configService,
|
||||
SecurityLogService securityLogService,
|
||||
AuditLogService auditLogService,
|
||||
ConfigService configService,
|
||||
MailService mailService,
|
||||
IdentityService identityService,
|
||||
IpLocateService ipLocateService,
|
||||
@@ -37,8 +32,6 @@ public class UserService
|
||||
{
|
||||
UserRepository = userRepository;
|
||||
TotpService = totpService;
|
||||
SecurityLogService = securityLogService;
|
||||
AuditLogService = auditLogService;
|
||||
MailService = mailService;
|
||||
IdentityService = identityService;
|
||||
IpLocateService = ipLocateService;
|
||||
@@ -85,10 +78,7 @@ public class UserService
|
||||
|
||||
await MailService.SendMail(user!, "register", values => {});
|
||||
|
||||
await AuditLogService.Log(AuditLogType.Register, x =>
|
||||
{
|
||||
x.Add<User>(user.Email);
|
||||
});
|
||||
//TODO: AuditLog
|
||||
|
||||
return await GenerateToken(user);
|
||||
}
|
||||
@@ -102,11 +92,7 @@ public class UserService
|
||||
|
||||
if (user == null)
|
||||
{
|
||||
await SecurityLogService.Log(SecurityLogType.LoginFail, x =>
|
||||
{
|
||||
x.Add<User>(email);
|
||||
x.Add<string>(password);
|
||||
});
|
||||
Logger.Warn($"Failed login attempt. Email: {email} Password: {password}", "security");
|
||||
throw new DisplayException("Email and password combination not found");
|
||||
}
|
||||
|
||||
@@ -115,11 +101,7 @@ public class UserService
|
||||
return user.TotpEnabled;
|
||||
}
|
||||
|
||||
await SecurityLogService.Log(SecurityLogType.LoginFail, x =>
|
||||
{
|
||||
x.Add<User>(email);
|
||||
x.Add<string>(password);
|
||||
});
|
||||
Logger.Warn($"Failed login attempt. Email: {email} Password: {password}", "security");
|
||||
throw new DisplayException("Email and password combination not found");;
|
||||
}
|
||||
|
||||
@@ -144,28 +126,18 @@ public class UserService
|
||||
|
||||
if (totpCodeValid)
|
||||
{
|
||||
await AuditLogService.Log(AuditLogType.Login, x =>
|
||||
{
|
||||
x.Add<User>(email);
|
||||
});
|
||||
//TODO: AuditLog
|
||||
return await GenerateToken(user, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
await SecurityLogService.Log(SecurityLogType.LoginFail, x =>
|
||||
{
|
||||
x.Add<User>(email);
|
||||
x.Add<string>(password);
|
||||
});
|
||||
Logger.Warn($"Failed login attempt. Email: {email} Password: {password}", "security");
|
||||
throw new DisplayException("2FA code invalid");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
await AuditLogService.Log(AuditLogType.Login, x =>
|
||||
{
|
||||
x.Add<User>(email);
|
||||
});
|
||||
//TODO: AuditLog
|
||||
return await GenerateToken(user!, true);
|
||||
}
|
||||
}
|
||||
@@ -178,10 +150,7 @@ public class UserService
|
||||
|
||||
if (isSystemAction)
|
||||
{
|
||||
await AuditLogService.LogSystem(AuditLogType.ChangePassword, x=>
|
||||
{
|
||||
x.Add<User>(user.Email);
|
||||
});
|
||||
//TODO: AuditLog
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -194,10 +163,7 @@ public class UserService
|
||||
values.Add("Location", location);
|
||||
});
|
||||
|
||||
await AuditLogService.Log(AuditLogType.ChangePassword, x =>
|
||||
{
|
||||
x.Add<User>(user.Email);
|
||||
});
|
||||
//TODO: AuditLog
|
||||
}
|
||||
}
|
||||
|
||||
@@ -207,28 +173,18 @@ public class UserService
|
||||
|
||||
if (user == null)
|
||||
{
|
||||
await SecurityLogService.LogSystem(SecurityLogType.SftpBruteForce, x =>
|
||||
{
|
||||
x.Add<int>(id);
|
||||
});
|
||||
Logger.Warn($"Detected an sftp bruteforce attempt. ID: {id} Password: {password}", "security");
|
||||
|
||||
throw new Exception("Invalid username");
|
||||
}
|
||||
|
||||
if (BCrypt.Net.BCrypt.Verify(password, user.Password))
|
||||
{
|
||||
await AuditLogService.LogSystem(AuditLogType.Login, x =>
|
||||
{
|
||||
x.Add<User>(user.Email);
|
||||
});
|
||||
//TODO: AuditLog
|
||||
return user;
|
||||
}
|
||||
|
||||
await SecurityLogService.LogSystem(SecurityLogType.SftpBruteForce, x =>
|
||||
{
|
||||
x.Add<int>(id);
|
||||
x.Add<string>(password);
|
||||
});
|
||||
Logger.Warn($"Detected an sftp bruteforce attempt. ID: {id} Password: {password}", "security");
|
||||
throw new Exception("Invalid userid or password");
|
||||
}
|
||||
|
||||
@@ -271,7 +227,7 @@ public class UserService
|
||||
var newPassword = StringHelper.GenerateString(16);
|
||||
await ChangePassword(user, newPassword, true);
|
||||
|
||||
await AuditLogService.Log(AuditLogType.PasswordReset, x => {});
|
||||
//TODO: AuditLog
|
||||
|
||||
var location = await IpLocateService.GetLocation();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user