Egy kis authentikáció
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user