@RequestMapping(value = "/editUser", method = RequestMethod.POST) public @ResponseBody String editUserPost( @ModelAttribute("user") User user, BindingResult result, Principal principal, @RequestParam String password, @RequestParam String name, @RequestParam String surname, @RequestParam String mailAddress, @RequestParam String img, @RequestParam int id) { String returnText; if (!result.hasErrors()) { User u = userService.getUser(id); if (!"".equals(name)) u.setName(name); if (!"".equals(surname)) u.setSurname(surname); if (!"".equals(img)) u.setImg(img); if (!"".equals(mailAddress)) u.setMailAddress(mailAddress); if (!"".equals(password)) { u.setPassword(password); userService.updateUser(u); } else { userService.updateUserByAdmin(u); } returnText = "Your edit was successful"; } else { returnText = "Sorry, an error has occur..."; } return returnText; }
@RequestMapping(value = "/add", method = RequestMethod.POST) @ResponseBody public String add(HttpServletResponse response, Principal principal, @RequestParam int points) throws IOException { User user = userService.getUserByPseudo(principal.getName()); user.setPoints(user.getPoints() + points); userService.updateUserByAdmin(user); return "" + user.getPoints(); }