路由
//后台分组
Route::namespace('admins')->middleware(['auth','rightvalidates'])->group(function (){
Route::get('admins/home/index','Home@index');
Route::get('admins/home/welcome','Home@welcome');
//网站设置
Route::get('admins/site/seo','Site@seo');
Route::post('admins/site/save_seo','Site@save_seo');
Route::get('admins/site/security','Site@security');
Route::post('admins/site/save_security','Site@save_security');
});
控制器Site
//调用安全设置菜单数据
public function security(){
$data['setsec'] =DB::table('xpcms_sys_setting')->where('keys','set_security')->first();
if($data['setsec']){
$data['setsec'] = (array)$data['setsec'];
$data['setsec']['values'] = json_decode($data['setsec']['values'],true);
}
return view('admins.site.security',$data);
}
//更新保存安全设置菜单数据
public function save_security(Request $req)
{
$login_faild = trim($req->login_faild);
$visit_time = trim($req->visit_time);
$sys_domain = trim($req->sys_domain);
$log_size = trim($req->log_size);
$use_log = trim($req->use_log);
$key = 'set_security';
$values = json_encode(array('login_faild'=>$login_faild,'visit_time'=>$visit_time,'sys_domain'=>$sys_domain,'log_size'=>$log_size,'use_log'=>$use_log));
//查询数据库,该记录是否存在,存在就更新 不存在就插入
$item = DB::table('xpcms_sys_setting')->where('keys',$key)->first();
if ($item){
DB::table('xpcms_sys_setting')->where('keys',$key)->update(array('values'=>$values));
}else{
DB::table('xpcms_sys_setting')->where('keys',$key)->insert(array('values'=>$values));
}
return json_encode(array('code'=>0,'msg'=>'保存成功'));
}
视图 security.blade.php
<!DOCTYPE html>
<html>
<head>
<title>安全设置</title>
<meta charset="utf-8">
<link rel="stylesheet" href="/static/css/style.css" media="all">
<script type="text/javascript" src="/static/js/jquery3.4.1.js"></script>
<script type="text/javascript" src="/static/layer/layer.js"></script>
<script type="text/javascript" src="/static/js/phpcn.js"></script>
<body>
<div class="phpcn-title">安全设置</div>
<form class="phpcn-form phpcn-bg-fff phpcn-p-10">
@csrf
<div class="phpcn-form-item phpcn-bg-fff ">
<label class="phpcn-form-lable">后台最大登录失败次数:</label>
<div class="phpcn-input-inline">
<input type="text" name="login_faild" placeholder="后台最大登录失败次数" class="phpcn-input" value="{{$setsec['values']['login_faild']}}">
</div>
</div>
<div class="phpcn-form-item phpcn-bg-fff ">
<label class="phpcn-form-lable">每分钟访问次数:</label>
<div class="phpcn-input-inline">
<input type="text" name="visit_time" placeholder="每分钟访问次数" class="phpcn-input" value="{{$setsec['values']['visit_time']}}">
</div>
</div>
<div class="phpcn-form-item phpcn-bg-fff ">
<label class="phpcn-form-lable">后台访问域名:</label>
<div class="phpcn-input-inline">
<input type="text" name="sys_domain" placeholder="后台访问域名" class="phpcn-input" value="{{$setsec['values']['sys_domain']}}">
</div>
</div>
<div class="phpcn-form-item phpcn-bg-fff ">
<label class="phpcn-form-lable">错误日志预警大小:</label>
<div class="phpcn-input-inline">
<input type="text" name="log_size" placeholder="错误日志预警大小" class="phpcn-input" value="{{$setsec['values']['log_size']}}">
</div>
</div>
<div class="phpcn-form-item phpcn-bg-fff ">
<label class="phpcn-form-lable">设置:</label>
<div class="phpcn-input-inline phpcn-form-checkbox2" >
<input type="checkbox" id="use_log" title="启用后台操作日志" value="{{$setsec['values']['use_log']}}" {{$setsec['values']['use_log'] == 1 ? 'checked' : ''}}>
</div>
</div>
<div class="phpcn-form-item phpcn-bg-fff ">
<button class="phpcn-button" type='button' onclick="site_save();">保存</button>
</div>
</form>
</div>
</body>
</html>
<script type="text/javascript">
function site_save() {
var login_faild = $.trim($('input[name="login_faild"]').val());
var visit_time = $.trim($('input[name="visit_time"]').val());
var sys_domain = $.trim($('input[name="sys_domain"]').val());
var log_size = $.trim($('input[name="log_size"]').val());
var use_log = $('#use_log').is(':checked')?1:0;
var _token = $('input[name="_token"]').val();
var data = {login_faild:login_faild,visit_time:visit_time,sys_domain:sys_domain,log_size:log_size,use_log:use_log,_token:_token};
$.post('/admins/site/save_security',data,function (res) {
if(res.code > 0){
return layer.alert(res.msg,{icon:2});
}else{
return layer.msg(res.msg,{icon:1});
}
},'json');
}
</script>