public IActionResult Post([FromBody] UserCredentialsForm user) { var userResult = _authenticationHelper.Authenticate(user.Email.ToUnescapeDataString(), user.Password.ToUnescapeDataString()); if (userResult is null) { return(Ok(new ErrorResult { Error = "Invalid user or credentials" })); } return(Ok(userResult)); }
public void CanAuthenticate() { // Arrange var controller = new AuthController(GetMockRepo()); var user = new UserCredentialsForm { Email = EmailAdmin, Password = PassAdmin }; // Act var result = controller.Post(user) as OkObjectResult; // Assert Assert.IsType <OkObjectResult>(result); Assert.IsType <UserResultForm>(result.Value); }
public void CannotAuthenticate() { // Arrange var controller = new AuthController(GetMockRepo()); var user = new UserCredentialsForm { Email = "Bad User", Password = "******" }; // Act var result = controller.Post(user) as OkObjectResult; // Assert Assert.IsType <OkObjectResult>(result); Assert.IsType <ErrorResult>(result.Value); Assert.False(string.IsNullOrWhiteSpace(((ErrorResult)result.Value).Error)); }
public IActionResult Post([FromBody] UserCredentialsForm user) { return(StatusCode(StatusCodes.Status500InternalServerError)); }