Search in sources :

Example 1 with SysRoleUser

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

the class SysRoleAdminController method delete.

/**
 * @param id
 * @param request
 * @param session
 * @param model
 * @return view name
 */
@RequestMapping("delete")
public String delete(Integer id, HttpServletRequest request, HttpSession session, ModelMap model) {
    SysRole entity = service.getEntity(id);
    SysSite site = getSite(request);
    if (null != entity) {
        if (ControllerUtils.verifyNotEquals("siteId", site.getId(), entity.getSiteId(), model)) {
            return TEMPLATE_ERROR;
        }
        service.delete(id);
        @SuppressWarnings("unchecked") List<SysRoleUser> roleUserList = (List<SysRoleUser>) roleUserService.getPage(id, null, null, null).getList();
        for (SysRoleUser roleUser : roleUserList) {
            userService.deleteRoleIds(roleUser.getId().getUserId(), id);
        }
        roleUserService.deleteByRoleId(id);
        roleModuleService.deleteByRoleId(id);
        roleAuthorizedService.deleteByRoleId(id);
        logOperateService.save(new LogOperate(site.getId(), getAdminFromSession(session).getId(), LogLoginService.CHANNEL_WEB_MANAGER, "delete.role", RequestUtils.getIpAddress(request), CommonUtils.getDate(), JsonUtils.getString(entity)));
    }
    return TEMPLATE_DONE;
}
Also used : LogOperate(com.publiccms.entities.log.LogOperate) SysRole(com.publiccms.entities.sys.SysRole) ArrayList(java.util.ArrayList) List(java.util.List) SysSite(com.publiccms.entities.sys.SysSite) SysRoleUser(com.publiccms.entities.sys.SysRoleUser) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with SysRoleUser

use of com.publiccms.entities.sys.SysRoleUser 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 3 with SysRoleUser

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

Example 4 with SysRoleUser

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

the class SysDeptAdminController method saveUser.

/**
 * @param entity
 * @param repassword
 * @param roleIds
 * @param request
 * @param session
 * @param model
 * @return view name
 */
@RequestMapping("saveUser")
public String saveUser(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);
    SysDept dept = service.getEntity(entity.getDeptId());
    SysUser admin = getAdminFromSession(session);
    if (ControllerUtils.verifyNotEmpty("username", entity.getName(), model) || ControllerUtils.verifyNotEmpty("deptId", dept, model) || ControllerUtils.verifyNotEquals("userId", dept.getUserId(), admin.getId(), model) || ControllerUtils.verifyNotEquals("siteId", site.getId(), dept.getSiteId(), model) || ControllerUtils.verifyNotEmpty("nickname", entity.getNickName(), model) || verifyNotUserName("username", entity.getName(), model) || verifyNotNickName("nickname", entity.getNickName(), model)) {
        return TEMPLATE_ERROR;
    }
    entity.setSuperuserAccess(true);
    entity.setRoles(arrayToCommaDelimitedString(roleIds));
    if (null != entity.getId()) {
        SysUser oldEntity = userService.getEntity(entity.getId());
        if (null == oldEntity || ControllerUtils.verifyNotEquals("siteId", site.getId(), oldEntity.getSiteId(), model)) {
            return TEMPLATE_ERROR;
        }
        SysUser user = userService.getEntity(entity.getId());
        if ((!user.getName().equals(entity.getName()) && ControllerUtils.verifyHasExist("username", userService.findByName(site.getId(), entity.getName()), model)) || (!user.getNickName().equals(entity.getNickName()) && ControllerUtils.verifyHasExist("nickname", userService.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 = userService.update(entity.getId(), entity, userIgnoreProperties);
        if (null != entity) {
            roleUserService.dealRoleUsers(entity.getId(), roleIds);
            logOperateService.save(new LogOperate(site.getId(), admin.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", userService.findByName(site.getId(), entity.getName()), model)) {
            return TEMPLATE_ERROR;
        }
        entity.setDeptId(dept.getId());
        entity.setSiteId(site.getId());
        entity.setPassword(VerificationUtils.md5Encode(entity.getPassword()));
        userService.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(), admin.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) SysDept(com.publiccms.entities.sys.SysDept) 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

LogOperate (com.publiccms.entities.log.LogOperate)4 SysRoleUser (com.publiccms.entities.sys.SysRoleUser)4 SysSite (com.publiccms.entities.sys.SysSite)4 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)4 SysRoleUserId (com.publiccms.entities.sys.SysRoleUserId)3 SysUser (com.publiccms.entities.sys.SysUser)3 SysDept (com.publiccms.entities.sys.SysDept)2 SysRole (com.publiccms.entities.sys.SysRole)2 SysDomain (com.publiccms.entities.sys.SysDomain)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1