redo
This commit is contained in:
@@ -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();
|
||||
|
Reference in New Issue
Block a user