Search in sources :

Example 1 with SysUser

use of com.publiccms.entities.sys.SysUser 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 SysUser

use of com.publiccms.entities.sys.SysUser 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 SysUser

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

the class CmsContentAdminController method save.

/**
 * 保存内容
 *
 * @param entity
 * @param attribute
 * @param contentParamters
 * @param draft
 * @param checked
 * @param request
 * @param session
 * @param model
 * @return view name
 */
@RequestMapping("save")
public String save(CmsContent entity, CmsContentAttribute attribute, @ModelAttribute CmsContentParamters contentParamters, Boolean draft, Boolean checked, HttpServletRequest request, HttpSession session, ModelMap model) {
    SysSite site = getSite(request);
    SysUser user = getAdminFromSession(session);
    SysDept dept = sysDeptService.getEntity(user.getDeptId());
    if (ControllerUtils.verifyNotEmpty("deptId", user.getDeptId(), model) && ControllerUtils.verifyNotEmpty("deptId", dept, model) && ControllerUtils.verifyCustom("noright", !(dept.isOwnsAllCategory() || null != sysDeptCategoryService.getEntity(new SysDeptCategoryId(user.getDeptId(), entity.getCategoryId()))), model)) {
        return TEMPLATE_ERROR;
    }
    CmsCategoryModel categoryModel = categoryModelService.getEntity(new CmsCategoryModelId(entity.getCategoryId(), entity.getModelId()));
    if (ControllerUtils.verifyNotEmpty("categoryModel", categoryModel, model)) {
        return TEMPLATE_ERROR;
    }
    CmsCategory category = categoryService.getEntity(entity.getCategoryId());
    if (null != category && site.getId() != category.getSiteId()) {
        category = null;
    }
    CmsModel cmsModel = modelComponent.getMap(site).get(entity.getModelId());
    if (ControllerUtils.verifyNotEmpty("category", category, model) || ControllerUtils.verifyNotEmpty("model", cmsModel, model)) {
        return TEMPLATE_ERROR;
    }
    entity.setHasFiles(cmsModel.isHasFiles());
    entity.setHasImages(cmsModel.isHasImages());
    entity.setOnlyUrl(cmsModel.isOnlyUrl());
    if ((null == checked || !checked) && null != draft && draft) {
        entity.setStatus(CmsContentService.STATUS_DRAFT);
    } else {
        entity.setStatus(CmsContentService.STATUS_PEND);
    }
    Date now = CommonUtils.getDate();
    if (null == entity.getPublishDate()) {
        entity.setPublishDate(now);
    }
    if (null != attribute.getText()) {
        String text = HtmlUtils.removeHtmlTag(attribute.getText());
        attribute.setWordCount(text.length());
        if (CommonUtils.empty(entity.getDescription())) {
            entity.setDescription(StringUtils.substring(text, 0, 300));
        }
    }
    if (null != entity.getId()) {
        CmsContent oldEntity = service.getEntity(entity.getId());
        if (null == oldEntity || ControllerUtils.verifyNotEquals("siteId", site.getId(), oldEntity.getSiteId(), model)) {
            return TEMPLATE_ERROR;
        }
        entity.setUpdateDate(now);
        entity = service.update(entity.getId(), entity, entity.isOnlyUrl() ? ignoreProperties : ignorePropertiesWithUrl);
        if (null != entity) {
            logOperateService.save(new LogOperate(site.getId(), user.getId(), LogLoginService.CHANNEL_WEB_MANAGER, "update.content", RequestUtils.getIpAddress(request), now, 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_MANAGER, "save.content", RequestUtils.getIpAddress(request), now, JsonUtils.getString(entity)));
    }
    Long[] tagIds = tagService.update(site.getId(), contentParamters.getTags());
    // 更新保存标签
    service.updateTagIds(entity.getId(), arrayToDelimitedString(tagIds, BLANK_SPACE));
    if (entity.isHasImages() || entity.isHasFiles()) {
        contentFileService.update(entity.getId(), user.getId(), entity.isHasFiles() ? contentParamters.getFiles() : null, // 更新保存图集,附件
        entity.isHasImages() ? contentParamters.getImages() : null);
    }
    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);
    // 更新保存推荐内容
    cmsContentRelatedService.update(entity.getId(), user.getId(), contentParamters.getContentRelateds());
    // 静态化
    templateComponent.createContentFile(site, entity, category, categoryModel);
    if (null != checked && checked) {
        service.check(site.getId(), user.getId(), new Long[] { entity.getId() }, false);
        if (CommonUtils.notEmpty(entity.getParentId())) {
            publish(new Long[] { entity.getParentId() }, request, session, model);
        }
        templateComponent.createCategoryFile(site, category, null, null);
    }
    return TEMPLATE_DONE;
}
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) SysDept(com.publiccms.entities.sys.SysDept) SysExtendField(com.publiccms.entities.sys.SysExtendField) ExtendField(com.publiccms.views.pojo.entities.ExtendField) SysDeptCategoryId(com.publiccms.entities.sys.SysDeptCategoryId) StringUtils.arrayToDelimitedString(org.springframework.util.StringUtils.arrayToDelimitedString) CmsCategoryModelId(com.publiccms.entities.cms.CmsCategoryModelId) CmsCategoryModel(com.publiccms.entities.cms.CmsCategoryModel) Date(java.util.Date) 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 4 with SysUser

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

the class CmsContentAdminController method related.

/**
 * @param entity
 * @param request
 * @param session
 * @param model
 * @return view name
 */
@RequestMapping("related")
public String related(CmsContentRelated entity, HttpServletRequest request, HttpSession session, ModelMap model) {
    CmsContent content = service.getEntity(entity.getContentId());
    CmsContent related = service.getEntity(entity.getRelatedContentId());
    SysSite site = getSite(request);
    if (null != content && null != related && site.getId() == content.getSiteId() && site.getId() == related.getSiteId()) {
        if (CommonUtils.empty(entity.getTitle())) {
            entity.setTitle(entity.getTitle());
        }
        if (CommonUtils.empty(entity.getDescription())) {
            entity.setDescription(entity.getDescription());
        }
        SysUser user = getAdminFromSession(session);
        entity.setUserId(user.getId());
        cmsContentRelatedService.save(entity);
        publish(new Long[] { entity.getContentId() }, request, session, model);
        logOperateService.save(new LogOperate(site.getId(), user.getId(), LogLoginService.CHANNEL_WEB_MANAGER, "related.content", RequestUtils.getIpAddress(request), CommonUtils.getDate(), JsonUtils.getString(related)));
    }
    return TEMPLATE_DONE;
}
Also used : CmsContent(com.publiccms.entities.cms.CmsContent) 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 5 with SysUser

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

the class SysUserService method checked.

/**
 * @param id
 * @param email
 */
public void checked(Serializable id, String email) {
    SysUser entity = getEntity(id);
    if (null != entity) {
        entity.setEmail(email);
        entity.setEmailChecked(true);
    }
}
Also used : SysUser(com.publiccms.entities.sys.SysUser)

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