healthchecks

This commit is contained in:
2025-08-25 18:52:59 +02:00
parent 5777e351bf
commit 0560a40876
33 changed files with 317 additions and 127 deletions

View File

@@ -4,13 +4,15 @@ using back.persistance.data.repositories.Abstracts;
using back.services.engine.Crypto;
using back.services.engine.mailing;
using System.Text;
using System.Text.Json;
namespace back.services.bussines.UserService;
public class UserService(
IUserRepository userRepository, ICryptoService cryptoService,
IEmailService emailService,
IBlobStorageService blobStorageService
IBlobStorageService blobStorageService,
JsonSerializerOptions jsonSerializerOptions
) : IUserService
{
private readonly IUserRepository _repository = userRepository ?? throw new ArgumentNullException(nameof(userRepository));
@@ -66,6 +68,14 @@ public class UserService(
return existingUser;
}
public async Task<User?> Login(string email, string decryptedPass)
{
var salt = await _repository.GetUserSaltByEmail(email);
var hashedPassword = _cryptoService.HashPassword(decryptedPass, salt);
var user = await _repository.Login(email, hashedPassword ?? string.Empty);
return user;
}
public async Task<User?> Login(string email, string password, string clientId)
{
if (string.IsNullOrEmpty(email) || string.IsNullOrEmpty(password)) return null;
@@ -73,9 +83,7 @@ public class UserService(
try
{
var decryptedPass = _cryptoService.Decrypt(clientId, password);
var salt = await _repository.GetUserSaltByEmail(email);
var hashedPassword = _cryptoService.HashPassword(decryptedPass, salt);
var user = await _repository.Login(email, hashedPassword ?? string.Empty);
var user = await Login(email, decryptedPass ?? string.Empty);
return user;
}
catch
@@ -101,21 +109,21 @@ public class UserService(
public async Task<User?> ValidateSystemUser(string email, string password, string systemKey, string clientId)
{
password = _cryptoService.Decrypt(clientId, password) ?? string.Empty;
systemKey = _cryptoService.Decrypt(clientId, systemKey) ?? string.Empty;
if (string.IsNullOrEmpty(email) || string.IsNullOrEmpty(password) || string.IsNullOrEmpty(systemKey))
var decryptedPassword = _cryptoService.Decrypt(clientId, password) ?? string.Empty;
var decryptedsystemKey = _cryptoService.Decrypt(clientId, systemKey) ?? string.Empty;
if (string.IsNullOrEmpty(email) || string.IsNullOrEmpty(decryptedPassword) || string.IsNullOrEmpty(decryptedsystemKey))
{
return null;
}
if (!email.Equals("@system", StringComparison.InvariantCultureIgnoreCase))
if (!email.Equals(User.SystemUser.Email, StringComparison.InvariantCultureIgnoreCase))
{
return null;
}
var systemKeyBytes = await _blobStorageService.GetBytes("systemkey.lock");
var systemKeyString = Encoding.UTF8.GetString(systemKeyBytes ?? []);
var systemKeyObject = System.Text.Json.JsonSerializer.Deserialize<SystemKey>(systemKeyString);
if (systemKeyObject == null || !systemKeyObject.IsValid(email, password, systemKey))
var systemKeyObject = JsonSerializer.Deserialize<SystemKey>(systemKeyString, jsonSerializerOptions);
if (systemKeyObject == null || !systemKeyObject.IsValid(email, decryptedPassword, decryptedsystemKey))
{
return null;
}
@@ -128,6 +136,6 @@ public class UserService(
{
return null;
}
return await Login(user.Email!, user.Password!, clientId);
return await Login(user.Email!, decryptedPassword);
}
}