Ejemplo n.º 1
0
 @DELETE
 public boolean deleteUser(
     @QueryParam("username") String username, @QueryParam("password") String password) {
   User user = userService.getUser(username, password);
   if (user == null) return false;
   return userService.deleteUser(user.getUid());
 }
Ejemplo n.º 2
0
 @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;
 }
Ejemplo n.º 3
0
 @GET
 public User getUser(
     @QueryParam("username") String username, @QueryParam("password") String password) {
   User user = userService.getUser(username, password);
   System.out.println(user.getDescription());
   return user;
 }
Ejemplo n.º 4
0
  // MAJ d'utilisateur
  @RequestMapping(value = "/updateUser", method = RequestMethod.POST)
  public ModelAndView update(
      @ModelAttribute("user") User user, BindingResult result, Principal principal) {
    int userId = userService.getUserByPseudo(principal.getName()).getId();
    // Utilisateur avec le meme id
    user.setId(userId);
    User uSameId = userService.getUser(user.getId());
    // Utilisateur avec le meme pseudo
    User uSamePseudo = userService.getUserByPseudo(user.getPseudo());
    // Utilisateur avec le meme email
    User uSameEmail = userService.getUserByMail(user.getMailAddress());

    UserMethod methods = new UserMethod();
    String msg = methods.canUpdate(user, uSameId, uSamePseudo, uSameEmail);

    if (msg.equals("")) {
      user.setId(userId);
      userService.updateUser(user);
    } else {
      ModelAndView mav = new ModelAndView("user/editUser");
      mav.addObject("error", msg);
      return mav;
    }

    return new ModelAndView("redirect:/user/index.html");
  }