public IActionResult Register([FromBody] UserToAuthenticateDto userModel) { var isUsernameUnique = _userRepository.IsUniqueUser(userModel.Username); if (!isUsernameUnique) { return(BadRequest(new { message = "Username already exists!" })); } var userToRegister = _userRepository.Register(userModel.Username, userModel.Password); return(Ok()); }
public IActionResult Authenticate([FromBody] UserToAuthenticateDto userModel) { var userFromDb = _userRepository.Authenticate(userModel.Username, userModel.Password); if (userFromDb == null) { return(BadRequest(new { message = "Username or password is incorrect" })); } var userToReturn = _mapper.Map <UserToReturnDto>(userFromDb); return(Ok(userToReturn)); }