示例#1
0
 @POST
 @Path("{userId}/follow/{followUserId}")
 public Response follow(
     @PathParam("userId") final String userId,
     @PathParam("followUserId") final String followUserId) {
   userDao.createFollowingRelation(userDao.getUser(userId), userDao.getUser(followUserId));
   return Response.ok().build();
 }
示例#2
0
 @POST
 @Path("{userId}/friend/{friendUserId}")
 public Response addFriend(
     @PathParam("userId") final String userId,
     @PathParam("friendUserId") final String friendUserId) {
   userDao.createFriendRelationWithPending(userDao.getUser(userId), userDao.getUser(friendUserId));
   return Response.ok().build();
   //  return null;
 }
示例#3
0
  @PUT
  @Path("{userId}/friend/{friendUserId}")
  public Response confirmFriend(
      @PathParam("userId") final String userId,
      @PathParam("friendUserId") final String friendUserId,
      @QueryParam(STATUS_QPARAM) final String status) {
    if (status.toLowerCase().equals("agreed")) {
      userDao.confirmFriendRelation(userDao.getUser(userId), userDao.getUser(friendUserId));
      // TODO:notification to user about acceptance

    } else if (status.toLowerCase().equals("cancel")) {
      userDao.deleteFriendRequest(userId, friendUserId, Constants.FRIEND_REQUEST_CANCEL_DELETE);
    }
    return Response.ok().build();
  }
示例#4
0
 @GET
 @Path("{userId}")
 public Response getUser(@PathParam("userId") final String userId) {
   User user = userDao.getUser(userId);
   com.campusconnect.neo4j.types.web.User returnUser = mapUserNeo4jToWeb(user);
   return Response.ok().entity(returnUser).build();
 }
 /** Test of getUser method, of class UserDao. */
 @Ignore
 public void testGetUser() {
   System.out.println("getUser");
   String id = "";
   UserDao instance = new UserDaoImpl();
   User expResult = null;
   User result = instance.getUser(id);
   assertEquals(expResult, result);
   // TODO review the generated test code and remove the default call to fail.
   fail("The test case is a prototype.");
 }
示例#6
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();
 }
示例#7
0
  @POST
  @Path("{userId}/addresses")
  public Response addAddress(
      @PathParam("userId") String userId,
      com.campusconnect.neo4j.types.web.Address addressPayload) {
    Address address = mapAddressWebToNeo4j(addressPayload);
    User user = userDao.getUser(userId);
    // create new address
    Address createdAddress = addressDao.createAddress(address, userId);
    // Link to user
    userDao.addAddressToUser(createdAddress, user);

    com.campusconnect.neo4j.types.web.Address returnAddress = mapAddressNeo4jToWeb(createdAddress);
    return Response.ok().entity(returnAddress).build();
  }
示例#8
0
 @POST
 @Path("{userId}/reminders")
 public Response createReminder(
     Reminder reminder,
     @PathParam("userId") final String userId,
     @QueryParam(REMINDER_ABOUT_QPARM) final String reminderAbout,
     @QueryParam(CREATED_BY_QPARAM) final String createdBy) {
   setReminderCreateProperties(reminder);
   Reminder createdReminder = reminderDao.createReminder(reminder);
   User reminderForUser = userDao.getUser(userId);
   Long currentTime = System.currentTimeMillis();
   ReminderRelationShip reminderRelationShip =
       new ReminderRelationShip(
           createdBy, currentTime, reminderForUser, currentTime, reminderAbout, reminder);
   userDao.setReminder(reminderRelationShip);
   return Response.created(null).entity(createdReminder).build();
 }
示例#9
0
  @Override
  protected void doPost(HttpServletRequest req, HttpServletResponse resp)
      throws ServletException, IOException {

    String login = req.getParameter("login");
    String password = req.getParameter("password");

    boolean accept = false;

    UserDao userDao = new UserDaoJdbcImpl();

    User user = userDao.getUser(login);

    if (user != null) {

      //            try {
      ////                accept = PasswordEncryptionService.authenticate(
      ////                        password,
      ////                        user.getPassword(),
      ////                        user.getSalt() );
      //
      //            } catch (NoSuchAlgorithmException | InvalidKeySpecException e) {
      //                e.printStackTrace();
      //            }

    }

    if (accept) {

      req.getSession().setAttribute("user_id", user.getId());
      req.getSession().setAttribute("user_role", user.getRole());
      resp.sendRedirect("/secured");

    } else {

      req.getSession().setAttribute("error", "error");
      req.getRequestDispatcher("/WEB-INF/jsp/login.jsp").forward(req, resp);
    }
  }
示例#10
0
 @POST
 @Path("{userId}/goodreads/synch")
 public Response synchGoodreads(@PathParam("userId") final String userId) throws Exception {
   initiateGoodreadsSynch(userDao.getUser(userId));
   return Response.ok().build();
 }
示例#11
0
 @Override
 public User getUser(String username) {
   return userdao.getUser(username);
 }
  @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"));
    }
  }
 @Test
 public void testGetUser() {
   User user = userDao.getUser(1);
   Assert.assertEquals(user.getLoginName(), "saima");
 }