Exemple #1
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;
 }
Exemple #2
0
 @RequestMapping(value = "/register.jspx", method = RequestMethod.POST)
 public String submit(
     String username,
     String email,
     String password,
     CmsUserExt userExt,
     String captcha,
     String nextUrl,
     HttpServletRequest request,
     HttpServletResponse response,
     ModelMap model)
     throws IOException {
   CmsSite site = CmsUtils.getSite(request);
   WebErrors errors = validateSubmit(username, email, password, captcha, site, request, response);
   if (errors.hasErrors()) {
     return FrontUtils.showError(request, response, model, errors);
   }
   String ip = RequestUtils.getIpAddr(request);
   cmsUserMng.registerMember(username, email, password, ip, null, userExt);
   log.info("member register success. username={}", username);
   if (!StringUtils.isBlank(nextUrl)) {
     response.sendRedirect(nextUrl);
     return null;
   } else {
     return FrontUtils.showMessage(request, model, "global.success");
   }
 }
Exemple #3
0
 /**
  * 密码修改提交页
  *
  * @param origPwd 原始密码
  * @param newPwd 新密码
  * @param email 邮箱
  * @param nextUrl 下一个页面地址
  * @param request
  * @param response
  * @param model
  * @return
  * @throws IOException
  */
 @RequestMapping(value = "/member/pwd.jspx", method = RequestMethod.POST)
 public String passwordSubmit(
     String origPwd,
     String newPwd,
     String email,
     String nextUrl,
     HttpServletRequest request,
     HttpServletResponse response,
     ModelMap model)
     throws IOException {
   CmsSite site = CmsUtils.getSite(request);
   CmsUser user = CmsUtils.getUser(request);
   FrontUtils.frontData(request, model, site);
   MemberConfig mcfg = site.getConfig().getMemberConfig();
   // 没有开启会员功能
   if (!mcfg.isMemberOn()) {
     return FrontUtils.showMessage(request, model, "member.memberClose");
   }
   if (user == null) {
     return FrontUtils.showLogin(request, model, site);
   }
   WebErrors errors = validatePasswordSubmit(user.getId(), origPwd, newPwd, email, request);
   if (errors.hasErrors()) {
     return FrontUtils.showError(request, response, model, errors);
   }
   cmsUserMng.updatePwdEmail(user.getId(), newPwd, email);
   return FrontUtils.showSuccess(request, model, nextUrl);
 }
 private WebErrors validateDelete(Integer[] ids, HttpServletRequest request) {
   WebErrors errors = WebErrors.create(request);
   errors.ifEmpty(ids, "ids");
   for (Integer id : ids) {
     vldExist(id, errors);
   }
   return errors;
 }
Exemple #5
0
 private WebErrors validateDelete(String[] names, HttpServletRequest request) {
   WebErrors errors = WebErrors.create(request);
   errors.ifEmpty(names, "names");
   for (String id : names) {
     vldExist(id, errors);
   }
   return errors;
 }
Exemple #6
0
 @RequestMapping("/ftp/v_edit.do")
 public String edit(Integer id, HttpServletRequest request, ModelMap model) {
   WebErrors errors = validateEdit(id, request);
   if (errors.hasErrors()) {
     return errors.showErrorPage(model);
   }
   model.addAttribute("ftp", manager.findById(id));
   return "ftp/edit";
 }
 private boolean vldExist(Integer id, WebErrors errors) {
   if (errors.ifNull(id, "id")) {
     return true;
   }
   CmsModelItem entity = manager.findById(id);
   if (errors.ifNotExist(entity, CmsModelItem.class, id)) {
     return true;
   }
   return false;
 }
 @RequestMapping("/item/v_edit.do")
 public String edit(Integer id, HttpServletRequest request, ModelMap model) {
   WebErrors errors = validateEdit(id, request);
   if (errors.hasErrors()) {
     return errors.showErrorPage(model);
   }
   CmsModelItem item = manager.findById(id);
   model.addAttribute("cmsModelItem", item);
   return "item/edit";
 }
 @RequestMapping("/vote_topic/v_edit.do")
 public String edit(Integer id, Integer pageNo, HttpServletRequest request, ModelMap model) {
   WebErrors errors = validateEdit(id, request);
   if (errors.hasErrors()) {
     return errors.showErrorPage(model);
   }
   model.addAttribute("cmsVoteTopic", manager.findById(id));
   model.addAttribute("pageNo", pageNo);
   return "vote_topic/edit";
 }
Exemple #10
0
 private WebErrors validateDelete(Integer[] ids, HttpServletRequest request) {
   WebErrors errors = WebErrors.create(request);
   CmsSite site = CmsUtils.getSite(request);
   if (errors.ifEmpty(ids, "ids")) {
     return errors;
   }
   for (Integer id : ids) {
     vldExist(id, site.getId(), errors);
   }
   return errors;
 }
Exemple #11
0
 @RequestMapping("/ftp/o_save.do")
 public String save(Ftp bean, HttpServletRequest request, ModelMap model) {
   WebErrors errors = validateSave(bean, request);
   if (errors.hasErrors()) {
     return errors.showErrorPage(model);
   }
   bean = manager.save(bean);
   log.info("save Ftp id={}", bean.getId());
   cmsLogMng.operating(request, "ftp.log.save", "id=" + bean.getId() + ";name=" + bean.getName());
   return "redirect:v_list.do";
 }
Exemple #12
0
 @RequestMapping("/item/o_update.do")
 public String update(CmsModelItem bean, HttpServletRequest request, ModelMap model) {
   WebErrors errors = validateUpdate(bean.getId(), bean, request);
   if (errors.hasErrors()) {
     return errors.showErrorPage(model);
   }
   bean = manager.update(bean);
   log.info("update CmsModelItem id={}.", bean.getId());
   model.addAttribute("modelId", bean.getModel().getId());
   model.addAttribute("isChannel", bean.getChannel());
   return "redirect:v_list.do";
 }
Exemple #13
0
 @RequestMapping("/vote_topic/o_delete.do")
 public String delete(Integer[] ids, Integer pageNo, HttpServletRequest request, ModelMap model) {
   WebErrors errors = validateDelete(ids, request);
   if (errors.hasErrors()) {
     return errors.showErrorPage(model);
   }
   CmsVoteTopic[] beans = manager.deleteByIds(ids);
   for (CmsVoteTopic bean : beans) {
     log.info("delete CmsVoteTopic id={}", bean.getId());
     cmsLogMng.operating(
         request, "cmsVoteTopic.log.delete", "id=" + bean.getId() + ";title=" + bean.getTitle());
   }
   return list(pageNo, request, model);
 }
Exemple #14
0
 private boolean vldExist(Integer id, Integer siteId, WebErrors errors) {
   if (errors.ifNull(id, "id")) {
     return true;
   }
   CmsVoteTopic entity = manager.findById(id);
   if (errors.ifNotExist(entity, CmsVoteTopic.class, id)) {
     return true;
   }
   if (!entity.getSite().getId().equals(siteId)) {
     errors.notInSite(CmsVoteTopic.class, id);
     return true;
   }
   return false;
 }
Exemple #15
0
 @RequestMapping("/ftp/o_delete.do")
 public String delete(Integer[] ids, Integer pageNo, HttpServletRequest request, ModelMap model) {
   WebErrors errors = validateDelete(ids, request);
   if (errors.hasErrors()) {
     return errors.showErrorPage(model);
   }
   Ftp[] beans = manager.deleteByIds(ids);
   for (Ftp bean : beans) {
     log.info("delete Ftp id={}", bean.getId());
     cmsLogMng.operating(
         request, "ftp.log.delete", "id=" + bean.getId() + ";name=" + bean.getName());
   }
   return list(pageNo, request, model);
 }
Exemple #16
0
 private WebErrors validateEdit(Integer id, HttpServletRequest request) {
   WebErrors errors = WebErrors.create(request);
   if (vldExist(id, errors)) {
     return errors;
   }
   return errors;
 }
Exemple #17
0
 private WebErrors validateSave(CmsModelItem bean, Integer modelId, HttpServletRequest request) {
   WebErrors errors = WebErrors.create(request);
   if (!StringUtils.isBlank(bean.getOptValue())) {
     bean.setOptValue(replaceLocaleSplit(bean.getOptValue(), request));
   }
   return errors;
 }
Exemple #18
0
 @RequestMapping("/ftp/o_update.do")
 public String update(Ftp bean, Integer pageNo, HttpServletRequest request, ModelMap model) {
   WebErrors errors = validateUpdate(bean.getId(), request);
   if (errors.hasErrors()) {
     return errors.showErrorPage(model);
   }
   // 留空不修改
   if (StringUtils.isBlank(bean.getPassword())) {
     bean.setPassword(manager.findById(bean.getId()).getPassword());
   }
   bean = manager.update(bean);
   log.info("update Ftp id={}.", bean.getId());
   cmsLogMng.operating(
       request, "ftp.log.update", "id=" + bean.getId() + ";name=" + bean.getName());
   return list(pageNo, request, model);
 }
Exemple #19
0
 private WebErrors validateUpdate(Integer id, HttpServletRequest request) {
   WebErrors errors = WebErrors.create(request);
   CmsSite site = CmsUtils.getSite(request);
   if (vldExist(id, site.getId(), errors)) {
     return errors;
   }
   return errors;
 }
Exemple #20
0
 private WebErrors validateUpdate(Integer id, CmsModelItem bean, HttpServletRequest request) {
   WebErrors errors = WebErrors.create(request);
   if (!StringUtils.isBlank(bean.getOptValue())) {
     bean.setOptValue(replaceLocaleSplit(bean.getOptValue(), request));
   }
   if (vldExist(id, errors)) {
     return errors;
   }
   return errors;
 }
Exemple #21
0
 @RequestMapping("/item/o_delete.do")
 public String delete(
     Integer[] ids,
     Integer modelId,
     Boolean isChannel,
     HttpServletRequest request,
     ModelMap model) {
   WebErrors errors = validateDelete(ids, request);
   if (errors.hasErrors()) {
     return errors.showErrorPage(model);
   }
   CmsModelItem[] beans = manager.deleteByIds(ids);
   for (CmsModelItem bean : beans) {
     log.info("delete CmsModelItem id={}", bean.getId());
   }
   model.addAttribute("modelId", modelId);
   model.addAttribute("isChannel", isChannel);
   return "redirect:v_list.do";
 }
Exemple #22
0
 @RequestMapping("/vote_topic/o_save.do")
 public String save(
     CmsVoteTopic bean,
     String[] itemTitle,
     Integer[] itemVoteCount,
     Integer[] itemPriority,
     HttpServletRequest request,
     ModelMap model) {
   WebErrors errors = validateSave(bean, request);
   if (errors.hasErrors()) {
     return errors.showErrorPage(model);
   }
   List<CmsVoteItem> items = getItems(null, itemTitle, itemVoteCount, itemPriority);
   bean = manager.save(bean, items);
   log.info("save CmsVoteTopic id={}", bean.getId());
   cmsLogMng.operating(
       request, "cmsVoteTopic.log.save", "id=" + bean.getId() + ";title=" + bean.getTitle());
   return "redirect:v_list.do";
 }
Exemple #23
0
 @RequestMapping("/data/o_delete.do")
 public String delete(
     String root,
     String[] names,
     HttpServletRequest request,
     ModelMap model,
     HttpServletResponse response) {
   WebErrors errors = validateDelete(names, request);
   if (errors.hasErrors()) {
     return errors.showErrorPage(model);
   }
   int count = resourceMng.delete(names);
   log.info("delete Resource count: {}", count);
   for (String name : names) {
     log.info("delete Resource name={}", name);
     cmsLogMng.operating(request, "resource.log.delete", "filename=" + name);
   }
   model.addAttribute("root", root);
   return listBackUpFiles(model, request, response);
 }
Exemple #24
0
 @RequestMapping("/vote_topic/o_update.do")
 public String update(
     CmsVoteTopic bean,
     Integer[] itemId,
     String[] itemTitle,
     Integer[] itemVoteCount,
     Integer[] itemPriority,
     Integer pageNo,
     HttpServletRequest request,
     ModelMap model) {
   WebErrors errors = validateUpdate(bean.getId(), request);
   if (errors.hasErrors()) {
     return errors.showErrorPage(model);
   }
   List<CmsVoteItem> items = getItems(itemId, itemTitle, itemVoteCount, itemPriority);
   bean = manager.update(bean, items);
   log.info("update CmsVoteTopic id={}.", bean.getId());
   cmsLogMng.operating(
       request, "cmsVoteTopic.log.update", "id=" + bean.getId() + ";title=" + bean.getTitle());
   return list(pageNo, request, model);
 }
Exemple #25
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";
 }
Exemple #26
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;
 }
Exemple #27
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;
 }
Exemple #28
0
 private boolean vldExist(String name, WebErrors errors) {
   if (errors.ifNull(name, "name")) {
     return true;
   }
   return false;
 }
Exemple #29
0
 private WebErrors validateSave(Ftp bean, HttpServletRequest request) {
   WebErrors errors = WebErrors.create(request);
   return errors;
 }
Exemple #30
0
 private WebErrors validateSave(CmsVoteTopic bean, HttpServletRequest request) {
   WebErrors errors = WebErrors.create(request);
   CmsSite site = CmsUtils.getSite(request);
   bean.setSite(site);
   return errors;
 }