use of com.publiccms.entities.sys.SysDomain in project PublicCMS-preview by sanluan.
the class SysDomainDirective method execute.
@Override
public void execute(RenderHandler handler) throws IOException, Exception {
String id = handler.getString("id");
if (CommonUtils.notEmpty(id)) {
SysDomain entity = service.getEntity(id);
if (null != entity) {
handler.put("object", entity).render();
}
} else {
String[] ids = handler.getStringArray("ids");
if (CommonUtils.notEmpty(ids)) {
List<SysDomain> entityList = service.getEntitys(ids);
Map<String, SysDomain> map = new LinkedHashMap<>();
for (SysDomain entity : entityList) {
map.put(String.valueOf(entity.getName()), entity);
}
handler.put("map", map).render();
}
}
}
use of com.publiccms.entities.sys.SysDomain 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;
}
use of com.publiccms.entities.sys.SysDomain in project PublicCMS-preview by sanluan.
the class SiteComponent method getDomain.
/**
* @param serverName
* @return domain
*/
public SysDomain getDomain(String serverName) {
SysDomain sysDomain = domainCache.get(serverName);
if (null == sysDomain) {
sysDomain = sysDomainService.getEntity(serverName);
if (null == sysDomain) {
int index;
if (null != serverName && 0 < (index = serverName.indexOf(DOT)) && index != serverName.lastIndexOf(DOT)) {
sysDomain = getDomain(serverName.substring(index + 1));
if (null != sysDomain.getName()) {
if (!sysDomain.isWild()) {
sysDomain = new SysDomain();
sysDomain.setSiteId(defaultSiteId);
}
}
} else {
sysDomain = new SysDomain();
sysDomain.setSiteId(defaultSiteId);
}
} else {
domainCache.put(serverName, sysDomain);
}
}
return sysDomain;
}
use of com.publiccms.entities.sys.SysDomain in project PublicCMS-preview by sanluan.
the class SiteComponent method getViewNamePrefix.
/**
* @param serverName
* @return view name prefix
*/
public String getViewNamePrefix(String serverName) {
SysDomain sysDomain = getDomain(serverName);
SysSite site = getSite(serverName);
return getViewNamePrefix(site, sysDomain);
}
use of com.publiccms.entities.sys.SysDomain in project PublicCMS-preview by sanluan.
the class IndexController method getViewName.
private String getViewName(Long id, Integer pageIndex, String requestPath, String body, HttpServletRequest request, HttpServletResponse response, ModelMap model) {
SysDomain domain = getDomain(request);
SysSite site = getSite(request);
String fullRequestPath = siteComponent.getViewNamePrefix(site, domain) + requestPath;
String templatePath = siteComponent.getWebTemplateFilePath() + fullRequestPath;
CmsPageMetadata metadata = metadataComponent.getTemplateMetadata(templatePath);
if (metadata.isUseDynamic()) {
if (metadata.isNeedLogin() && null == getUserFromSession(request.getSession())) {
Map<String, String> config = configComponent.getConfigData(site.getId(), Config.CONFIG_CODE_SITE);
String loginPath = config.get(LoginConfigComponent.CONFIG_LOGIN_PATH);
StringBuilder sb = new StringBuilder(REDIRECT);
if (CommonUtils.notEmpty(loginPath)) {
return sb.append(loginPath).append("?returnUrl=").append(RequestUtils.getEncodePath(requestPath, request.getQueryString())).toString();
} else {
return sb.append(site.getDynamicPath()).toString();
}
}
String[] acceptParamters = StringUtils.split(metadata.getAcceptParamters(), COMMA_DELIMITED);
if (CommonUtils.notEmpty(acceptParamters)) {
billingRequestParamtersToModel(request, acceptParamters, model);
if (null != id && ArrayUtils.contains(acceptParamters, "id")) {
model.addAttribute("id", id.toString());
if (null != pageIndex && ArrayUtils.contains(acceptParamters, "pageIndex")) {
model.addAttribute("pageIndex", pageIndex.toString());
}
}
}
model.addAttribute("metadata", metadata);
if (metadata.isNeedBody()) {
model.addAttribute("body", body);
}
if (CommonUtils.notEmpty(metadata.getContentType())) {
response.setContentType(metadata.getContentType());
}
if (CommonUtils.notEmpty(metadata.getCacheTime()) && 0 < metadata.getCacheTime()) {
int cacheMillisTime = metadata.getCacheTime() * 1000;
String cacheControl = request.getHeader("Cache-Control");
String pragma = request.getHeader("Pragma");
if (CommonUtils.notEmpty(cacheControl) && "no-cache".equalsIgnoreCase(cacheControl) || CommonUtils.notEmpty(pragma) && "no-cache".equalsIgnoreCase(pragma)) {
cacheMillisTime = 0;
}
return templateCacheComponent.getCachedPath(requestPath, fullRequestPath, cacheMillisTime, acceptParamters, request, model);
}
} else {
try {
response.sendError(HttpServletResponse.SC_NOT_FOUND);
} catch (IOException e) {
}
}
return requestPath;
}
Aggregations