This commit is contained in:
FangfangZhao 2018-10-23 00:31:36 +08:00
parent 5dc396ec78
commit 9250a8cc58
5 changed files with 125 additions and 63 deletions

View file

@ -129,18 +129,23 @@ public class RequestWatchHandler extends HandlerInterceptorAdapter {
*/
public static boolean verfiyPass(HttpServletRequest request, HttpServletResponse response) throws IOException {
request.setAttribute(TIMEOUT_KEY, System.currentTimeMillis());
final String requestURI = request.getRequestURI();
String requestUrl = request.getRequestURI();
String qstr = request.getQueryString();
if (StringUtils.isNotBlank(qstr)) {
requestUrl += "?" + qstr;
}
ID user = AppUtils.getRequestUser(request);
if (user != null) {
Application.getSessionStore().setCurrentCaller(user);
// 管理后台访问
if (requestURI.contains("/admin/") && !AdminEntryControll.isAdminVerified(request)) {
if (requestUrl.contains("/admin/") && !AdminEntryControll.isAdminVerified(request)) {
if (ServletUtils.isAjaxRequest(request)) {
ServletUtils.writeJson(response, AppUtils.formatClientMsg(403, "请验证管理员访问权限"));
} else {
response.sendRedirect(ServerListener.getContextPath() + "/user/entry-admin?nexturl=" + CodecUtils.urlEncode(requestURI));
response.sendRedirect(ServerListener.getContextPath() + "/user/entry-admin?nexturl=" + CodecUtils.urlEncode(requestUrl));
}
return false;
}
@ -148,18 +153,18 @@ public class RequestWatchHandler extends HandlerInterceptorAdapter {
} else {
boolean isIgnore = false;
for (String r : IGNORE_RES) {
if (requestURI.contains(r)) {
if (requestUrl.contains(r)) {
isIgnore = true;
break;
}
}
if (!isIgnore) {
LOG.warn("Unauthorized access [ " + requestURI + " ] from [ " + ServletUtils.getReferer(request) + " ]");
LOG.warn("Unauthorized access [ " + requestUrl + " ] from [ " + ServletUtils.getReferer(request) + " ]");
if (ServletUtils.isAjaxRequest(request)) {
ServletUtils.writeJson(response, AppUtils.formatClientMsg(403, "未授权访问"));
} else {
response.sendRedirect(ServerListener.getContextPath() + "/user/login?nexturl=" + CodecUtils.urlEncode(requestURI));
response.sendRedirect(ServerListener.getContextPath() + "/user/login?nexturl=" + CodecUtils.urlEncode(requestUrl));
}
return false;
}

View file

@ -0,0 +1,97 @@
/*
rebuild - Building your system freely.
Copyright (C) 2018 devezhao <zhaofang123@gmail.com>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.rebuild.web.admin.entity;
import java.io.IOException;
import java.util.HashSet;
import java.util.Set;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import com.alibaba.fastjson.JSON;
import com.rebuild.server.Application;
import com.rebuild.server.entityhub.EasyMeta;
import com.rebuild.server.helper.manager.ViewTabManager;
import com.rebuild.server.metadata.EntityHelper;
import com.rebuild.server.metadata.MetadataHelper;
import com.rebuild.utils.JSONUtils;
import com.rebuild.web.BaseControll;
import com.rebuild.web.LayoutConfig;
import cn.devezhao.commons.web.ServletUtils;
import cn.devezhao.persist4j.Entity;
import cn.devezhao.persist4j.Field;
import cn.devezhao.persist4j.Record;
import cn.devezhao.persist4j.engine.ID;
/**
*
* @author devezhao
* @since 10/23/2018
*/
@Controller
@RequestMapping("/admin/entity/")
public class ViewTabControll extends BaseControll implements LayoutConfig {
@RequestMapping(value = "{entity}/viewtab-config", method = RequestMethod.POST)
@Override
public void sets(@PathVariable String entity,
HttpServletRequest request, HttpServletResponse response) throws IOException {
ID user = getRequestUser(request);
JSON config = ServletUtils.getRequestJson(request);
Object[] vtab = ViewTabManager.getRaw(entity);
Record record = null;
if (vtab == null) {
record = EntityHelper.forNew(EntityHelper.ViewTabConfig, user);
record.setString("belongEntity", entity);
} else {
record = EntityHelper.forUpdate((ID) vtab[0], user);
}
record.setString("config", config.toJSONString());
Application.getCommonService().createOrUpdate(record);
writeSuccess(response);
}
@RequestMapping(value = "{entity}/viewtab-config", method = RequestMethod.GET)
@Override
public void gets(@PathVariable String entity,
HttpServletRequest request, HttpServletResponse response) throws IOException {
Object[] vtab = ViewTabManager.getRaw(entity);
Entity entityMeta = MetadataHelper.getEntity(entity);
Set<String[]> refs = new HashSet<>();
for (Field field : entityMeta.getReferenceToFields()) {
Entity e = field.getOwnEntity();
refs.add(new String[] { e.getName(), EasyMeta.getLabel(e) });
}
JSON ret = JSONUtils.toJSONObject(
new String[] { "config", "refs" },
new Object[] { vtab == null ? null : vtab[1], refs });
writeSuccess(response, ret);
}
}

View file

@ -32,27 +32,20 @@ import org.apache.commons.lang.ArrayUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.math.NumberUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import com.alibaba.fastjson.JSON;
import com.rebuild.server.Application;
import com.rebuild.server.entityhub.EasyMeta;
import com.rebuild.server.helper.manager.FieldValueWrapper;
import com.rebuild.server.helper.manager.ViewTabManager;
import com.rebuild.server.metadata.EntityHelper;
import com.rebuild.server.metadata.MetadataHelper;
import com.rebuild.utils.JSONUtils;
import com.rebuild.web.BaseControll;
import com.rebuild.web.LayoutConfig;
import cn.devezhao.commons.CalendarUtils;
import cn.devezhao.commons.ObjectUtils;
import cn.devezhao.commons.web.ServletUtils;
import cn.devezhao.persist4j.Entity;
import cn.devezhao.persist4j.Field;
import cn.devezhao.persist4j.Record;
import cn.devezhao.persist4j.dialect.FieldType;
import cn.devezhao.persist4j.engine.ID;
@ -63,10 +56,10 @@ import cn.devezhao.persist4j.engine.ID;
* @since 10/22/2018
*/
@Controller
@RequestMapping("/app/")
public class RelatedListControll extends BaseControll implements LayoutConfig {
@RequestMapping("/app/entity/")
public class RelatedListControll extends BaseControll {
@RequestMapping("entity/related-list")
@RequestMapping("related-list")
public void relatedList(HttpServletRequest request, HttpServletResponse response) throws IOException {
ID masterId = getIdParameterNotNull(request, "master");
String related = getParameterNotNull(request, "related");
@ -93,7 +86,7 @@ public class RelatedListControll extends BaseControll implements LayoutConfig {
writeSuccess(response, ret);
}
@RequestMapping("entity/related-counts")
@RequestMapping("related-counts")
public void relatedCounts(HttpServletRequest request, HttpServletResponse response) throws IOException {
ID masterId = getIdParameterNotNull(request, "master");
String relates[] = getParameterNotNull(request, "relates").split(",");
@ -139,46 +132,4 @@ public class RelatedListControll extends BaseControll implements LayoutConfig {
}
return baseSql;
}
// --
@RequestMapping(value = "{entity}/viewtab-settings", method = RequestMethod.POST)
@Override
public void sets(@PathVariable String entity,
HttpServletRequest request, HttpServletResponse response) throws IOException {
ID user = getRequestUser(request);
JSON config = ServletUtils.getRequestJson(request);
Object[] vtab = ViewTabManager.getRaw(entity);
Record record = null;
if (vtab == null) {
record = EntityHelper.forNew(EntityHelper.ViewTabConfig, user);
record.setString("belongEntity", entity);
} else {
record = EntityHelper.forUpdate((ID) vtab[0], user);
}
record.setString("config", config.toJSONString());
Application.getCommonService().createOrUpdate(record);
writeSuccess(response);
}
@RequestMapping(value = "{entity}/viewtab-settings", method = RequestMethod.GET)
@Override
public void gets(@PathVariable String entity,
HttpServletRequest request, HttpServletResponse response) throws IOException {
Object[] vtab = ViewTabManager.getRaw(entity);
Entity entityMeta = MetadataHelper.getEntity(entity);
Set<String[]> refs = new HashSet<>();
for (Field field : entityMeta.getReferenceToFields()) {
Entity e = field.getOwnEntity();
refs.add(new String[] { e.getName(), EasyMeta.getLabel(e) });
}
JSON ret = JSONUtils.toJSONObject(
new String[] { "config", "refs" },
new Object[] { vtab == null ? null : vtab[1], refs });
writeSuccess(response, ret);
}
}

View file

@ -32,7 +32,7 @@
<script type="text/javascript">
$(document).ready(function(){
const entity = $urlp('entity')
$.get(rb.baseUrl + '/app/' + entity + '/viewtab-settings', function(res){
$.get(rb.baseUrl + '/admin/entity/' + entity + '/viewtab-config', function(res){
$(res.data.refs).each(function(){ render_unset(this) })
$(res.data.config).each(function(){
$('.unset-list li[data-key="' + this + '"]').trigger('click')
@ -47,7 +47,7 @@ $(document).ready(function(){
});
let btn = $(this).button('loading')
$.post(rb.baseUrl + '/app/' + entity + '/viewtab-settings', JSON.stringify(config), function(res){
$.post(rb.baseUrl + '/admin/entity/' + entity + '/viewtab-config', JSON.stringify(config), function(res){
btn.button('reset')
if (res.error_code == 0) parent.location.reload()
});

View file

@ -41,13 +41,22 @@ $(document).ready(function(){
let nexturl = decodeURIComponent($urlp('nexturl') || '../admin/systems')
$('.J_verify-btn').click(function(){
let passwd = $val('#admin-passwd')
if (!!!passwd) return
if (!!!passwd) return false
let but = $(this).button('loading')
$.post('admin-verify?passwd=' + passwd, function(res) {
if (res.error_code == 0) location.replace(nexturl)
else rb.notice(res.error_msg)
else{
rb.notice(res.error_msg)
but.button('reset')
}
})
return false
})
if (self != top && $(window).width() < 800){
$('.splash-footer, .navbar').remove()
$('.rb-wrapper').addClass('pt-0')
}
})
</script>
</body>