예제 #1
0
        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)));
            }
        }
예제 #2
0
        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));
        }
예제 #3
0
        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));
        }