Search in sources :

Example 6 with SysUser

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

the class SysUserService method updateLoginStatus.

/**
 * @param id
 * @param ip
 * @return
 */
public SysUser updateLoginStatus(Serializable id, String ip) {
    SysUser entity = getEntity(id);
    if (null != entity) {
        entity.setLastLoginDate(CommonUtils.getDate());
        entity.setLastLoginIp(ip);
        entity.setLoginCount(entity.getLoginCount() + 1);
    }
    return entity;
}
Also used : SysUser(com.publiccms.entities.sys.SysUser)

Example 7 with SysUser

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

the class SysUserDirective method execute.

@Override
public void execute(RenderHandler handler) throws IOException, Exception {
    Long id = handler.getLong("id");
    SysSite site = getSite(handler);
    if (CommonUtils.notEmpty(id)) {
        SysUser entity = service.getEntity(id);
        entity.setPassword(null);
        if (null != entity && site.getId() == entity.getSiteId()) {
            entity.setPassword(null);
            handler.put("object", entity).render();
        }
    } else {
        Long[] ids = handler.getLongArray("ids");
        if (CommonUtils.notEmpty(ids)) {
            List<SysUser> entityList = service.getEntitys(ids);
            Map<String, SysUser> map = new LinkedHashMap<>();
            for (SysUser entity : entityList) {
                if (site.getId() == entity.getSiteId()) {
                    entity.setPassword(null);
                    map.put(String.valueOf(entity.getId()), entity);
                }
            }
            handler.put("map", map).render();
        }
    }
}
Also used : SysUser(com.publiccms.entities.sys.SysUser) SysSite(com.publiccms.entities.sys.SysSite) LinkedHashMap(java.util.LinkedHashMap)

Example 8 with SysUser

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

the class SysDeptAdminController method disable.

/**
 * @param id
 * @param request
 * @param session
 * @param model
 * @return view name
 */
@RequestMapping(value = "disableUser", method = RequestMethod.POST)
public String disable(Long id, HttpServletRequest request, HttpSession session, ModelMap model) {
    if (ControllerUtils.verifyEquals("admin.operate", getAdminFromSession(session).getId(), id, model)) {
        return TEMPLATE_ERROR;
    }
    SysUser entity = userService.getEntity(id);
    if (null != entity) {
        SysSite site = getSite(request);
        SysDept dept = service.getEntity(entity.getDeptId());
        SysUser admin = getAdminFromSession(session);
        if (ControllerUtils.verifyNotEquals("siteId", site.getId(), entity.getSiteId(), model) || ControllerUtils.verifyNotEmpty("deptId", dept, model) || ControllerUtils.verifyNotEquals("userId", dept.getUserId(), admin.getId(), model)) {
            return TEMPLATE_ERROR;
        }
        userService.updateStatus(id, true);
        logOperateService.save(new LogOperate(site.getId(), admin.getId(), LogLoginService.CHANNEL_WEB_MANAGER, "disable.user", RequestUtils.getIpAddress(request), CommonUtils.getDate(), JsonUtils.getString(entity)));
    }
    return TEMPLATE_DONE;
}
Also used : LogOperate(com.publiccms.entities.log.LogOperate) SysUser(com.publiccms.entities.sys.SysUser) SysDept(com.publiccms.entities.sys.SysDept) SysSite(com.publiccms.entities.sys.SysSite) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 9 with SysUser

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

the class SysSiteAdminController method save.

/**
 * @param entity
 * @param domainName
 * @param roleName
 * @param deptName
 * @param userName
 * @param password
 * @param request
 * @param session
 * @param model
 * @return view name
 */
@RequestMapping("save")
public String save(SysSite entity, String domainName, String roleName, String deptName, String userName, String password, HttpServletRequest request, HttpSession session, ModelMap model) {
    SysSite site = getSite(request);
    if (ControllerUtils.verifyCustom("noright", !siteComponent.isMaster(site.getId()), model)) {
        return TEMPLATE_ERROR;
    }
    if (!entity.isUseStatic()) {
        entity.setUseSsi(false);
    }
    if (null != entity.getId()) {
        entity = service.update(entity.getId(), entity, ignoreProperties);
        if (null != entity) {
            logOperateService.save(new LogOperate(site.getId(), getAdminFromSession(session).getId(), LogLoginService.CHANNEL_WEB_MANAGER, "update.site", RequestUtils.getIpAddress(request), CommonUtils.getDate(), JsonUtils.getString(entity)));
        }
    } else {
        if (ControllerUtils.verifyCustom("needAuthorizationEdition", !CmsVersion.isAuthorizationEdition(), model) || ControllerUtils.verifyCustom("unauthorizedDomain", !CmsVersion.verifyDomain(domainName), model) || ControllerUtils.verifyNotEmpty("userName", userName, model) || ControllerUtils.verifyNotEmpty("password", password, model) || ControllerUtils.verifyHasExist("domain", service.getEntity(domainName), model)) {
            return TEMPLATE_ERROR;
        }
        service.save(entity);
        SysDomain domain = new SysDomain(domainName, entity.getId(), false);
        domainService.save(domain);
        SysDept dept = new SysDept(entity.getId(), deptName, 0, true, true);
        // 初始化部门
        deptService.save(dept);
        SysRole role = new SysRole(entity.getId(), roleName, true, true);
        // 初始化角色
        roleService.save(role);
        SysUser user = new SysUser(entity.getId(), userName, VerificationUtils.md5Encode(password), userName, dept.getId(), role.getId().toString(), null, false, true, false, null, null, 0, CommonUtils.getDate());
        // 初始化用户
        userService.save(user);
        // 初始化角色用户映射
        roleUserService.save(new SysRoleUser(new SysRoleUserId(role.getId(), user.getId())));
        logOperateService.save(new LogOperate(site.getId(), getAdminFromSession(session).getId(), LogLoginService.CHANNEL_WEB_MANAGER, "save.site", RequestUtils.getIpAddress(request), CommonUtils.getDate(), JsonUtils.getString(entity)));
    }
    siteComponent.clear();
    return TEMPLATE_DONEANDREFRESH;
}
Also used : LogOperate(com.publiccms.entities.log.LogOperate) SysDomain(com.publiccms.entities.sys.SysDomain) SysUser(com.publiccms.entities.sys.SysUser) SysDept(com.publiccms.entities.sys.SysDept) SysRole(com.publiccms.entities.sys.SysRole) SysRoleUserId(com.publiccms.entities.sys.SysRoleUserId) SysSite(com.publiccms.entities.sys.SysSite) SysRoleUser(com.publiccms.entities.sys.SysRoleUser) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 10 with SysUser

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

the class SysUserAdminController method save.

/**
 * @param entity
 * @param repassword
 * @param roleIds
 * @param request
 * @param session
 * @param model
 * @return view name
 */
@RequestMapping("save")
public String save(SysUser entity, String repassword, Integer[] roleIds, HttpServletRequest request, HttpSession session, ModelMap model) {
    SysSite site = getSite(request);
    entity.setName(StringUtils.trim(entity.getName()));
    entity.setNickName(StringUtils.trim(entity.getNickName()));
    entity.setPassword(StringUtils.trim(entity.getPassword()));
    repassword = StringUtils.trim(repassword);
    if (ControllerUtils.verifyNotEmpty("username", entity.getName(), model) || ControllerUtils.verifyNotEmpty("nickname", entity.getNickName(), model) || verifyNotUserName("username", entity.getName(), model) || verifyNotNickName("nickname", entity.getNickName(), model)) {
        return TEMPLATE_ERROR;
    }
    if (entity.isSuperuserAccess()) {
        entity.setRoles(arrayToCommaDelimitedString(roleIds));
    } else {
        roleIds = null;
        entity.setRoles(null);
        entity.setDeptId(null);
    }
    if (null != entity.getId()) {
        SysUser oldEntity = service.getEntity(entity.getId());
        if (null == oldEntity || ControllerUtils.verifyNotEquals("siteId", site.getId(), oldEntity.getSiteId(), model)) {
            return TEMPLATE_ERROR;
        }
        SysUser user = service.getEntity(entity.getId());
        if ((!user.getName().equals(entity.getName()) && ControllerUtils.verifyHasExist("username", service.findByName(site.getId(), entity.getName()), model)) || (!user.getNickName().equals(entity.getNickName()) && ControllerUtils.verifyHasExist("nickname", service.findByNickName(site.getId(), entity.getNickName()), model))) {
            return TEMPLATE_ERROR;
        }
        if (CommonUtils.notEmpty(entity.getPassword())) {
            if (ControllerUtils.verifyNotEquals("repassword", entity.getPassword(), repassword, model)) {
                return TEMPLATE_ERROR;
            }
            entity.setPassword(VerificationUtils.md5Encode(entity.getPassword()));
        } else {
            entity.setPassword(user.getPassword());
            if (CommonUtils.empty(entity.getEmail()) || !entity.getEmail().equals(user.getEmail())) {
                entity.setEmailChecked(false);
            }
        }
        entity = service.update(entity.getId(), entity, ignoreProperties);
        if (null != entity) {
            roleUserService.dealRoleUsers(entity.getId(), roleIds);
            logOperateService.save(new LogOperate(site.getId(), getAdminFromSession(session).getId(), LogLoginService.CHANNEL_WEB_MANAGER, "update.user", RequestUtils.getIpAddress(request), CommonUtils.getDate(), JsonUtils.getString(entity)));
        }
    } else {
        if (ControllerUtils.verifyNotEmpty("password", entity.getPassword(), model) || ControllerUtils.verifyNotEquals("repassword", entity.getPassword(), repassword, model) || ControllerUtils.verifyHasExist("username", service.findByName(site.getId(), entity.getName()), model)) {
            return TEMPLATE_ERROR;
        }
        entity.setSiteId(site.getId());
        entity.setPassword(VerificationUtils.md5Encode(entity.getPassword()));
        service.save(entity);
        if (CommonUtils.notEmpty(roleIds)) {
            for (Integer roleId : roleIds) {
                roleUserService.save(new SysRoleUser(new SysRoleUserId(roleId, entity.getId())));
            }
        }
        logOperateService.save(new LogOperate(site.getId(), getAdminFromSession(session).getId(), LogLoginService.CHANNEL_WEB_MANAGER, "save.user", RequestUtils.getIpAddress(request), CommonUtils.getDate(), JsonUtils.getString(entity)));
    }
    return TEMPLATE_DONE;
}
Also used : LogOperate(com.publiccms.entities.log.LogOperate) SysUser(com.publiccms.entities.sys.SysUser) SysRoleUserId(com.publiccms.entities.sys.SysRoleUserId) SysSite(com.publiccms.entities.sys.SysSite) SysRoleUser(com.publiccms.entities.sys.SysRoleUser) 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