Egy kis authentikáció

This commit is contained in:
2025-01-21 15:52:30 +01:00
parent 3b11c6adc5
commit 30d82fc9bf
12 changed files with 186 additions and 12 deletions
@@ -1,7 +1,8 @@
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using WorkFlowCheck.BL.DTO;
using WorkFlowCheck.Common.DTO;
using WorkFlowCheck.BL.Services.Interfaces;
using Serilog;
namespace WorkFlowCheck.API.Controllers
{
@@ -47,5 +48,53 @@ namespace WorkFlowCheck.API.Controllers
return retVal;
}
[HttpPost("authenticate")]
public async Task<ApiResponseDTO<UserDTO>> Authenticate([FromBody] UserDTO userDTO)
{
var retVal = new ApiResponseDTO<UserDTO>()
{
IsSuccess = true
};
if (string.IsNullOrEmpty(userDTO.UserName) || string.IsNullOrEmpty(userDTO.Password))
{
retVal.IsSuccess = false;
retVal.Errors.Add("Nem megfelelő felhasználói név vagy jelszó");
return retVal;
}
try
{
var userDTO_Response = await _userService.Authenticate(userDTO.UserName, userDTO.Password);
if (userDTO_Response != null)
{
if (string.IsNullOrEmpty(userDTO_Response.UserName) == false && userDTO_Response.UserName == userDTO.UserName)
{
retVal.IsSuccess = true;
retVal.Data = userDTO_Response;
Log.Information($"Sikeres azonosítás! {userDTO.UserName}");
}
else
{
var error = $"Nem megfelelő felhasználó vagy jelszó! {userDTO.UserName}";
retVal.IsSuccess = false;
retVal.Errors.Add(error);
Log.Information(error);
}
}
else
{
var error = $"Nem megfelelő felhasználó vagy jelszó! {userDTO.UserName}";
retVal.IsSuccess = false;
retVal.Errors.Add(error);
Log.Information(error);
}
}
catch (Exception ex)
{
Log.Error(ex.Message);
}
return retVal;
}
}
}