@RequestMapping(method = RequestMethod.POST)
  @ResponseStatus(HttpStatus.CREATED)
  public @ResponseBody Object apiRegister(
      @Valid UserEntity userEntity, BindingResult bindingResult, HttpServletRequest request)
      throws BindException, IOException {
    if (bindingResult.hasErrors()) {

      return "NotAllRequiredFields";
    } else {
      if (userService.checkIfExist(userEntity.getEmail())) {
        return "EmailAlreadyTaken";
      } else {
        ObjectMapper mapper = new ObjectMapper();

        return mapper.writeValueAsString(
            userService.createNewUserAndAuthenticate(userEntity, request, false));
      }
    }
  }
  @RequestMapping(value = "/check", method = RequestMethod.POST)
  @ResponseBody
  public void checkIfAlreadyRegistred(
      @RequestParam("email") String email, HttpServletResponse response) throws IOException {
    response.setCharacterEncoding("UTF-8");
    response.setContentType("text/html");

    if (userService.checkIfExist(email)) {
      response.getWriter().write("alreadyExists");
    } else {
      response.getWriter().write("available");
    }
  }
  @RequestMapping(value = "/{uid}", method = RequestMethod.GET, produces = "text/html")
  public String getUserById(@PathVariable Integer uid, Map<String, Object> model) {

    model.put("userEntity", userService.getById(uid));
    return "showUserProfile";
  }
  @RequestMapping(method = RequestMethod.GET)
  public String listUsers(Map<String, Object> model) {

    model.put("userList", userService.getAllUsers());
    return "userListView";
  }