Search in sources :

Example 1 with SysSite

use of com.publiccms.entities.sys.SysSite in project PublicCMS-preview by sanluan.

the class LoginAdminController method changeMyselfPassword.

/**
 * @param oldpassword
 * @param password
 * @param repassword
 * @param request
 * @param session
 * @param response
 * @param model
 * @return view name
 */
@RequestMapping(value = "changePassword", method = RequestMethod.POST)
public String changeMyselfPassword(String oldpassword, String password, String repassword, HttpServletRequest request, HttpSession session, HttpServletResponse response, ModelMap model) {
    SysSite site = getSite(request);
    SysUser user = service.getEntity(getAdminFromSession(session).getId());
    if (ControllerUtils.verifyNotEquals("siteId", site.getId(), user.getSiteId(), model)) {
        return TEMPLATE_ERROR;
    }
    String encodedOldPassword = VerificationUtils.md5Encode(oldpassword);
    if (ControllerUtils.verifyNotEquals("password", user.getPassword(), encodedOldPassword, model)) {
        return TEMPLATE_ERROR;
    } else if (ControllerUtils.verifyNotEmpty("password", password, model) || ControllerUtils.verifyNotEquals("repassword", password, repassword, model)) {
        return TEMPLATE_ERROR;
    } else {
        clearAdminToSession(request.getContextPath(), request.getSession(), response);
        model.addAttribute(MESSAGE, "message.needReLogin");
    }
    service.updatePassword(user.getId(), VerificationUtils.md5Encode(password));
    sysUserTokenService.delete(user.getId());
    logOperateService.save(new LogOperate(site.getId(), user.getId(), LogLoginService.CHANNEL_WEB_MANAGER, "changepassword", RequestUtils.getIpAddress(request), CommonUtils.getDate(), encodedOldPassword));
    return "common/ajaxTimeout";
}
Also used : LogOperate(com.publiccms.entities.log.LogOperate) SysUser(com.publiccms.entities.sys.SysUser) SysSite(com.publiccms.entities.sys.SysSite) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with SysSite

use of com.publiccms.entities.sys.SysSite in project PublicCMS-preview by sanluan.

the class LoginAdminController method login.

/**
 * @param username
 * @param password
 * @param returnUrl
 * @param request
 * @param session
 * @param response
 * @param model
 * @return view name
 */
@RequestMapping(value = "login", method = RequestMethod.POST)
public String login(String username, String password, String returnUrl, HttpServletRequest request, HttpSession session, HttpServletResponse response, ModelMap model) {
    SysSite site = getSite(request);
    username = StringUtils.trim(username);
    password = StringUtils.trim(password);
    if (ControllerUtils.verifyNotEmpty("username", username, model) || ControllerUtils.verifyNotEmpty("password", password, model)) {
        model.addAttribute("username", username);
        model.addAttribute("returnUrl", returnUrl);
        return "login";
    }
    String ip = RequestUtils.getIpAddress(request);
    SysUser user = service.findByName(site.getId(), username);
    if (ControllerUtils.verifyNotExist("username", user, model) || ControllerUtils.verifyNotEquals("password", VerificationUtils.md5Encode(password), user.getPassword(), model) || verifyNotAdmin(user, model) || verifyNotEnablie(user, model)) {
        model.addAttribute("username", username);
        model.addAttribute("returnUrl", returnUrl);
        Long userId = null;
        if (null != user) {
            userId = user.getId();
        }
        logLoginService.save(new LogLogin(site.getId(), username, userId, ip, LogLoginService.CHANNEL_WEB_MANAGER, false, CommonUtils.getDate(), password));
        return "login";
    }
    setAdminToSession(session, user);
    service.updateLoginStatus(user.getId(), ip);
    String authToken = UUID.randomUUID().toString();
    sysUserTokenService.save(new SysUserToken(authToken, site.getId(), user.getId(), LogLoginService.CHANNEL_WEB_MANAGER, CommonUtils.getDate(), ip));
    try {
        StringBuilder sb = new StringBuilder();
        sb.append(user.getId()).append(CommonConstants.getCookiesUserSplit()).append(authToken).append(CommonConstants.getCookiesUserSplit()).append(user.isSuperuserAccess()).append(CommonConstants.getCookiesUserSplit()).append(URLEncoder.encode(user.getNickName(), DEFAULT_CHARSET_NAME));
        RequestUtils.addCookie(request.getContextPath(), response, CommonConstants.getCookiesAdmin(), sb.toString(), Integer.MAX_VALUE, null);
    } catch (UnsupportedEncodingException e) {
        log.error(e.getMessage(), e);
    }
    logLoginService.save(new LogLogin(site.getId(), username, user.getId(), ip, LogLoginService.CHANNEL_WEB_MANAGER, true, CommonUtils.getDate(), null));
    if (CommonUtils.notEmpty(returnUrl)) {
        return REDIRECT + returnUrl;
    }
    return REDIRECT + CommonConstants.getDefaultPage();
}
Also used : SysUserToken(com.publiccms.entities.sys.SysUserToken) SysUser(com.publiccms.entities.sys.SysUser) LogLogin(com.publiccms.entities.log.LogLogin) UnsupportedEncodingException(java.io.UnsupportedEncodingException) SysSite(com.publiccms.entities.sys.SysSite) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with SysSite

use of com.publiccms.entities.sys.SysSite in project PublicCMS-preview by sanluan.

the class CmsCategoryAdminController method move.

/**
 * @param ids
 * @param parentId
 * @param request
 * @param session
 * @param model
 * @return view name
 */
@RequestMapping("move")
public String move(Integer[] ids, Integer parentId, HttpServletRequest request, HttpSession session, ModelMap model) {
    SysSite site = getSite(request);
    CmsCategory parent = service.getEntity(parentId);
    if (CommonUtils.notEmpty(ids) && (null == parent || null != parent && site.getId() == parent.getSiteId())) {
        for (Integer id : ids) {
            move(site, id, parentId);
        }
        logOperateService.save(new LogOperate(site.getId(), getAdminFromSession(session).getId(), LogLoginService.CHANNEL_WEB_MANAGER, "move.category", RequestUtils.getIpAddress(request), CommonUtils.getDate(), new StringBuilder(StringUtils.join(ids, ',')).append(" to ").append(parentId).toString()));
    }
    return TEMPLATE_DONE;
}
Also used : LogOperate(com.publiccms.entities.log.LogOperate) CmsCategory(com.publiccms.entities.cms.CmsCategory) SysSite(com.publiccms.entities.sys.SysSite) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 4 with SysSite

use of com.publiccms.entities.sys.SysSite in project PublicCMS-preview by sanluan.

the class CmsCategoryAdminController method save.

/**
 * @param entity
 * @param attribute
 * @param categoryParamters
 * @param request
 * @param session
 * @param model
 * @return view name
 */
@RequestMapping("save")
public String save(CmsCategory entity, CmsCategoryAttribute attribute, @ModelAttribute CmsCategoryParamters categoryParamters, HttpServletRequest request, HttpSession session, ModelMap model) {
    SysSite site = getSite(request);
    if (null != entity.getId()) {
        CmsCategory oldEntity = service.getEntity(entity.getId());
        if (null == oldEntity || ControllerUtils.verifyNotEquals("siteId", site.getId(), oldEntity.getSiteId(), model)) {
            return TEMPLATE_ERROR;
        }
        entity = service.update(entity.getId(), entity, ignoreProperties);
        if (null != entity) {
            if (null != oldEntity.getParentId() && oldEntity.getParentId() != entity.getParentId()) {
                service.generateChildIds(site.getId(), oldEntity.getParentId());
                service.generateChildIds(site.getId(), entity.getParentId());
            } else if (null != entity.getParentId() && null == oldEntity.getParentId()) {
                service.generateChildIds(site.getId(), entity.getParentId());
            }
            logOperateService.save(new LogOperate(site.getId(), getAdminFromSession(session).getId(), LogLoginService.CHANNEL_WEB_MANAGER, "update.category", RequestUtils.getIpAddress(request), CommonUtils.getDate(), JsonUtils.getString(entity)));
        }
    } else {
        if (entity.isOnlyUrl()) {
            entity.setUrl(entity.getPath());
        }
        entity.setSiteId(site.getId());
        service.save(entity);
        service.addChildIds(entity.getParentId(), entity.getId());
        logOperateService.save(new LogOperate(site.getId(), getAdminFromSession(session).getId(), LogLoginService.CHANNEL_WEB_MANAGER, "save.category", RequestUtils.getIpAddress(request), CommonUtils.getDate(), JsonUtils.getString(entity)));
    }
    if (null == extendService.getEntity(entity.getExtendId())) {
        entity = service.updateExtendId(entity.getId(), (Integer) extendService.save(new SysExtend("category", entity.getId())));
    }
    Integer[] tagTypeIds = tagTypeService.update(site.getId(), categoryParamters.getTagTypes());
    // 更新保存标签分类
    service.updateTagTypeIds(entity.getId(), arrayToCommaDelimitedString(tagTypeIds));
    List<CmsCategoryModelParamters> categoryModelList = categoryParamters.getCategoryModelList();
    if (CommonUtils.notEmpty(categoryModelList)) {
        for (CmsCategoryModelParamters cmsCategoryModelParamters : categoryModelList) {
            if (null != cmsCategoryModelParamters.getCategoryModel()) {
                cmsCategoryModelParamters.getCategoryModel().getId().setCategoryId(entity.getId());
                if (cmsCategoryModelParamters.isUse()) {
                    categoryModelService.updateCategoryModel(cmsCategoryModelParamters.getCategoryModel());
                } else {
                    categoryModelService.delete(cmsCategoryModelParamters.getCategoryModel().getId());
                }
            }
        }
    }
    // 修改或增加内容扩展字段
    extendFieldService.update(entity.getExtendId(), categoryParamters.getContentExtends());
    CmsCategoryType categoryType = categoryTypeService.getEntity(entity.getTypeId());
    if (null != categoryType && CommonUtils.notEmpty(categoryType.getExtendId())) {
        List<SysExtendField> categoryTypeExtendList = extendFieldService.getList(categoryType.getExtendId());
        Map<String, String> map = ExtendUtils.getSysExtentDataMap(categoryParamters.getExtendDataList(), categoryTypeExtendList);
        attribute.setData(ExtendUtils.getExtendString(map));
    } else {
        attribute.setData(null);
    }
    attributeService.updateAttribute(entity.getId(), attribute);
    try {
        publish(site, entity.getId(), null);
    } catch (IOException | TemplateException e) {
        ControllerUtils.verifyCustom("static", true, model);
        log.error(e.getMessage(), e);
    }
    return TEMPLATE_DONE;
}
Also used : LogOperate(com.publiccms.entities.log.LogOperate) TemplateException(freemarker.template.TemplateException) CmsCategoryType(com.publiccms.entities.cms.CmsCategoryType) StringUtils.arrayToCommaDelimitedString(org.springframework.util.StringUtils.arrayToCommaDelimitedString) IOException(java.io.IOException) CmsCategoryModelParamters(com.publiccms.views.pojo.model.CmsCategoryModelParamters) SysSite(com.publiccms.entities.sys.SysSite) SysExtendField(com.publiccms.entities.sys.SysExtendField) CmsCategory(com.publiccms.entities.cms.CmsCategory) SysExtend(com.publiccms.entities.sys.SysExtend) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 5 with SysSite

use of com.publiccms.entities.sys.SysSite in project PublicCMS-preview by sanluan.

the class CmsCategoryAdminController method delete.

/**
 * @param ids
 * @param request
 * @param session
 * @return view name
 */
@RequestMapping("delete")
public String delete(Integer[] ids, HttpServletRequest request, HttpSession session) {
    if (CommonUtils.notEmpty(ids)) {
        SysSite site = getSite(request);
        service.delete(site.getId(), ids);
        contentService.deleteByCategoryIds(site.getId(), ids);
        logOperateService.save(new LogOperate(site.getId(), getAdminFromSession(session).getId(), LogLoginService.CHANNEL_WEB_MANAGER, "delete.category", RequestUtils.getIpAddress(request), CommonUtils.getDate(), StringUtils.join(ids, ',')));
    }
    return TEMPLATE_DONE;
}
Also used : LogOperate(com.publiccms.entities.log.LogOperate) SysSite(com.publiccms.entities.sys.SysSite) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

SysSite (com.publiccms.entities.sys.SysSite)175 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)135 LogOperate (com.publiccms.entities.log.LogOperate)117 IOException (java.io.IOException)33 SysUser (com.publiccms.entities.sys.SysUser)21 LinkedHashMap (java.util.LinkedHashMap)19 TemplateException (freemarker.template.TemplateException)15 File (java.io.File)14 CmsContent (com.publiccms.entities.cms.CmsContent)12 CmsCategory (com.publiccms.entities.cms.CmsCategory)11 MultipartFile (org.springframework.web.multipart.MultipartFile)10 SysTask (com.publiccms.entities.sys.SysTask)9 HashMap (java.util.HashMap)8 LogUpload (com.publiccms.entities.log.LogUpload)7 SysDept (com.publiccms.entities.sys.SysDept)7 SysUserToken (com.publiccms.entities.sys.SysUserToken)7 CmsPlaceMetadata (com.publiccms.views.pojo.entities.CmsPlaceMetadata)7 CmsPageMetadata (com.publiccms.views.pojo.entities.CmsPageMetadata)6 CmsPlace (com.publiccms.entities.cms.CmsPlace)5 SysDomain (com.publiccms.entities.sys.SysDomain)5