Пример #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 = "/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();
 }
Пример #3
0
  @POST
  @Produces(MediaType.APPLICATION_JSON)
  @Path("select")
  public String getUserData(String json) {
    JSONObject jObj = null;
    try {
      jObj = new JSONObject(json);
      Integer userID = Integer.parseInt(jObj.getString("userID"));
      User user = dbManager.getUserbyAccountId(userID);

      jObj.put("middle_name", user.getMiddleName());
      jObj.put("last_name", user.getLastName());
      jObj.put("street", user.getStreet());
      jObj.put("house_number", user.getHouseNumber());
      jObj.put("city", user.getCity());
      jObj.put("postal_code", user.getPostalCode());
      jObj.put("country", user.getCountry());
      Account account = user.getAccountId();
      jObj.put("email", account.getUserName());

    } catch (JSONException ex) {
      Logger.getLogger(ChangeAccount.class.getName()).log(Level.SEVERE, null, ex);
    } finally {
      return jObj.toString();
    }
  }
Пример #4
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 "";
   }
 }
Пример #5
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;
 }
Пример #6
0
  @POST
  @Path("update")
  @Consumes(MediaType.APPLICATION_JSON)
  public String updateUserData(String json)
      throws JSONException, IOException, NonexistentEntityException, RollbackFailureException,
          Exception {
    JSONObject jObj = new JSONObject(json);
    try {
      int userId = jObj.getInt("userID");
      String email = jObj.getString("email");
      String password = jObj.getString("password");

      String middleName = jObj.optString("middle_name");
      String lastName = jObj.optString("last_name");
      String street = jObj.optString("street");
      String houseNumber = jObj.optString("house_number");
      String postalCode = jObj.optString("postal_code");
      String city = jObj.optString("city");
      String country = jObj.optString("country");

      Account account = dbManager.findById(Account.class, userId);
      account.setUserName(email);
      account.setPassword(password);
      User user = account.getUser();
      user.setCity(city);
      user.setCountry(country);
      user.setHouseNumber(houseNumber);
      user.setLastName(lastName);
      user.setPostalCode(postalCode);
      user.setStreet(street);

      if (password != null && !password.isEmpty()) {
        dbManager.save(account);
      }
      dbManager.save(user);

    } catch (Exception ex) {
      Logger.getLogger(ChangeAccount.class.getName()).log(Level.SEVERE, null, ex);
      return jObj.put("result", true).toString();
    }
    jObj = new JSONObject();

    return jObj.put("result", true).toString();
  }
Пример #7
0
 @RequestMapping(value = "/getPoints", method = RequestMethod.GET)
 @ResponseBody
 public String getPoints(HttpServletResponse response, Principal principal) throws IOException {
   User user = userService.getUserByPseudo(principal.getName());
   return "" + user.getPoints();
 }
Пример #8
0
 @Transactional
 public Double getCash(String userName) {
   User user = dao.getUserByName(userName);
   return user.getCash();
 }