Example #1
0
 @RequestMapping(value = "/userpic/upload", method = RequestMethod.POST)
 public String uploadUserPicture(
     @RequestPart("profilePicture") Part userPicrure, Principal principal) throws IOException {
   User user = userService.findUser(principal.getName());
   userService.uploadPicture(userPicrure, user.getId());
   return "redirect:/";
 }
Example #2
0
 @RequestMapping(value = "/signup", method = RequestMethod.POST)
 public String registerUser(@Valid User user, Errors errors, Model model) {
   if (errors.hasErrors()) return "signup";
   if (userService.findUser(user.getUsername()) != null) {
     Alert alert =
         new Alert(
             AlertType.DANGER,
             "Error!",
             "User with name " + user.getUsername() + " already registered");
     model.addAttribute(alert);
     return "signup";
   }
   userService.newUser(user, Role.ROLE_USER);
   return "redirect:/";
 }
Example #3
0
 @RequestMapping(value = "/show/{username}", method = RequestMethod.GET)
 public String showUserPage(
     @PathVariable("username") String username, Model model, Principal principal) {
   User profileuser = userService.findUser(username);
   User user;
   if (principal == null) {
     user = new User();
   } else user = userService.findUser(principal.getName());
   List<Post> postList = postService.findByUsername(username);
   List<User> followersList = userService.findFollowers(username);
   if (followersList == null) followersList = new ArrayList<>();
   model.addAttribute(postList);
   model.addAttribute("profileUser", profileuser);
   model.addAttribute(user);
   model.addAttribute("followersList", followersList);
   return "profile";
 }
Example #4
0
 @RequestMapping(value = "/unfollow", method = RequestMethod.GET)
 @Transactional
 public String unfollowUser(@RequestParam("user") String username, Principal principal) {
   userService.unfollow(principal.getName(), username);
   return "redirect:/";
 }
Example #5
0
 @RequestMapping(value = "/userpic/remove", method = RequestMethod.POST)
 public String removeUserPicture(Principal principal) {
   User user = userService.findUser(principal.getName());
   userService.removePicture(user.getId());
   return "redirect:/";
 }