public async Task <IActionResult> Login([FromBody] LoginDto customer) { var customerEntity = await _repository.Customer.GetCustomerByEmail(customer.email); if (customerEntity == null) { return(NotFound()); } if (!AuthExtensions.VerifyPasswordHash(customer.password, customerEntity.passwordHash, customerEntity.passwordSalt)) { return(NotFound("Invalid email or password")); } var claims = new List <Claim> { new Claim(ClaimTypes.NameIdentifier, customerEntity.id.ToString()), new Claim(ClaimTypes.Email, customerEntity.email), new Claim(ClaimTypes.Name, customerEntity.name) }; var customerResult = _mapper.Map <CustomerDto>(customerEntity); return(Ok(new { customer = customerResult, token = AuthExtensions.TokenGeneration(claims, _config) })); }
public async Task <IActionResult> Login([FromBody] LoginDto user) { var userEntity = await _repository.User.GetUserByEmail(user.email); if (userEntity == null) { return(NotFound()); } if (!AuthExtensions.VerifyPasswordHash(user.password, userEntity.passwordHash, userEntity.passwordSalt)) { return(NotFound("Invalid email or password")); } var userResult = new UserDto(); var token = string.Empty; this.CreateUserResponse(userEntity, out userResult, out token); var menus = await _repository.RolMenu.GetRolMenusByRolId(userEntity.rolId); var menusResult = _mapper.Map <IEnumerable <RolMenuDto> >(menus) .Select(m => m.Menu); return(Ok(new { user = userResult, menu = menusResult, token, })); }