@Transactional(rollbackForClassName = "java.lang.Exception")
  @RequestMapping(
      value = "updateAccount",
      params = {"delete"},
      method = RequestMethod.POST)
  public ModelAndView deleteAccount(@Valid User user, HttpServletRequest request)
      throws IllegalRequestException {

    Integer authUserId = userCookieGenerator.getUserId(request);
    if (!authUserId.equals(user.getId())) throw new IllegalRequestException();

    userProfileMapper.deleteProfile(authUserId);
    userMasterMapper.deleteUser(authUserId);

    ConnectionRepository connectionRepository =
        usersConnectionRepository.createConnectionRepository(authUserId.toString());
    Connection connection = connectionRepository.findPrimaryConnection(Facebook.class);
    if (connection != null) connectionRepository.removeConnection(connection.getKey());
    connection = connectionRepository.findPrimaryConnection(Twitter.class);
    if (connection != null) connectionRepository.removeConnection(connection.getKey());

    ModelAndView modelAndView = new ModelAndView();
    modelAndView.setViewName("forward:logout");
    return modelAndView;
  }
  @Transactional(rollbackForClassName = "java.lang.Exception")
  @RequestMapping(
      value = "updateAccount",
      params = {"update"},
      method = RequestMethod.POST)
  public ModelAndView updateAccount(
      @Valid User user, BindingResult result, HttpServletRequest request)
      throws IllegalRequestException {

    if (!userCookieGenerator.getUserId(request).equals(user.getId()))
      throw new IllegalRequestException();

    try {
      if (result.hasErrors()) {
        throw new InvalidInputException();
      }
      if (!user.validForEditingAccount()) {
        Map<String, String> rejectValueMap = user.getRejectValueMap();
        for (Map.Entry<String, String> entry : rejectValueMap.entrySet()) {
          result.rejectValue(entry.getKey(), entry.getValue());
        }
        throw new InvalidInputException();
      }
      if (userMasterMapper.countUserByEmail(user.getEmail(), user.getId()) != 0) {
        result.rejectValue("email", "error.email.exists");
        throw new InvalidInputException();
      }
    } catch (InvalidInputException e) {
      ModelAndView modelAndView = new ModelAndView();
      modelAndView.addObject("activeTab", "account");
      modelAndView.addObject("user", user);
      modelAndView.setViewName("user/edit");
      return modelAndView;
    }

    userMasterMapper.updateAccount(user.getId(), user.getEmail());

    ModelAndView modelAndView = new ModelAndView();
    modelAndView.addObject("activeTab", "account");
    modelAndView.addObject("updated", true);
    modelAndView.setViewName("user/edit");
    return modelAndView;
  }
  @Transactional(rollbackForClassName = "java.lang.Exception")
  @RequestMapping(value = "updateAccount", method = RequestMethod.GET)
  public ModelAndView updateAccount(HttpServletRequest request) throws IllegalRequestException {

    User user = userMasterMapper.getUserById(userCookieGenerator.getUserId(request));
    if (user == null) throw new IllegalRequestException();

    ModelAndView modelAndView = new ModelAndView();
    modelAndView.addObject("user", user);
    modelAndView.setViewName("user/editAccount");
    return modelAndView;
  }