博客列表 >2020-1-7:后台开发-->网站设置--安全设置菜单开发

2020-1-7:后台开发-->网站设置--安全设置菜单开发

Rambo-Yang
Rambo-Yang原创
2020年01月09日 15:52:01794浏览

路由

  1. //后台分组
  2. Route::namespace('admins')->middleware(['auth','rightvalidates'])->group(function (){
  3. Route::get('admins/home/index','Home@index');
  4. Route::get('admins/home/welcome','Home@welcome');
  5. //网站设置
  6. Route::get('admins/site/seo','Site@seo');
  7. Route::post('admins/site/save_seo','Site@save_seo');
  8. Route::get('admins/site/security','Site@security');
  9. Route::post('admins/site/save_security','Site@save_security');
  10. });

控制器Site

  1. //调用安全设置菜单数据
  2. public function security(){
  3. $data['setsec'] =DB::table('xpcms_sys_setting')->where('keys','set_security')->first();
  4. if($data['setsec']){
  5. $data['setsec'] = (array)$data['setsec'];
  6. $data['setsec']['values'] = json_decode($data['setsec']['values'],true);
  7. }
  8. return view('admins.site.security',$data);
  9. }
  10. //更新保存安全设置菜单数据
  11. public function save_security(Request $req)
  12. {
  13. $login_faild = trim($req->login_faild);
  14. $visit_time = trim($req->visit_time);
  15. $sys_domain = trim($req->sys_domain);
  16. $log_size = trim($req->log_size);
  17. $use_log = trim($req->use_log);
  18. $key = 'set_security';
  19. $values = json_encode(array('login_faild'=>$login_faild,'visit_time'=>$visit_time,'sys_domain'=>$sys_domain,'log_size'=>$log_size,'use_log'=>$use_log));
  20. //查询数据库,该记录是否存在,存在就更新 不存在就插入
  21. $item = DB::table('xpcms_sys_setting')->where('keys',$key)->first();
  22. if ($item){
  23. DB::table('xpcms_sys_setting')->where('keys',$key)->update(array('values'=>$values));
  24. }else{
  25. DB::table('xpcms_sys_setting')->where('keys',$key)->insert(array('values'=>$values));
  26. }
  27. return json_encode(array('code'=>0,'msg'=>'保存成功'));
  28. }

视图 security.blade.php

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>安全设置</title>
  5. <meta charset="utf-8">
  6. <link rel="stylesheet" href="/static/css/style.css" media="all">
  7. <script type="text/javascript" src="/static/js/jquery3.4.1.js"></script>
  8. <script type="text/javascript" src="/static/layer/layer.js"></script>
  9. <script type="text/javascript" src="/static/js/phpcn.js"></script>
  10. <body>
  11. <div class="phpcn-title">安全设置</div>
  12. <form class="phpcn-form phpcn-bg-fff phpcn-p-10">
  13. @csrf
  14. <div class="phpcn-form-item phpcn-bg-fff ">
  15. <label class="phpcn-form-lable">后台最大登录失败次数:</label>
  16. <div class="phpcn-input-inline">
  17. <input type="text" name="login_faild" placeholder="后台最大登录失败次数" class="phpcn-input" value="{{$setsec['values']['login_faild']}}">
  18. </div>
  19. </div>
  20. <div class="phpcn-form-item phpcn-bg-fff ">
  21. <label class="phpcn-form-lable">每分钟访问次数:</label>
  22. <div class="phpcn-input-inline">
  23. <input type="text" name="visit_time" placeholder="每分钟访问次数" class="phpcn-input" value="{{$setsec['values']['visit_time']}}">
  24. </div>
  25. </div>
  26. <div class="phpcn-form-item phpcn-bg-fff ">
  27. <label class="phpcn-form-lable">后台访问域名:</label>
  28. <div class="phpcn-input-inline">
  29. <input type="text" name="sys_domain" placeholder="后台访问域名" class="phpcn-input" value="{{$setsec['values']['sys_domain']}}">
  30. </div>
  31. </div>
  32. <div class="phpcn-form-item phpcn-bg-fff ">
  33. <label class="phpcn-form-lable">错误日志预警大小:</label>
  34. <div class="phpcn-input-inline">
  35. <input type="text" name="log_size" placeholder="错误日志预警大小" class="phpcn-input" value="{{$setsec['values']['log_size']}}">
  36. </div>
  37. </div>
  38. <div class="phpcn-form-item phpcn-bg-fff ">
  39. <label class="phpcn-form-lable">设置:</label>
  40. <div class="phpcn-input-inline phpcn-form-checkbox2" >
  41. <input type="checkbox" id="use_log" title="启用后台操作日志" value="{{$setsec['values']['use_log']}}" {{$setsec['values']['use_log'] == 1 ? 'checked' : ''}}>
  42. </div>
  43. </div>
  44. <div class="phpcn-form-item phpcn-bg-fff ">
  45. <button class="phpcn-button" type='button' onclick="site_save();">保存</button>
  46. </div>
  47. </form>
  48. </div>
  49. </body>
  50. </html>
  51. <script type="text/javascript">
  52. function site_save() {
  53. var login_faild = $.trim($('input[name="login_faild"]').val());
  54. var visit_time = $.trim($('input[name="visit_time"]').val());
  55. var sys_domain = $.trim($('input[name="sys_domain"]').val());
  56. var log_size = $.trim($('input[name="log_size"]').val());
  57. var use_log = $('#use_log').is(':checked')?1:0;
  58. var _token = $('input[name="_token"]').val();
  59. var data = {login_faild:login_faild,visit_time:visit_time,sys_domain:sys_domain,log_size:log_size,use_log:use_log,_token:_token};
  60. $.post('/admins/site/save_security',data,function (res) {
  61. if(res.code > 0){
  62. return layer.alert(res.msg,{icon:2});
  63. }else{
  64. return layer.msg(res.msg,{icon:1});
  65. }
  66. },'json');
  67. }
  68. </script>

声明:本文内容转载自脚本之家,由网友自发贡献,版权归原作者所有,如您发现涉嫌抄袭侵权,请联系admin@php.cn 核实处理。
全部评论
文明上网理性发言,请遵守新闻评论服务协议