Example #1
0
  @GET
  @Path("/mylogin")
  @Produces(MediaType.APPLICATION_JSON)
  public Response editUser(@CookieParam(value = "name") String uid) {

    UserDAO userDAO = Factory.getInstance().getUserDAO();
    SessionDAO sessionDAO = Factory.getInstance().getSessionDAO();

    UserEntity user = userDAO.getById(sessionDAO.haveKey(uid));
    UserDTO userDTO = new UserDTO(user);
    if (user == null) {

      return Response.ok().status(400).build();
    }
    System.out.println(user.getLogin());

    return Response.ok().entity(userDTO).build();
  }
  @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));
      }
    }
  }