博客列表 >20-01-07作业 综合实战 【网站后台设置】【安全设置】开发

20-01-07作业 综合实战 【网站后台设置】【安全设置】开发

遗忘了寂寞
遗忘了寂寞原创
2020年01月09日 17:12:55651浏览

网站设置类 Site

  1. <?php
  2. namespace App\Http\Controllers\admins;
  3. use Illuminate\Http\Request;
  4. use App\Http\Controllers\Controller;
  5. use Illuminate\Support\Facades\Auth;
  6. use Illuminate\Support\Facades\DB;
  7. // 后台设置相关
  8. class Site extends Controller{
  9. // SEO设置
  10. public function seo(){
  11. //查询数据库SEO数据
  12. $data['set'] = DB::table('xpcms_sys_setting')->where('keys','site_seo')->item();
  13. if($data['set']){
  14. $data['set']['values'] = json_decode($data['set']['values'],true);
  15. }
  16. return view('admins.site.seo',$data);
  17. }
  18. // 安全设置
  19. public function security(){
  20. //查询数据库SEO数据
  21. $data['set'] = DB::table('xpcms_sys_setting')->where('keys','set_security')->item();
  22. if($data['set']){
  23. $data['set']['values'] = json_decode($data['set']['values'],true);
  24. }
  25. return view('admins.site.security',$data);
  26. }
  27. //设置通用保存
  28. public function save(Request $req){
  29. $keys = $req->keys;
  30. $values =json_encode($req->values);
  31. $item = DB::table('xpcms_sys_setting')->where('keys',$keys)->item();
  32. if($item){
  33. DB::table('xpcms_sys_setting')->where('keys',$keys)->update(['values'=>$values]);
  34. }else{
  35. DB::table('xpcms_sys_setting')->insert(['keys'=>$keys,'values'=>$values]);
  36. }
  37. return json_encode(array('code'=>0,'msg'=>'保存成功'));
  38. }
  39. }

路由

  1. <?php
  2. /*
  3. |--------------------------------------------------------------------------
  4. | Web Routes
  5. |--------------------------------------------------------------------------
  6. |
  7. | Here is where you can register web routes for your application. These
  8. | routes are loaded by the RouteServiceProvider within a group which
  9. | contains the "web" middleware group. Now create something great!
  10. |
  11. */
  12. Route::get('/', function () {
  13. return view('welcome');
  14. });
  15. //后台登录
  16. Route::get('/admins/Account/login','admins\Account@login')->name('login');
  17. //验证码
  18. Route::get('/admins/account/captcha','admins\Account@captcha');
  19. //处理登录
  20. Route::post('/admins/account/dologin','admins\Account@dologin');
  21. // Route::get('/admins/home/index','admins\Home@index');
  22. // 后台分组
  23. Route::namespace('admins')->middleware(['auth','rightvalidates'])->group(function(){
  24. Route::get('/admins/home/index','Home@index');
  25. Route::get('/admins/home/welcome','Home@welcome');
  26. // 网站设置
  27. Route::get('/admins/site/seo','Site@seo');
  28. Route::get('/admins/site/security','Site@security');
  29. Route::post('/admins/site/save','Site@save');
  30. });

视图security.blade.php

  1. <!DOCTYPE html>
  2. <html lang="zh">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <meta http-equiv="X-UA-Compatible" content="ie=edge">
  7. <link rel="shortcut icon" type="imege/x-icon" href="/static/img/tj_footlogo.png" />
  8. <link rel="stylesheet" href="/layui/css/layui.css" media="all">
  9. <script src="/static/js/jquery3.4.1.js"></script>
  10. <script type="text/javascript" src="/layui/layui.js"></script>
  11. </head>
  12. <body>
  13. <form class="layui-form" action="">
  14. <div>
  15. <div style="padding: 10px;text-align:center;line-height: 40px;"><h1>安全设置</h1></div>
  16. @csrf
  17. <div class="layui-form-item">
  18. <label class="layui-form-label">失败次数</label>
  19. <div class="layui-input-inline">
  20. <input type="text" name="login_faild" id="login_faild" required lay-verify="required" autocomplete="off" class="layui-input" value="{{$set['values']['login_faild']}}">
  21. </div>
  22. <div class="layui-form-mid layui-word-aux">登录失败次数</div>
  23. </div>
  24. <div class="layui-form-item">
  25. <label class="layui-form-label">过期时间</label>
  26. <div class="layui-input-inline">
  27. <input type="text" name="visit_time" id="visit_time" required lay-verify="required" autocomplete="off" class="layui-input" value="{{$set['values']['visit_time']}}">
  28. </div>
  29. <div class="layui-form-mid layui-word-aux"></div>
  30. </div>
  31. <div class="layui-form-item">
  32. <label class="layui-form-label">日志</label>
  33. <div class="layui-input-block">
  34. <input type="checkbox" name="use_log" id="use_log" lay-skin="switch" lay-text="开启|关闭" value="1" @if($set['values']['use_log']==1) checked="checked" @endif>
  35. </div>
  36. </div>
  37. <div class="layui-form-item">
  38. <label class="layui-form-label">日志大小</label>
  39. <div class="layui-input-inline">
  40. <input type="text" name="log_size" id="log_size" required lay-verify="required" autocomplete="off" class="layui-input" value="{{$set['values']['log_size']}}">
  41. </div>
  42. <div class="layui-form-mid layui-word-aux"></div>
  43. </div>
  44. <div class="layui-form-item">
  45. <label class="layui-form-label">域名</label>
  46. <div class="layui-input-block">
  47. <input type="text" name="sys_domain" id="sys_domain" required lay-verify="required" autocomplete="off" class="layui-input" value="{{$set['values']['sys_domain']}}">
  48. </div>
  49. </div>
  50. <div class="layui-form-item">
  51. <div class="layui-input-block">
  52. <input name="keys" type="hidden" id="keys" value="{{$set['keys']}}" />
  53. <button class="layui-btn" type="button" onclick="site_save();">立即提交</button>
  54. <button type="reset" class="layui-btn layui-btn-primary">重置</button>
  55. </div>
  56. </div>
  57. </div>
  58. </form>
  59. <script type="text/javascript">
  60. layui.use(['element','layer','form'], function(){
  61. var element = layui.element;
  62. var layer = layui.layer;
  63. var form = layui.form;
  64. });
  65. function site_save(){
  66. var keys=$.trim($('#keys').val());
  67. var values=new Object();
  68. values.login_faild= $.trim($('#login_faild').val());
  69. values.visit_time=$.trim($('#visit_time').val());
  70. values.use_log=$.trim($('#use_log:checked').val());
  71. if(values.use_log !=1){
  72. values.use_log=0;
  73. }
  74. values.log_size=$.trim($('#log_size').val());
  75. values.sys_domain=$.trim($('#sys_domain').val());
  76. var _token = $('input[name="_token"]').val();
  77. $.post('/admins/site/save',{keys:keys,values:values,_token:_token},function(res){
  78. if(res.code>0){
  79. return layer.alert(res.msg,{icon:2});
  80. }else{
  81. return layer.msg(res.msg,{icon:1});
  82. }
  83. },'json')
  84. }
  85. </script>
  86. </body>
  87. </html>


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