Search in sources :

Example 11 with SysUser

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

the class ContentController method save.

/**
 * 保存内容
 *
 * @param entity
 * @param attribute
 * @param contentParamters
 * @param returnUrl
 * @param request
 * @param session
 * @param response
 * @param model
 * @return view name
 */
@RequestMapping(value = "save", method = RequestMethod.POST)
public String save(CmsContent entity, CmsContentAttribute attribute, @ModelAttribute CmsContentParamters contentParamters, String returnUrl, HttpServletRequest request, HttpSession session, HttpServletResponse response, ModelMap model) {
    SysSite site = getSite(request);
    if (CommonUtils.empty(returnUrl)) {
        returnUrl = site.getDynamicPath();
    }
    SysUser user = getUserFromSession(session);
    CmsCategoryModel categoryModel = categoryModelService.getEntity(new CmsCategoryModelId(entity.getCategoryId(), entity.getModelId()));
    if (ControllerUtils.verifyNotEmpty("categoryModel", categoryModel, model) || ControllerUtils.verifyCustom("contribute", null == user, model)) {
        return REDIRECT + returnUrl;
    }
    CmsCategory category = categoryService.getEntity(entity.getCategoryId());
    if (null != category && (site.getId() != category.getSiteId() || !category.isAllowContribute())) {
        category = null;
    }
    CmsModel cmsModel = modelComponent.getMap(site).get(entity.getModelId());
    if (ControllerUtils.verifyNotEmpty("category", category, model) || ControllerUtils.verifyNotEmpty("model", cmsModel, model)) {
        return REDIRECT + returnUrl;
    }
    entity.setHasFiles(cmsModel.isHasFiles());
    entity.setHasImages(cmsModel.isHasImages());
    entity.setOnlyUrl(cmsModel.isOnlyUrl());
    entity.setStatus(CmsContentService.STATUS_PEND);
    if (null != entity.getId()) {
        CmsContent oldEntity = service.getEntity(entity.getId());
        if (null == oldEntity || ControllerUtils.verifyNotEquals("siteId", site.getId(), oldEntity.getSiteId(), model)) {
            return REDIRECT + returnUrl;
        }
        entity = service.update(entity.getId(), entity, entity.isOnlyUrl() ? ignoreProperties : ignorePropertiesWithUrl);
        if (null != entity.getId()) {
            logOperateService.save(new LogOperate(site.getId(), user.getId(), LogLoginService.CHANNEL_WEB, "update.content", RequestUtils.getIpAddress(request), CommonUtils.getDate(), JsonUtils.getString(entity)));
        }
    } else {
        entity.setSiteId(site.getId());
        entity.setUserId(user.getId());
        service.save(entity);
        if (CommonUtils.notEmpty(entity.getParentId())) {
            service.updateChilds(entity.getParentId(), 1);
        }
        logOperateService.save(new LogOperate(site.getId(), user.getId(), LogLoginService.CHANNEL_WEB, "save.content", RequestUtils.getIpAddress(request), CommonUtils.getDate(), JsonUtils.getString(entity)));
    }
    if (entity.isHasImages() || entity.isHasFiles()) {
        contentFileService.update(entity.getId(), user.getId(), entity.isHasFiles() ? contentParamters.getFiles() : null, // 更新保存图集,附件
        entity.isHasImages() ? contentParamters.getImages() : null);
    }
    if (null != attribute.getText()) {
        attribute.setWordCount(HtmlUtils.removeHtmlTag(attribute.getText()).length());
    }
    List<ExtendField> modelExtendList = cmsModel.getExtendList();
    Map<String, String> map = ExtendUtils.getExtentDataMap(contentParamters.getModelExtendDataList(), modelExtendList);
    if (null != category && null != extendService.getEntity(category.getExtendId())) {
        List<SysExtendField> categoryExtendList = extendFieldService.getList(category.getExtendId());
        Map<String, String> categoryMap = ExtendUtils.getSysExtentDataMap(contentParamters.getCategoryExtendDataList(), categoryExtendList);
        if (CommonUtils.notEmpty(map)) {
            map.putAll(categoryMap);
        } else {
            map = categoryMap;
        }
    }
    if (CommonUtils.notEmpty(map)) {
        attribute.setData(ExtendUtils.getExtendString(map));
    } else {
        attribute.setData(null);
    }
    // 更新保存扩展字段,文本字段
    attributeService.updateAttribute(entity.getId(), attribute);
    return REDIRECT + returnUrl;
}
Also used : CmsContent(com.publiccms.entities.cms.CmsContent) LogOperate(com.publiccms.entities.log.LogOperate) SysUser(com.publiccms.entities.sys.SysUser) CmsModel(com.publiccms.views.pojo.entities.CmsModel) SysExtendField(com.publiccms.entities.sys.SysExtendField) ExtendField(com.publiccms.views.pojo.entities.ExtendField) CmsCategoryModelId(com.publiccms.entities.cms.CmsCategoryModelId) CmsCategoryModel(com.publiccms.entities.cms.CmsCategoryModel) SysSite(com.publiccms.entities.sys.SysSite) SysExtendField(com.publiccms.entities.sys.SysExtendField) CmsCategory(com.publiccms.entities.cms.CmsCategory) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 12 with SysUser

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

the class LotteryController method check.

/**
 * @param callback
 * @param request
 * @param session
 * @param response
 */
@RequestMapping("status")
public void check(String callback, HttpServletRequest request, HttpSession session, HttpServletResponse response) {
    try {
        HttpParameterHandler handler = new HttpParameterHandler(mappingJackson2HttpMessageConverter, jsonMediaType, request, callback, response);
        SysUser user = getUserFromSession(session);
        if (null != user) {
            lotteryStatusDirective.execute(handler, null, user);
        }
        handler.render();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : SysUser(com.publiccms.entities.sys.SysUser) HttpParameterHandler(com.publiccms.common.handler.HttpParameterHandler) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 13 with SysUser

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

the class PlaceController method check.

/**
 * @param id
 * @param returnUrl
 * @param request
 * @param session
 * @param response
 * @param model
 * @return view name
 */
@RequestMapping("check")
public String check(Long id, String returnUrl, HttpServletRequest request, HttpSession session, HttpServletResponse response, ModelMap model) {
    SysSite site = getSite(request);
    if (CommonUtils.empty(returnUrl)) {
        returnUrl = site.getDynamicPath();
    }
    CmsPlace entity = service.getEntity(id);
    SysUser user = getUserFromSession(session);
    String filePath = siteComponent.getWebTemplateFilePath(site, TemplateComponent.INCLUDE_DIRECTORY + entity.getPath());
    CmsPlaceMetadata metadata = metadataComponent.getPlaceMetadata(filePath);
    if (ControllerUtils.verifyCustom("manage", null == entity || null == user || CommonUtils.empty(metadata.getAdminIds()) || !ArrayUtils.contains(metadata.getAdminIds(), user.getId()), model) || ControllerUtils.verifyNotEquals("siteId", site.getId(), entity.getSiteId(), model)) {
        return REDIRECT + returnUrl;
    } else {
        service.check(id);
        logOperateService.save(new LogOperate(site.getId(), user.getId(), LogLoginService.CHANNEL_WEB, "check.place", RequestUtils.getIpAddress(request), CommonUtils.getDate(), id.toString()));
        return REDIRECT + returnUrl;
    }
}
Also used : LogOperate(com.publiccms.entities.log.LogOperate) CmsPlace(com.publiccms.entities.cms.CmsPlace) SysUser(com.publiccms.entities.sys.SysUser) CmsPlaceMetadata(com.publiccms.views.pojo.entities.CmsPlaceMetadata) SysSite(com.publiccms.entities.sys.SysSite) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 14 with SysUser

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

the class VoteController method lottery.

/**
 * @param callback
 * @param request
 * @param session
 * @param response
 */
@RequestMapping("vote")
public void lottery(String callback, HttpServletRequest request, HttpSession session, HttpServletResponse response) {
    try {
        HttpParameterHandler handler = new HttpParameterHandler(mappingJackson2HttpMessageConverter, jsonMediaType, request, callback, response);
        SysUser user = getUserFromSession(session);
        if (null != user) {
            voteDirective.execute(handler, null, user);
        }
        handler.render();
    } catch (Exception e) {
    }
}
Also used : SysUser(com.publiccms.entities.sys.SysUser) HttpParameterHandler(com.publiccms.common.handler.HttpParameterHandler) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 15 with SysUser

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

the class UserController method saveEmail.

/**
 * @param email
 * @param returnUrl
 * @param request
 * @param session
 * @param response
 * @param model
 * @return view name
 */
@RequestMapping(value = "saveEmail", method = RequestMethod.POST)
public String saveEmail(String email, String returnUrl, HttpServletRequest request, HttpSession session, HttpServletResponse response, ModelMap model) {
    SysSite site = getSite(request);
    if (CommonUtils.empty(returnUrl)) {
        returnUrl = site.getDynamicPath();
    }
    Map<String, String> config = configComponent.getConfigData(site.getId(), EmailComponent.CONFIG_CODE);
    String emailTitle = config.get(EmailTemplateConfigComponent.CONFIG_EMAIL_TITLE);
    String emailPath = config.get(EmailTemplateConfigComponent.CONFIG_EMAIL_PATH);
    SysUser user = getUserFromSession(session);
    if (ControllerUtils.verifyNotEmpty("user", user, model) || ControllerUtils.verifyNotEmpty("email", email, model) || ControllerUtils.verifyNotEmpty("email.config", emailTitle, model) || ControllerUtils.verifyNotEmpty("email.config", emailPath, model) || verifyNotEMail("email", email, model) || ControllerUtils.verifyHasExist("email", service.findByEmail(site.getId(), email), model)) {
        return REDIRECT + returnUrl;
    } else {
        SysEmailToken sysEmailToken = new SysEmailToken();
        sysEmailToken.setUserId(user.getId());
        sysEmailToken.setAuthToken(UUID.randomUUID().toString());
        sysEmailToken.setEmail(email);
        sysEmailTokenService.save(sysEmailToken);
        try {
            Map<String, Object> emailModel = new HashMap<>();
            emailModel.put("user", user);
            emailModel.put("site", site);
            emailModel.put("email", email);
            emailModel.put("authToken", sysEmailToken.getAuthToken());
            if (emailComponent.sendHtml(site.getId(), email, FreeMarkerUtils.generateStringByString(emailTitle, templateComponent.getWebConfiguration(), emailModel), FreeMarkerUtils.generateStringByFile(siteComponent.getWebTemplateFilePath(site, emailPath), templateComponent.getWebConfiguration(), emailModel))) {
                model.addAttribute(MESSAGE, "sendEmail.success");
            } else {
                model.addAttribute(MESSAGE, "sendEmail.error");
            }
        } catch (IOException | TemplateException | MessagingException e) {
            model.addAttribute(ERROR, "sendEmail.error");
        }
        return REDIRECT + returnUrl;
    }
}
Also used : SysUser(com.publiccms.entities.sys.SysUser) HashMap(java.util.HashMap) TemplateException(freemarker.template.TemplateException) MessagingException(javax.mail.MessagingException) SysEmailToken(com.publiccms.entities.sys.SysEmailToken) IOException(java.io.IOException) SysSite(com.publiccms.entities.sys.SysSite) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

SysUser (com.publiccms.entities.sys.SysUser)29 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)23 SysSite (com.publiccms.entities.sys.SysSite)21 LogOperate (com.publiccms.entities.log.LogOperate)15 SysDept (com.publiccms.entities.sys.SysDept)5 HttpParameterHandler (com.publiccms.common.handler.HttpParameterHandler)3 CmsContent (com.publiccms.entities.cms.CmsContent)3 CmsPlace (com.publiccms.entities.cms.CmsPlace)3 SysRoleUser (com.publiccms.entities.sys.SysRoleUser)3 SysRoleUserId (com.publiccms.entities.sys.SysRoleUserId)3 SysUserToken (com.publiccms.entities.sys.SysUserToken)3 CmsPlaceMetadata (com.publiccms.views.pojo.entities.CmsPlaceMetadata)3 Cookie (javax.servlet.http.Cookie)3 CmsCategory (com.publiccms.entities.cms.CmsCategory)2 CmsCategoryModel (com.publiccms.entities.cms.CmsCategoryModel)2 CmsCategoryModelId (com.publiccms.entities.cms.CmsCategoryModelId)2 LogLogin (com.publiccms.entities.log.LogLogin)2 SysExtendField (com.publiccms.entities.sys.SysExtendField)2 CmsModel (com.publiccms.views.pojo.entities.CmsModel)2 ExtendField (com.publiccms.views.pojo.entities.ExtendField)2