public async Task <IActionResult> Authenticate(AuthenticateRequest model) { AuthenticateResponse response = await _userService.Authenticate(model); if (response == null) { return(BadRequest(new { message = "Username or password is incorrect " })); } return(Ok(response)); }
public async Task <IActionResult> Authenticate([FromBody] UserLoginInputModel model) { var response = await _userAuthService.Authenticate(model); if (response == null) { return(BadRequest(response)); } return(Ok(response)); }
public ActionResult <ReadUserDTO> Authenticate([FromBody] LoginDTO loginDTO) { var response = _userAuthService.Authenticate(loginDTO, ipAddress()); if (response == null) { return(BadRequest(new { message = "Username or password is incorrect" })); } setTokenCookie(response.RefreshToken); return(Ok(response)); }
public async Task <IActionResult> Authenticate([FromBody] AuthenticateModel model) { if (!ModelState.IsValid) { return(BadRequest(ModelState.GetErrorMessages())); } var user = await _userAuthService.Authenticate(model.Email, model.password); if (!user.Success) { return(BadRequest(new { success = false, message = user.Message })); } var tokenHandler = new JwtSecurityTokenHandler(); var key = Encoding.ASCII.GetBytes(_appSettings.Secret); var tokenDescriptor = new SecurityTokenDescriptor { Subject = new ClaimsIdentity(new Claim[] { new Claim(ClaimTypes.Name, user._user.UserId.ToString()), new Claim(ClaimTypes.NameIdentifier, user._user.CompanyId.ToString()) }), Expires = DateTime.UtcNow.AddDays(7), SigningCredentials = new SigningCredentials(new SymmetricSecurityKey(key), SecurityAlgorithms.HmacSha256Signature) }; var token = tokenHandler.CreateToken(tokenDescriptor); var tokenString = tokenHandler.WriteToken(token); var userdata = _mapper.Map <UserModel>(user._user); HttpContext.Session.SetString("JWToken", tokenString); return(Ok(new { success = true, user = userdata, token = tokenString } )); }