🍎 新增api可关闭选项

pull/18/head
ruibaby 2018-06-28 00:32:14 +08:00
parent 77f1dda005
commit 129106a2ae
5 changed files with 143 additions and 12 deletions

View File

@ -1,5 +1,6 @@
package cc.ryanc.halo.config; package cc.ryanc.halo.config;
import cc.ryanc.halo.web.interceptor.ApiInterceptor;
import cc.ryanc.halo.web.interceptor.InstallInterceptor; import cc.ryanc.halo.web.interceptor.InstallInterceptor;
import cc.ryanc.halo.web.interceptor.LoginInterceptor; import cc.ryanc.halo.web.interceptor.LoginInterceptor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
@ -30,6 +31,9 @@ public class MvcConfig implements WebMvcConfigurer {
@Autowired @Autowired
private InstallInterceptor installInterceptor; private InstallInterceptor installInterceptor;
@Autowired
private ApiInterceptor apiInterceptor;
/** /**
* *
* *
@ -48,6 +52,8 @@ public class MvcConfig implements WebMvcConfigurer {
.excludePathPatterns("/install") .excludePathPatterns("/install")
.excludePathPatterns("/install/do") .excludePathPatterns("/install/do")
.excludePathPatterns("/static/**"); .excludePathPatterns("/static/**");
registry.addInterceptor(apiInterceptor)
.addPathPatterns("/api/**");
} }
/** /**

View File

@ -325,7 +325,7 @@ public class HaloUtils {
* *
* @param hostIp ip * @param hostIp ip
* @param userName * @param userName
* @param password * @param password password
* @param savePath * @param savePath
* @param fileName * @param fileName
* @param databaseName * @param databaseName
@ -470,7 +470,7 @@ public class HaloUtils {
* *
* @param smtpHost smtpHost * @param smtpHost smtpHost
* @param userName * @param userName
* @param password * @param password password
*/ */
public static void configMail(String smtpHost, String userName, String password) { public static void configMail(String smtpHost, String userName, String password) {
Properties properties = OhMyEmail.defaultConfig(false); Properties properties = OhMyEmail.defaultConfig(false);

View File

@ -0,0 +1,36 @@
package cc.ryanc.halo.web.interceptor;
import cc.ryanc.halo.model.dto.HaloConst;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* @author : RYAN0UP
* @date : 2018/6/28
*/
@Component
public class ApiInterceptor implements HandlerInterceptor {
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
if (StringUtils.equals("true", HaloConst.OPTIONS.get("api_status"))) {
return true;
}
response.sendRedirect("/404");
return false;
}
@Override
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
}
@Override
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
}
}

View File

@ -2,7 +2,7 @@ server:
port: 8090 port: 8090
use-forward-headers: true use-forward-headers: true
undertow: undertow:
io-threads : 2 io-threads: 2
worker-threads: 36 worker-threads: 36
buffer-size: 1024 buffer-size: 1024
directBuffers: true directBuffers: true

View File

@ -17,7 +17,7 @@
</style> </style>
<section class="content-header"> <section class="content-header">
<h1> <h1>
设置 博客设置
<small></small> <small></small>
</h1> </h1>
<ol class="breadcrumb"> <ol class="breadcrumb">
@ -26,7 +26,7 @@
<i class="fa fa-dashboard"></i> 首页</a> <i class="fa fa-dashboard"></i> 首页</a>
</li> </li>
<li><a data-pjax="true" href="#">设置</a></li> <li><a data-pjax="true" href="#">设置</a></li>
<li class="active">网站设置</li> <li class="active">博客设置</li>
</ol> </ol>
</section> </section>
<!-- tab选项卡 --> <!-- tab选项卡 -->
@ -395,12 +395,66 @@
<!-- 附件设置 --> <!-- 附件设置 -->
<div class="tab-pane" id="attach"> <div class="tab-pane" id="attach">
<form method="post" class="form-horizontal" id="attachOptions"> <form method="post" class="form-horizontal" id="attachOptions">
<div class="box-body"> <#--<div class="box-body">-->
<p> <#--<div class="form-group">-->
开发中...<br/> <#--<label class="col-sm-2 control-label">存储位置:</label>-->
可选图片存储在本地或者七牛云等云... <#--<div class="col-sm-4">-->
</p> <#--<label class="radio-inline">-->
</div> <#--<input type="radio" name="attach_loc" value="server" ${((options.attach_loc?default('server'))=='server')?string('checked','')}> 本地服务器-->
<#--</label>-->
<#--<label class="radio-inline">-->
<#--<input type="radio" name="attach_loc" value="upyun" ${((options.attach_loc?if_exists)=='upyun')?string('checked','')}> 又拍云-->
<#--</label>-->
<#--<label class="radio-inline">-->
<#--<input type="radio" name="attach_loc" value="qiniu" ${((options.attach_loc?if_exists)=='qiniu')?string('checked','')}> 七牛云-->
<#--</label>-->
<#--</div>-->
<#--</div>-->
<#--<!-- 原生设置 &ndash;&gt;-->
<#--<div class="server-options" style="display: none">-->
<#--</div>-->
<#--<!-- 又拍云选项 &ndash;&gt;-->
<#--<div class="upyun-options" style="display: none">-->
<#--<div class="form-group">-->
<#--<label for="upyunOssDomain" class="col-sm-2 control-label">域名绑定:</label>-->
<#--<div class="col-sm-4">-->
<#--<input type="text" class="form-control" id="upyunOssDomain" name="upyun_oss_domain" value="${options.upyun_oss_domain?if_exists}">-->
<#--</div>-->
<#--</div>-->
<#--<div class="form-group">-->
<#--<label for="upyunOssBucket" class="col-sm-2 control-label">空间名称:</label>-->
<#--<div class="col-sm-4">-->
<#--<input type="text" class="form-control" id="upyunOssBucket" name="upyun_oss_bucket" value="${options.upyun_oss_bucket?if_exists}">-->
<#--</div>-->
<#--</div>-->
<#--<div class="form-group">-->
<#--<label for="upyunOssOperator" class="col-sm-2 control-label">操作员名称:</label>-->
<#--<div class="col-sm-4">-->
<#--<input type="text" class="form-control" id="upyunOssOperator" name="upyun_oss_operator" value="${options.upyun_oss_operator?if_exists}">-->
<#--</div>-->
<#--</div>-->
<#--<div class="form-group">-->
<#--<label for="upyunOssPwd" class="col-sm-2 control-label">操作员密码:</label>-->
<#--<div class="col-sm-4">-->
<#--<input type="text" class="form-control" id="upyunOssPwd" name="upyun_oss_pwd" value="${options.upyun_oss_pwd?if_exists}">-->
<#--</div>-->
<#--</div>-->
<#--<div class="form-group">-->
<#--<label for="upyunOssSrc" class="col-sm-2 control-label">文件目录:</label>-->
<#--<div class="col-sm-4">-->
<#--<input type="text" class="form-control" id="upyunOssSrc" name="upyun_oss_src" value="${options.upyun_oss_src?if_exists}">-->
<#--</div>-->
<#--</div>-->
<#--</div>-->
<#--<!-- 七牛云 &ndash;&gt;-->
<#--<div class="qiniu-options" style="display: none">-->
<#--</div>-->
<#--</div>-->
<div class="box-footer"> <div class="box-footer">
<button type="button" class="btn btn-primary btn-sm " onclick="saveOptions('attachOptions')">保存</button> <button type="button" class="btn btn-primary btn-sm " onclick="saveOptions('attachOptions')">保存</button>
</div> </div>
@ -529,6 +583,17 @@
<div class="tab-pane" id="other"> <div class="tab-pane" id="other">
<form method="post" class="form-horizontal" id="otherOptions"> <form method="post" class="form-horizontal" id="otherOptions">
<div class="box-body"> <div class="box-body">
<div class="form-group">
<label class="col-sm-2 control-label">API服务</label>
<div class="col-sm-4">
<label class="radio-inline">
<input type="radio" name="api_status" value="true" ${((options.api_status?if_exists)=='true')?string('checked','')}> 启用
</label>
<label class="radio-inline">
<input type="radio" name="api_status" value="false" ${((options.api_status?default('false'))=='false')?string('checked','')}> 禁用
</label>
</div>
</div>
<div class="form-group"> <div class="form-group">
<label for="statisticsCode" class="col-sm-2 control-label">统计代码: <label for="statisticsCode" class="col-sm-2 control-label">统计代码:
<span data-toggle="tooltip" data-placement="top" title="可以使用cnzz百度google等" style="cursor: pointer"> <span data-toggle="tooltip" data-placement="top" title="可以使用cnzz百度google等" style="cursor: pointer">
@ -651,6 +716,27 @@
} }
} }
function checkAttachOption() {
var server = $('input:radio[value=server]:checked').val();
var upyun = $('input:radio[value=upyun]:checked').val();
var qiniu = $('input:radio[value=qiniu]:checked').val();
if(server!=null){
$('.server-options').show();
}else{
$('.server-options').hide();
}
if(upyun!=null){
$('.upyun-options').show();
}else{
$('.upyun-options').hide();
}
if(qiniu!=null){
$('.qiniu-options').show();
}else{
$('.qiniu-options').hide();
}
}
/** /**
* 后台布局切换 * 后台布局切换
*/ */
@ -677,6 +763,9 @@
$('input[name=comment_system]').click(function () { $('input[name=comment_system]').click(function () {
checkCommentOption(); checkCommentOption();
}); });
$('input[name=attach_loc]').click(function () {
checkAttachOption();
});
$('input[name=admin_layout]').click(function () { $('input[name=admin_layout]').click(function () {
viewLayout(); viewLayout();
}); });
@ -706,4 +795,4 @@
<#include "module/_footer.ftl"> <#include "module/_footer.ftl">
</div> </div>
<@footer></@footer> <@footer></@footer>
</#compress> </#compress>