@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(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)); } } }