Jelszó módosítása

This commit is contained in:
2025-04-14 12:31:50 +02:00
parent 44e6719c3d
commit 29200ae418
18 changed files with 676 additions and 9 deletions
+1
View File
@@ -18,6 +18,7 @@ namespace WorkFlowCheck.BL.Infra
service.AddScoped<ICheckListService, CheckListService>();
service.AddScoped<INumberGeneratorService, NumberGeneratorService>();
service.AddScoped<IMessageService, MessageService>();
service.AddScoped<ISystemService, SystemService>();
}
}
}
@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace WorkFlowCheck.BL.Services.Interfaces
{
public interface ISystemService
{
Task<string> GetDatabaseAndVersionInfoAsync();
}
}
@@ -16,6 +16,7 @@ namespace WorkFlowCheck.BL.Services.Interfaces
Task<UserDTO> Authenticate(string UserName, string Password);
Task<string> Authenticate2F1(string UserName, string Password);
Task<UserDTO> Authenticate2F2(string UserName, string Password, string Code, string token2FA);
Task<UserDTO> Authenticate2F2ChangePassword(string UserName, string OldPassword, string NewPassword, string Code, string token2FA);
Task<UserDTO> AuthenticateNFC(string NFCCode);
@@ -0,0 +1,49 @@
using AutoMapper;
using DocumentFormat.OpenXml.InkML;
using Microsoft.Data.SqlClient;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WorkFlowCheck.BL.Services.Interfaces;
using WorkFlowCheck.DL;
namespace WorkFlowCheck.BL.Services
{
public class SystemService : ISystemService
{
public readonly AppDbContext _dbContext;
public readonly IMapper _mapper;
public readonly IConfiguration _config;
public SystemService(AppDbContext dbContext,
IMapper mapper,
IConfiguration configuration)
{
_config = configuration;
_dbContext = dbContext;
_mapper = mapper;
}
public async Task<string> GetDatabaseAndVersionInfoAsync()
{
var retVal = "";
var connection = _dbContext.Database.GetDbConnection();
var typeName = connection.GetType().Name;
//if (typeName.Contains("Npgsql"))
//{
// var builder = new NpgsqlConnectionStringBuilder(connection.ConnectionString);
// retVal= builder.Database;
//}
if (typeName.Contains("SqlConnection"))
{
var builder = new SqlConnectionStringBuilder(connection.ConnectionString);
retVal= builder.InitialCatalog;
}
return retVal;
}
}
}
+48 -1
View File
@@ -208,7 +208,54 @@ namespace WorkFlowCheck.BL.Services
}
return retVal;
}
public async Task<UserDTO> Authenticate2F2ChangePassword(string userName, string oldPassword, string newPassword, string code, string token2FA)
{
var retVal = new UserDTO() { RoleDTO = new List<RoleDTO>() };
try
{
var user = await _dbContext.Users
.Include(i => i.UserRoles)
.ThenInclude(i => i.Role)
.Where(w => w.UserName == userName && w.Active != false)
.FirstOrDefaultAsync();
if (user != null && PasswordHasher.VerifyPassword(user.PasswordHash, oldPassword))
{
if (CodeGenerator2F.ValidateToken2F(token2FA, userName, oldPassword, code))
{
user.PasswordHash = PasswordHasher.HashPassword(newPassword);
var userDTO = new UserDTO()
{
Id = user.Id,
UserName = user.UserName,
RoleDTO = new List<RoleDTO>(),
};
foreach (var item in user.UserRoles)
{
userDTO.RoleDTO.Add(new RoleDTO()
{
Id = item.Role.Id,
RoleName = item.Role.RoleName,
});
}
user.PasswordHash = PasswordHasher.HashPassword(newPassword);
user.JwtToken = GenerateJwtToken(userDTO);
await _dbContext.SaveChangesAsync();
retVal = _mapper.Map<UserDTO>(user);
return retVal;
}
}
}
catch (Exception ex)
{
Log.Error(ex.Message);
}
return retVal;
}
public async Task<UserDTO> AuthenticateNFC(string NFCCode)
{