public Task <Result <AuthenticateResponseModel> > Authenticate(AuthenticateRequestModel model, string ipAddress) { try { var user = _userLoginService.Authenticate(model); if (user == null) { return(Task.FromResult(ResultMessage <AuthenticateResponseModel> .Error(Constants.NotFoundUserLogin))); } var employee = _employeeService.GetEmployee(user.FkEmpId ?? 0); var jwtToken = GenerateJwtToken(user); var refreshToken = GenerateRefreshToken(ipAddress, model.Username); _refreshTokenService.CreateRefreshToken(refreshToken); var resultAuthentication = new AuthenticateResponseModel(employee, jwtToken, refreshToken.Token, user.Role); return(Task.FromResult(ResultMessage <AuthenticateResponseModel> .Success(resultAuthentication))); } catch (Exception ex) { return(Task.FromResult(ResultMessage <AuthenticateResponseModel> .ExceptionError(ex))); } }
public IActionResult Authenticate(AuthenticateRequest model) { var response = _userService.Authenticate(model); if (response == null) { return(BadRequest(new { message = "Username or password is incorrect" })); } return(Ok(response)); }
public IActionResult Authenticate([FromBody] User userParam) { var user = _userLoginService.Authenticate(userParam.Username, userParam.Password); if (user == null) { return(BadRequest(new { message = "Username or password is incorrect" })); } return(Ok(user)); }