示例#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());
 }
示例#2
0
  public void doPost(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    request.setCharacterEncoding("utf-8");
    response.setContentType("text/html;charset=utf-8");
    boolean isAccessed = SessionFilter.sessionCheck(request, response);
    if (isAccessed == false) {
      response.sendRedirect(request.getContextPath() + "/login.jsp");
    }
    // 管理员
    boolean isAdmin = AdminUtils.adminCheck(request, response);
    if (isAdmin == false) {
      return;
    }
    System.out.println(request.getParameter("pageCode") + ",,,");
    Integer pageCode = Integer.parseInt(request.getParameter("pageCode"));
    if (pageCode == null) {
      return;
    }
    pageCode = (pageCode - 1) * UserDao.PAGESIZE;
    String jsonStr = "";
    PrintWriter out = null;

    // 依赖UserServlet
    UserService userService = new UserService();
    //		User user=(User)request.getSession().getAttribute("sessionUser");
    //		{"res":0或1,"user":[{"account":"","name":"","phone":"","email":""},{}]}
    //		if(user.getType() != AdminUtils.ADMINTYPE) {
    //			jsonStr =
    // "{\"res\":1,\"user\":[{\"account\":null,\"name\":null,\"phone\":null,\"email\":null}]}";
    //		} else {

    // json
    ArrayList<User> users = userService.findUsers(pageCode);
    if (users.size() == 0) {
      jsonStr =
          "{\"res\":-1,\"user\":[{\"account\":null,\"name\":null,\"phone\":null,\"email\":null}]}";
    } else {
      jsonStr = "{\"res\":0,\"user\":[";
      for (User user2 : users) {
        String str =
            "{\"acounnt\":\""
                + user2.getAccount()
                + "\",\"username\":\""
                + user2.getUsername()
                + "\",\"phone\":\""
                + user2.getPhone()
                + "\",\"email\":\""
                + user2.getEmail()
                + "\",\"type\":"
                + user2.getType()
                + "},";
        jsonStr += str;
      }
      jsonStr = jsonStr.substring(0, jsonStr.length() - 1);
      jsonStr += "]}";
    }
    //		}
    //			jsonStr = new String(jsonStr.getBytes("ISO-8859-1"), "utf-8");
    JsonUtils.writeJson(response, jsonStr);
  }
示例#3
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;
 }
示例#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");
  }
示例#5
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();
 }
示例#6
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;
 }
示例#7
0
 @RequestMapping(value = "/index", method = RequestMethod.GET)
 public ModelAndView index(Principal principal) {
   User user = userService.getUserByPseudo(principal.getName());
   ModelAndView mav = new ModelAndView("user/games/index");
   mav.addObject("user", user);
   return mav;
 }
示例#8
0
 @RequestMapping(value = "/editUser", method = RequestMethod.GET)
 public ModelAndView editUserGet(
     @ModelAttribute("user") User user, Principal principal, BindingResult result) {
   ModelAndView mav = new ModelAndView("user/editUser");
   mav.addObject("user", userService.getUserByPseudo(principal.getName()));
   return mav;
 }
示例#9
0
 // Game
 @RequestMapping(value = "/keyboard", method = RequestMethod.GET)
 public ModelAndView keyboard(Principal principal) {
   User user = userService.getUserByPseudo(principal.getName());
   ModelAndView mav = new ModelAndView("user/games/piano");
   mav.addObject("keys", keyboardService.liste());
   mav.addObject("user", user);
   return mav;
 }
示例#10
0
 @PUT
 public boolean updateUser(
     @QueryParam("username") String username,
     @QueryParam("password") String password,
     @QueryParam("description") String description) {
   User user = new User();
   user.setUsername(username);
   user.setPassword(password);
   user.setDescription(description);
   return userService.updateUser(user);
 }
示例#11
0
 @RequestMapping(patterns = "/doRegist", method = RequestMethod.POST)
 public String doRegist(HttpServletRequest request, HttpServletResponse response) {
   User user = null;
   try {
     XForm userRegistForm = XFormLoader.newInstance(request, UserForm.class);
     user = XFormConverter.cast(userRegistForm, User.class);
   } catch (XFormCastException e) {
     return "out:" + e.getMessage();
   }
   try {
     userService.add(user);
     return "out:success";
   } catch (Exception e) {
     return "out:" + e.getMessage();
   }
 }
示例#12
0
 @RequestMapping(patterns = "/doLogin", method = RequestMethod.POST)
 public String doLogin(HttpServletRequest request, HttpServletResponse response) {
   User user;
   try {
     XForm userLoginForm = XFormLoader.newInstance(request, UserForm.class);
     user = XFormConverter.cast(userLoginForm, User.class);
   } catch (XFormCastException e) {
     return "redirect:/user/login?note=invalid form found.";
   }
   try {
     if ((user = userService.get(user)) == null) {
       return "redirect:/user/login?note=illegal identity.";
     }
     request.getSession().setAttribute("user", user);
     return "redirect:/friend/list";
   } catch (Exception e) {
     return "redirect:/user/login?note=" + e.getMessage();
   }
 }
示例#13
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 "";
   }
 }
示例#14
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();
 }