@RequestMapping(value = "/saveFriendsPost/{id}", method = RequestMethod.POST)
  public String saveFriendsPost(
      WallPost wallPost,
      BindingResult result,
      HttpServletRequest request,
      @PathVariable(value = "id") int friendId,
      @RequestParam(value = "holler") MultipartFile file) {
    User postBy = (User) request.getSession().getAttribute("loggedUser");
    User postTo = userService.getUser(friendId);
    wallPost.setPostTo(postTo);
    wallPost.setPostBy(postBy);
    wallPost.setDate(new Date());
    wallPost.setAudioContentType(file.getContentType());
    wallPost.setAudioFileName(file.getOriginalFilename());
    try {
      wallPost.setAudioContent(file.getBytes());
    } catch (IOException e) {
      e.printStackTrace();
    }
    postValidator.validate(wallPost, result);
    if (!result.hasErrors()) {
      log.debug("Saved the wall Post" + wallPost.getPostContent());
      postService.saveNewPost(wallPost);
    }

    if (request.getSession().getAttribute("friend") != null) {
      User friend = (User) request.getSession().getAttribute("friend");
      String id = Integer.toString(friend.getUserId());
      request.getSession().setAttribute("friend", null);
      return "redirect:/friends/showFullProfile/" + id;
    } else {
      return "redirect:/posts";
    }
  }
  public void validate(Object obj, Errors errors) {
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "loginName", "required.login.name");
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "password", "required.password");

    LoginCommand loginCmd = (LoginCommand) obj;

    User user2 = userManager.getUserByLoginName(loginCmd.getLoginName());

    if (user2 == null) {
      errors.rejectValue("loginName", "incorrect.login.name");
    } else if (!loginCmd.getPassword().equals(user2.getPassword())) {
      errors.rejectValue("password", "incorrect.password");
    }
  }
Esempio n. 3
0
  public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
      throws IOException, ServletException {

    HttpSession session = ((HttpServletRequest) request).getSession(false);
    User user = (User) session.getAttribute("user");
    FoodVotingService foodVotingService = new FoodVotingService();
    if (!foodVotingService.votingAccess(user)) {
      if (user.isAdmin()) {
        RequestDispatcher requestDispatcher =
            request.getRequestDispatcher("WEB-INF/jsp/foodvoting/result.jsp");
        requestDispatcher.forward(request, response);
      } else {

        RequestDispatcher requestDispatcher =
            request.getRequestDispatcher("WEB-INF/jsp/foodvoting/success.jsp");
        requestDispatcher.forward(request, response);
      }
    }
    chain.doFilter(request, response);
  }
 @Test
 public void testGetUser() {
   User user = userDao.getUser(1);
   Assert.assertEquals(user.getLoginName(), "saima");
 }