コード例 #1
0
 @Override
 public void execute(HttpServletRequest request, HttpServletResponse response)
     throws ServletException, IOException {
   String email = request.getParameter("email");
   String password = request.getParameter("password");
   String confirmPassword = request.getParameter("confirm_password");
   HttpSession session = request.getSession();
   ResourceBundle bundle = (ResourceBundle) session.getAttribute("bundle");
   if (password.equals(confirmPassword)) {
     User user = service.getByEmail(email);
     if (user != null) {
       user.setPassword(new HashMD5().hash(password));
       service.update(user.getId(), user);
       session.setAttribute(
           "toastr_notification",
           "success|" + UTF8.encoding(bundle.getString("restore" + ".notification.success")));
       response.sendRedirect(ServerLocationUtils.getServerPath(request) + "/login");
       return;
     }
     response.sendError(HttpServletResponse.SC_NOT_FOUND);
   } else {
     request.setAttribute("email", email);
     request.setAttribute(
         "toastr_notification",
         "error|" + UTF8.encoding(bundle.getString("restore" + ".notification.match")));
     request.getRequestDispatcher("jsp/user/pwrestore_newpw.jsp").forward(request, response);
   }
 }
コード例 #2
0
  @Override
  public void execute(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {

    HttpSession session = request.getSession();
    ResourceBundle bundle = (ResourceBundle) session.getAttribute("bundle");

    String jsonError = "";
    ServletContext context = request.getSession().getServletContext();
    response.setContentType("application/json");

    try {
      if (ServletFileUpload.isMultipartContent(request)) {
        String fileName;
        String filePath;
        FileType.Type type;
        List<FileItem> multiparts =
            new ServletFileUpload(new DiskFileItemFactory()).parseRequest(request);
        for (FileItem item : multiparts) {
          if (!item.isFormField()) {
            fileName = new File(item.getName()).getName();
            type = FileType.getType(fileName);
            if (type != null) {
              filePath = context.getRealPath(type.getPath());
              SecureRandom random = new SecureRandom();
              fileName =
                  new BigInteger(130, random).toString(32) + FileType.parseFileFormat(fileName);
              item.write(new File(filePath + File.separator + fileName));
              request
                  .getSession()
                  .setAttribute(
                      "urlCat",
                      ServerLocationUtils.getServerPath(request) + type.getPath() + "/" + fileName);
              LOG.debug("File uploaded successfully");
              response
                  .getWriter()
                  .print(
                      new JSONObject()
                          .put(
                              "success",
                              UTF8.encoding(bundle.getString("notification.upload.file.success"))));
            } else {
              jsonError = UTF8.encoding(bundle.getString("notification.wrong.file.format"));
            }
          }
        }
      } else {
        jsonError = UTF8.encoding(bundle.getString("notification.request.error"));
      }
    } catch (Exception e) {
      LOG.error(e.getLocalizedMessage(), e);
      jsonError = UTF8.encoding(bundle.getString("notification.upload.file.error"));
    } finally {
      if (!jsonError.isEmpty()) {
        response.getWriter().print(new JSONObject().put("error", jsonError));
      }
    }
  }