Beispiel #1
0
 @RequestMapping("/data/o_revert.do")
 public String revert(
     String filename,
     String db,
     ModelMap model,
     HttpServletRequest request,
     HttpServletResponse response)
     throws IOException {
   String backpath = realPathResolver.get(Constants.BACKUP_PATH);
   String backFilePath = backpath + SLASH + filename;
   String sql = readFile(backFilePath);
   // 还原暂时没做备份提示。
   dataBackMng.executeSQL("use " + SPLIT + db + SPLIT + BR);
   dataBackMng.executeSQL(sql);
   // 若db发生变化,需要处理jdbc
   try {
     String defaultCatalog = dataBackMng.getDefaultCatalog();
     if (!defaultCatalog.equals(db)) {
       String dbXmlPath = realPathResolver.get(dbXmlFileName);
       dbXml(dbXmlPath, defaultCatalog, db);
     }
   } catch (Exception e) {
     WebErrors errors = WebErrors.create(request);
     errors.addErrorCode("db.revert.error");
     errors.addErrorString(e.getMessage());
     if (errors.hasErrors()) {
       return errors.showErrorPage(model);
     }
   }
   // 需要重启web服务器,可能会存在bug
   session.setAttribute(request, response, AUTH_KEY, null);
   request.getSession().invalidate();
   return "login";
 }
Beispiel #2
0
 @RequestMapping(value = "/data/o_export.do")
 public String exportSubmit(
     String[] names, ModelMap model, HttpServletRequest request, HttpServletResponse response)
     throws UnsupportedEncodingException {
   if (validate(names, request)) {
     WebErrors errors = WebErrors.create(request);
     errors.addErrorCode(INVALID_PARAM);
     return errors.showErrorPage(model);
   }
   String backName = "back";
   if (names[0] != null) {
     backName =
         names[0].substring(
             names[0].indexOf(Constants.BACKUP_PATH) + Constants.BACKUP_PATH.length() + 1);
   }
   List<FileEntry> fileEntrys = new ArrayList<FileEntry>();
   response.setContentType("application/x-download;charset=UTF-8");
   response.addHeader("Content-disposition", "filename=" + backName + ".zip");
   for (String filename : names) {
     File file = new File(realPathResolver.get(filename));
     fileEntrys.add(new FileEntry("", "", file));
   }
   try {
     // 模板一般都在windows下编辑,所以默认编码为GBK
     Zipper.zip(response.getOutputStream(), fileEntrys, "GBK");
   } catch (IOException e) {
     log.error("export db error!", e);
   }
   return null;
 }
Beispiel #3
0
 private WebErrors validateSubmit(
     String username,
     String email,
     String password,
     String captcha,
     CmsSite site,
     HttpServletRequest request,
     HttpServletResponse response) {
   MemberConfig mcfg = site.getConfig().getMemberConfig();
   WebErrors errors = WebErrors.create(request);
   try {
     if (!imageCaptchaService.validateResponseForID(
         session.getSessionId(request, response), captcha)) {
       errors.addErrorCode("error.invalidCaptcha");
       return errors;
     }
   } catch (CaptchaServiceException e) {
     errors.addErrorCode("error.exceptionCaptcha");
     log.warn("", e);
     return errors;
   }
   if (errors.ifOutOfLength(username, "username", mcfg.getUsernameMinLen(), 100)) {
     return errors;
   }
   if (errors.ifOutOfLength(password, "password", mcfg.getPasswordMinLen(), 100)) {
     return errors;
   }
   if (errors.ifMaxLength(email, "email", 100)) {
     return errors;
   }
   // 保留字检查不通过,返回false。
   if (!mcfg.checkUsernameReserved(username)) {
     errors.addErrorCode("error.usernameReserved");
     return errors;
   }
   // 用户名存在,返回false。
   if (unifiedUserMng.usernameExist(username)) {
     errors.addErrorCode("error.usernameExist");
     return errors;
   }
   return errors;
 }
Beispiel #4
0
 private WebErrors validatePasswordSubmit(
     Integer id, String origPwd, String newPwd, String email, HttpServletRequest request) {
   WebErrors errors = WebErrors.create(request);
   if (errors.ifBlank(origPwd, "origPwd", 100)) {
     return errors;
   }
   if (errors.ifMaxLength(newPwd, "newPwd", 100)) {
     return errors;
   }
   if (errors.ifMaxLength(email, "email", 100)) {
     return errors;
   }
   if (!cmsUserMng.isPasswordValid(id, origPwd)) {
     errors.addErrorCode("member.origPwdInvalid");
     return errors;
   }
   return errors;
 }