public async Task Authenticate_ValidUserNameAndPassword() { UserDto user = await _userService.AuthenticateUser("Onkar", "123"); Assert.IsTrue(user.UserId == 1); Assert.AreEqual(1, user.UserId); }
public async Task <IActionResult> Login(LoginModel loginModel) { _logger.LogInformation("Started : Logging In."); UserDto userDto = await _userService.AuthenticateUser(loginModel.UserName, loginModel.Password); if (userDto != null) { // On Successful authentication, generate jwt token. string token = JwtTokenHelper.GenerateJwtToken(userDto, _appSettings); return(Ok( new ApiResponse <string> { IsSuccess = true, Result = token, Message = "Authentication successful." })); } else { return(BadRequest( new ApiResponse <string> { IsSuccess = false, Result = "Authentication failed.", Message = "Username or password is incorrect." })); } }