Пример #1
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");
  }
Пример #2
0
 @RequestMapping(value = "/isEmailWithoutId", method = RequestMethod.GET)
 @ResponseBody
 public String isEmailWithoutId(
     HttpServletResponse response,
     Principal principal,
     @RequestParam int id,
     @RequestParam String mail)
     throws IOException {
   User user = userService.getUserByMail(mail);
   if (user != null) {
     if (user.getId() == id) {
       return "";
     } else {
       return "This email already exists";
     }
   } else {
     return "";
   }
 }