コード例 #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));
      }
    }
  }
コード例 #3
0
  @Override
  public void execute(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {

    String code = request.getParameter("code");
    if (code == null || code.equals("")) {
      throw new RuntimeException("ERROR: Didn't get code parameter in callback.");
    }
    FBConnection fbConnection = new FBConnection();
    String accessToken = fbConnection.getAccessToken(code);

    FBGraph fbGraph = new FBGraph(accessToken);
    String graph = fbGraph.getFBGraph();
    Map<String, String> fbProfileData = fbGraph.getGraphData(graph);

    UserService userService = new UserService();
    User user = userService.getByEmail(fbProfileData.get("email"));

    if (user != null) {
      HttpSession session = request.getSession();
      ResourceBundle bundle = (ResourceBundle) session.getAttribute("bundle");
      switch (user.getState()) {
        case CREATED:
          // Користувач не активний
          request.setAttribute(
              "toastr_notification",
              "warning|" + UTF8.encoding(bundle.getString("login" + ".notification.created")));
          request.getRequestDispatcher("jsp/user/login.jsp").forward(request, response);
          return;
        case BANNED:
          // Користувач забанений
          request.setAttribute(
              "toastr_notification",
              "warning|" + UTF8.encoding(bundle.getString("login" + ".notification.banned")));
          request.getRequestDispatcher("jsp/user/login.jsp").forward(request, response);
          return;
        case ACTIVATED:
          request.getSession().setAttribute("user", user);
          response.sendRedirect("/");
      }
    } else {
      request.getSession().setAttribute("name", fbProfileData.get("first_name"));
      request.getSession().setAttribute("surname", fbProfileData.get("last_name"));
      request.getSession().setAttribute("email", fbProfileData.get("email"));
      response.sendRedirect(ServerResolver.getServerPath(request) + "/register");
    }
  }