Egy kis authentikáció
This commit is contained in:
@@ -5,7 +5,7 @@ using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using AutoMapper;
|
||||
using AutoMapper.Configuration.Conventions;
|
||||
using WorkFlowCheck.BL.DTO;
|
||||
using WorkFlowCheck.Common.DTO;
|
||||
using WorkFlowCheck.DL.Entities;
|
||||
|
||||
namespace WorkFlowCheck.BL.Mappings
|
||||
@@ -15,6 +15,9 @@ namespace WorkFlowCheck.BL.Mappings
|
||||
public MapperProfile()
|
||||
{
|
||||
CreateMap<User, UserDTO>();
|
||||
CreateMap<UserDTO, User>()
|
||||
.ForMember(dest => dest.PasswordHash, opt => opt.MapFrom<PasswordHashResolver>());
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
using AutoMapper;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using WorkFlowCheck.Common.DTO;
|
||||
using WorkFlowCheck.Common.Security;
|
||||
using WorkFlowCheck.DL.Entities;
|
||||
|
||||
namespace WorkFlowCheck.BL.Mappings
|
||||
{
|
||||
public class PasswordHashResolver : IValueResolver<UserDTO, User, string>
|
||||
{
|
||||
public string Resolve(UserDTO source, User destination, string destMember, ResolutionContext context)
|
||||
{
|
||||
return PasswordHasher.HashPassword(source.Password);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,12 +3,13 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using WorkFlowCheck.BL.DTO;
|
||||
using WorkFlowCheck.Common.DTO;
|
||||
|
||||
namespace WorkFlowCheck.BL.Services.Interfaces
|
||||
{
|
||||
public interface IUserService
|
||||
{
|
||||
Task<UserDTO> GetUser(int Id);
|
||||
Task<UserDTO> Authenticate(string UserName, string Password);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,9 +6,10 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using WorkFlowCheck.BL.DTO;
|
||||
using WorkFlowCheck.Common.DTO;
|
||||
using WorkFlowCheck.BL.Services.Interfaces;
|
||||
using WorkFlowCheck.DL;
|
||||
using WorkFlowCheck.Common.Security;
|
||||
|
||||
namespace WorkFlowCheck.BL.Services
|
||||
{
|
||||
@@ -39,5 +40,24 @@ namespace WorkFlowCheck.BL.Services
|
||||
}
|
||||
return retVal;
|
||||
}
|
||||
|
||||
public async Task<UserDTO> Authenticate(string userName, string password)
|
||||
{
|
||||
var retVal = new UserDTO();
|
||||
|
||||
try
|
||||
{
|
||||
var user = await _dbContext.Users.Where(w => w.UserName == userName).FirstOrDefaultAsync();
|
||||
if (user != null && PasswordHasher.VerifyPassword(user.PasswordHash, password))
|
||||
{
|
||||
retVal = _mapper.Map<UserDTO>(user);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error(ex.Message);
|
||||
}
|
||||
return retVal;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\WorkFlowCheck.Common\WorkFlowCheck.Common.csproj" />
|
||||
<ProjectReference Include="..\WorkFlowCheck.DL\WorkFlowCheck.DL.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user