This commit is contained in:
2025-08-28 16:01:55 +02:00
parent 68b74284c7
commit c7a94893a2
63 changed files with 633 additions and 200 deletions

View File

@@ -4,8 +4,8 @@ using back.persistance.data;
using back.persistance.data.repositories.Abstracts;
using back.services.engine.Crypto;
using back.services.engine.PasswordGenerator;
using MCVIngenieros.Transactional.Abstractions.Interfaces;
using System.Text.Json;
using Transactional.Abstractions.Interfaces;
namespace back.services.engine.SystemUser;
@@ -14,17 +14,20 @@ public class SystemUserGenerator(
JsonSerializerOptions jsonSerializerOptions,
IUserRepository userRepository,
IPersonRepository personRepository,
IRoleRepository roleRepository,
IPermissionRepository permissionRepository,
ICryptoService cryptoService,
IBlobStorageService blobStorageService,
IPasswordGenerator passwordGenerator) : ISystemUserGenerator
{
public async Task GenerateAsync()
{
var systemKey = new SystemKey() {
var systemKey = new SystemKey()
{
Password = passwordGenerator.Generate(16),
};
var systemKeyJson = JsonSerializer.Serialize(systemKey, options: jsonSerializerOptions);
using Stream stream = new MemoryStream(new System.Text.UTF8Encoding(true).GetBytes(systemKeyJson));
await blobStorageService.Delete("systemkey.lock");
@@ -42,11 +45,13 @@ public class SystemUserGenerator(
{
await transactional.DoTransaction(async () =>
{
await permissionRepository.SeedDefaultPermissions();
await roleRepository.SeedDefaultRoles();
await personRepository.Insert(Person.SystemPerson);
await userRepository.Insert(User.SystemUser);
});
}
else
else
{
await userRepository.Update(User.SystemUser);
await userRepository.SaveChanges();