예제 #1
0
  @POST
  public Response createUser(
      @QueryParam(ACCESS_TOKEN_QPARAM) final String accessToken,
      final com.campusconnect.neo4j.types.web.User userPayload)
      throws URISyntaxException {

    StringBuffer validateUserDataMessage = Validator.validateUserObject(userPayload);
    if (null != validateUserDataMessage) {
      throw new InvalidInputDataException(INVALId_ARGMENTS, validateUserDataMessage.toString());
    }

    User user = mapUserWebToNeo4j(userPayload);

    if (user.getEmail() != null) {
      User existingUser = userDao.getUserByEmail(user.getEmail());
      if (null != existingUser) {
        if (existingUser.getFbId() == null && user.getFbId() != null) {
          existingUser.setFbId(user.getFbId());
          existingUser = userDao.updateUser(existingUser.getId(), existingUser);
        }
        if (existingUser.getGoogleId() == null && user.getGoogleId() != null) {
          existingUser.setGoogleId(user.getGoogleId());
          existingUser = userDao.updateUser(existingUser.getId(), existingUser);
        }
        com.campusconnect.neo4j.types.web.User returnUser = mapUserNeo4jToWeb(existingUser);
        return Response.created(new URI("/users/" + returnUser.getId())).entity(returnUser).build();
      }
    }
    if (user.getFbId() != null) {
      User existingUser = userDao.getUserByFbId(user.getFbId());
      if (null != existingUser) {
        com.campusconnect.neo4j.types.web.User returnUser = mapUserNeo4jToWeb(existingUser);
        return Response.created(new URI("/users/" + returnUser.getId())).entity(returnUser).build();
      }
    }

    if (user.getGoogleId() != null) {
      User existingUser = userDao.getUserByGoogleId(user.getGoogleId());
      if (null != existingUser) {
        com.campusconnect.neo4j.types.web.User returnUser = mapUserNeo4jToWeb(existingUser);
        return Response.created(new URI("/users/" + returnUser.getId())).entity(returnUser).build();
      }
    }
    addPropertiesForCreate(user);
    User createdUser = userDao.createUser(user, accessToken);
    com.campusconnect.neo4j.types.web.User returnUser = mapUserNeo4jToWeb(createdUser);
    return Response.created(new URI("/users/" + returnUser.getId())).entity(returnUser).build();
  }
예제 #2
0
 @PUT
 @Path("{userId}")
 public Response updateUser(
     @PathParam("userId") final String userId,
     com.campusconnect.neo4j.types.web.User userPayload) {
   User user = mapUserWebToNeo4j(userPayload);
   user.setLastModifiedDate(System.currentTimeMillis());
   User updatedUser = userDao.updateUser(userId, user);
   com.campusconnect.neo4j.types.web.User returnUser = mapUserNeo4jToWeb(updatedUser);
   return Response.ok().entity(returnUser).build();
 }
예제 #3
0
 @PUT
 @Path("{userId}/fields")
 public Response updateUserFields(@PathParam("userId") final String userId, Fields fields)
     throws Exception {
   // todo: validate passed fields are valid or not
   User user = userDao.getUser(userId);
   setUpdatedFields(user, fields);
   user.setLastModifiedDate(System.currentTimeMillis());
   User updatedUser = userDao.updateUser(userId, user);
   checkWhetherSynchIsNeeded(updatedUser, fields);
   com.campusconnect.neo4j.types.web.User returnUser = mapUserNeo4jToWeb(updatedUser);
   return Response.ok().entity(returnUser).build();
 }
예제 #4
0
 private void updateUserGoodReadsSynchToInprogress(User user) {
   user.setGoodReadsSynchStatus(IN_PROGRESS_GREADS_STATUS);
   userDao.updateUser(user.getId(), user);
 }
  @RequestMapping(method = RequestMethod.POST)
  public ModelAndView edit(
      HttpServletRequest request,
      @Valid @ModelAttribute("form") EditRegisterRequest form,
      Errors errors)
      throws Exception {
    Template tmpl = Template.getTemplate(request);

    if (!tmpl.isSessionAuthorized()) {
      throw new AccessViolationException("Not authorized");
    }

    String nick = tmpl.getNick();
    String password = Strings.emptyToNull(form.getPassword());

    if (password != null && password.equalsIgnoreCase(nick)) {
      errors.reject(null, "пароль не может совпадать с логином");
    }

    InternetAddress mail = null;

    if (!Strings.isNullOrEmpty(form.getEmail())) {
      try {
        mail = new InternetAddress(form.getEmail());
      } catch (AddressException e) {
        errors.rejectValue("email", null, "Некорректный e-mail: " + e.getMessage());
      }
    }

    String url = null;

    if (!Strings.isNullOrEmpty(form.getUrl())) {
      url = URLUtil.fixURL(form.getUrl());
    }

    String name = Strings.emptyToNull(form.getName());

    if (name != null) {
      name = StringUtil.escapeHtml(name);
    }

    String town = null;

    if (!Strings.isNullOrEmpty(form.getTown())) {
      town = StringUtil.escapeHtml(form.getTown());
    }

    String info = null;

    if (!Strings.isNullOrEmpty(form.getInfo())) {
      info = StringUtil.escapeHtml(form.getInfo());
    }

    ipBlockDao.checkBlockIP(request.getRemoteAddr(), errors, tmpl.getCurrentUser());

    boolean emailChanged = false;

    User user = userDao.getUser(nick);

    if (Strings.isNullOrEmpty(form.getOldpass())) {
      errors.rejectValue("oldpass", null, "Для изменения регистрации нужен ваш пароль");
    } else if (!user.matchPassword(form.getOldpass())) {
      errors.rejectValue("oldpass", null, "Неверный пароль");
    }

    user.checkAnonymous();

    String newEmail = null;

    if (mail != null) {
      if (user.getEmail() != null && user.getEmail().equals(form.getEmail())) {
        newEmail = null;
      } else {
        if (userDao.getByEmail(mail.getAddress(), false) != null) {
          errors.rejectValue("email", null, "такой email уже используется");
        }

        newEmail = mail.getAddress();

        emailChanged = true;
      }
    }

    if (!errors.hasErrors()) {
      userDao.updateUser(user, name, url, newEmail, town, password, info);

      if (emailChanged) {
        emailService.sendEmail(user.getNick(), mail.getAddress(), false);
      }
    } else {
      return new ModelAndView("edit-reg");
    }

    if (emailChanged) {
      String msg =
          "Обновление регистрации прошло успешно. Ожидайте письма с кодом активации смены email.";

      return new ModelAndView("action-done", "message", msg);
    } else {
      return new ModelAndView(new RedirectView("/people/" + nick + "/profile"));
    }
  }