Skip to content

Commit c7bdce0

Browse files
committedDec 24, 2022
更新:优化发帖改帖
·
v2.7.7v2.1.7
1 parent 6f10ed6 commit c7bdce0

File tree

20 files changed

+123
-3208
lines changed

20 files changed

+123
-3208
lines changed
 

‎app/Middleware/CsrfMiddleware.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
3636
if(request()->isMethod("post") && csrf_token() !== request()->input("_token")) {
3737
return admin_abort(["msg" => "会话超时,请刷新后重新提交"],419);
3838
}
39-
4039
return $handler->handle($request);
4140
}
4241

‎app/Plugins/Topic/resources/views/create.blade.php

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,30 @@
5252
<h3 class="card-title">附加信息</h3>
5353
</div>
5454
<div class="card-body">
55-
<div class="row">
56-
@foreach(Itf()->get('topic-create-options') as $k=>$v)
57-
@if(call_user_func($v['enable'])===true)
58-
@include($v['view'])
59-
@endif
60-
@endforeach
61-
</div>
55+
<div class="row">
56+
@foreach(Itf()->get('topic-create-options') as $k=>$v)
57+
@if(call_user_func($v['enable'])===true)
58+
@include($v['view'])
59+
@endif
60+
@endforeach
61+
</div>
62+
</div>
63+
</div>
64+
</div>
65+
<div class="col-12">
66+
<div class="row row-cards">
67+
<div class="col-lg-9">
68+
<div class="card card-body">
69+
<label for="" class="form-label">验证码</label>
70+
<div class="input-group">
71+
<input type="text" name="captcha" class="form-control" placeholder="captcha"
72+
autocomplete="off" required>
73+
<span class="input-group-link">
74+
<img class="captcha" src="{{captcha()->inline()}}" alt=""
75+
onclick="this.src='/captcha?id='+Math.random()">
76+
</span>
77+
</div>
78+
</div>
6279
</div>
6380
</div>
6481
</div>

‎app/Plugins/Topic/resources/views/create/basis.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
</option>
1313
@foreach(\App\Plugins\Topic\src\Models\TopicTag::query()->where('status','=',null)->get() as $topic_tags)
1414
<option value="{{$topic_tags->id}}"
15-
data-custom-properties="&lt;span class=&quot;badge&quot; style=&quot;background-color: {{$topic_tags->color}} &quot; &gt;{{$topic_tags->icon}}&lt;/span&gt;">
15+
data-custom-properties="&lt;span class=&quot;badge&quot; style=&quot;background-color: {{$topic_tags->color}} &quot; &gt;{{$topic_tags->icon}}&lt;/span&gt;" @if(request()->input('basis.tag') && request()->input('basis.tag')==$topic_tags->id){{"selected"}}@endif>
1616
{{$topic_tags->name}}
1717
</option>
1818
@endforeach

‎app/Plugins/Topic/resources/views/create/preview.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
<link href="{{ file_hash("css/diy.css") }}" rel="stylesheet"/>
2424
<link rel="stylesheet" href="{{mix('css/app.css')}}">
2525
<script>
26-
var csrf_token = "{{ recsrf_token() }}";
26+
var csrf_token = "{{ csrf_token() }}";
2727
var ws_url = "{{ws_url()}}";
2828
var _token = "{{auth()->token()}}";
2929
var imageUpUrl = "/user/upload/image?_token={{ csrf_token() }}";

‎app/Plugins/Topic/resources/views/edit.blade.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,26 @@
6464
</div>
6565
</div>
6666
</div>
67+
<div class="col-12">
68+
<div class="row row-cards">
69+
<div class="col-lg-9">
70+
<div class="card card-body">
71+
<label for="" class="form-label">验证码</label>
72+
<div class="input-group">
73+
<input type="text" name="captcha" class="form-control" placeholder="captcha"
74+
autocomplete="off" required>
75+
<span class="input-group-link">
76+
<img class="captcha" src="{{captcha()->inline()}}" alt=""
77+
onclick="this.src='/captcha?id='+Math.random()">
78+
</span>
79+
</div>
80+
</div>
81+
</div>
82+
</div>
83+
</div>
6784
<div class="col-12">
6885
@csrf()
69-
<button class="btn btn-primary" type="submit">提交</button>
86+
<button timeout="1500" auto-event="disabled" class="btn btn-primary" type="submit">提交</button>
7087
</div>
7188
</div>
7289
</form>

‎app/Plugins/Topic/src/Controllers/TopicController.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
use Hyperf\HttpServer\Annotation\GetMapping;
2525
use Hyperf\HttpServer\Annotation\Middleware;
2626
use Hyperf\HttpServer\Annotation\PostMapping;
27+
use Hyperf\RateLimit\Annotation\RateLimit;
2728

2829
#[Controller(prefix: '/topic')]
2930
#[Middleware(\App\Plugins\User\src\Middleware\AuthMiddleware::class)]
@@ -100,6 +101,7 @@ public function edit($topic_id)
100101
}
101102

102103
#[PostMapping(path: '/topic/update')]
104+
#[RateLimit(create:1, capacity:1, consume:1)]
103105
public function edit_post()
104106
{
105107
$quanxian = false;
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
/**
5+
* This file is part of zhuchunshu.
6+
* @link https://github.com/zhuchunshu
7+
* @document https://github.com/zhuchunshu/super-forum
8+
* @contact laravel@88.com
9+
* @license https://github.com/zhuchunshu/super-forum/blob/master/LICENSE
10+
*/
11+
namespace App\Plugins\Topic\src\Handler\Topic\Middleware\Create;
12+
13+
use App\Plugins\Topic\src\Handler\Topic\Middleware\MiddlewareInterface;
14+
15+
#[\App\Plugins\Topic\src\Annotation\Topic\CreateFirstMiddleware]
16+
class CaptchaMiddleware implements MiddlewareInterface
17+
{
18+
public function handler($data, \Closure $next)
19+
{
20+
if (! captcha()->check(request()->input('captcha'))) {
21+
unset($data['basis']['content']);
22+
return redirect()->with('danger', '验证码错误')->url('topic/create?' . http_build_query($data))->go();
23+
}
24+
return $next($data);
25+
}
26+
}

‎app/Plugins/Topic/src/Handler/Topic/Middleware/Create/CreateMiddleware.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ public function handler($data, \Closure $next)
3636
'title' => 'required|string|min:' . get_options('topic_create_title_min', 1) . '|max:' . get_options('topic_create_title_max', 200),
3737
'tag' => 'required|exists:topic_tag,id',
3838
],
39+
[],
3940
[
4041
'content' => '内容',
4142
'title' => '标题',
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
/**
5+
* This file is part of zhuchunshu.
6+
* @link https://github.com/zhuchunshu
7+
* @document https://github.com/zhuchunshu/super-forum
8+
* @contact laravel@88.com
9+
* @license https://github.com/zhuchunshu/super-forum/blob/master/LICENSE
10+
*/
11+
namespace App\Plugins\Topic\src\Handler\Topic\Middleware\Update;
12+
13+
use App\Plugins\Topic\src\Handler\Topic\Middleware\MiddlewareInterface;
14+
15+
#[\App\Plugins\Topic\src\Annotation\Topic\UpdateFirstMiddleware]
16+
class CaptchaMiddleware implements MiddlewareInterface
17+
{
18+
public function handler($data, \Closure $next)
19+
{
20+
if (! captcha()->check(request()->input('captcha'))) {
21+
return redirect()->url('/' . $data['basis']['topic_id'] . '.html')->with('danger', '验证码错误')->go();
22+
}
23+
return $next($data);
24+
}
25+
}

‎app/Plugins/Topic/src/Handler/Topic/Middleware/Update/UpdateMiddleware.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ public function handler($data, \Closure $next)
3838
'title' => 'required|string|min:' . get_options('topic_create_title_min', 1) . '|max:' . get_options('topic_create_title_max', 200),
3939
'tag' => 'required|exists:topic_tag,id',
4040
],
41+
[],
4142
[
4243
'topic_id' => '帖子id',
4344
'content' => '正文内容',

‎app/Themes/CodeFec/resources/views/app.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
<link href="{{ file_hash("css/diy.css") }}" rel="stylesheet" />
1717
<link rel="stylesheet" href="{{mix('css/app.css')}}">
1818
<script>
19-
var csrf_token = "{{ recsrf_token() }}";
19+
var csrf_token = "{{ csrf_token() }}";
2020
var ws_url = "{{ws_url()}}";
2121
var _token = "{{auth()->token()}}";
2222
var imageUpUrl = "/user/upload/image?_token={{ csrf_token() }}";

‎app/Themes/CodeFec/resources/views/topic/show/content.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
{{__('app.essence')}}
1818
</div>
1919
@endif
20-
<div class="row">
20+
<div class="row" style="margin-top: -10px">
2121
{{-- 标题--}}
2222
<div class="col-md-12" id="title">
2323
<h1 data-bs-toggle="tooltip" data-bs-placement="left" title="{{__('topic.title')}}">

‎app/Themes/CodeFec/resources/views/user/sign.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
<link rel="stylesheet" href="{{mix("plugins/Core/css/core.css")}}">
2323
<link href="{{ file_hash("css/diy.css") }}" rel="stylesheet" />
2424
<script>
25-
var csrf_token = "{{ recsrf_token() }}";
25+
var csrf_token = "{{ csrf_token() }}";
2626
var ws_url = "{{ws_url()}}";
2727
var login_token = "{{auth()->token()}}";
2828
</script>

‎app/View/Component/CsrfToken.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class CsrfToken extends Component
1010
public $token;
1111
public function __construct()
1212
{
13-
$this->token = recsrf_token();
13+
$this->token = csrf_token();
1414
}
1515
public function render()
1616
{

‎app/helpers.php

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -498,15 +498,27 @@ function csrf_token()
498498
}
499499
}
500500

501+
if (! function_exists('csrf_token')) {
502+
function csrf_token()
503+
{
504+
if (! session()->has('csrf_token')) {
505+
session()->set('csrf_token', Str::random());
506+
}
507+
if (! cache()->has('csrf_token.' . session()->get('csrf_token'))) {
508+
cache()->set('csrf_token.' . session()->get('csrf_token'), Str::random());
509+
}
510+
return cache()->get('csrf_token.' . session()->get('csrf_token'));
511+
}
512+
}
513+
501514
if (! function_exists('recsrf_token')) {
502515
function recsrf_token()
503516
{
504-
return csrf_token();
505-
// if(!session()->has("csrf_token")){
506-
// session()->set("csrf_token",Str::random());
507-
// }
508-
// cache()->set("csrf_token".session()->get("csrf_token"),Str::random(),300);
509-
// return cache()->get("csrf_token".session()->get("csrf_token"));
517+
if (! session()->has('csrf_token')) {
518+
session()->set('csrf_token', Str::random());
519+
}
520+
cache()->set('csrf_token.' . session()->get('csrf_token'), Str::random());
521+
return cache()->get('csrf_token.' . session()->get('csrf_token'));
510522
}
511523
}
512524

‎public/js/alpine.js

Lines changed: 0 additions & 3182 deletions
Large diffs are not rendered by default.

‎public/mix-manifest.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
"/js/app.js": "/js/app.js?id=5f4131c4a24b6dabd927",
33
"/js/install.js": "/js/install.js?id=e2a427dad25f612dc8fb",
44
"/js/vue.js": "/js/vue.js?id=c0ed491e9d9bbd0212ac",
5-
"/js/alpine.js": "/js/alpine.js?id=3b24a5041f6ceb43ef89",
65
"/js/admin/login.js": "/js/admin/login.js?id=da1c592d350b030d748d",
76
"/js/admin/EditFile.js": "/js/admin/EditFile.js?id=4d5216bc31a8a5907c6c",
87
"/js/admin/error.js": "/js/admin/error.js?id=766b20ab83ddf9c42848",
@@ -11,7 +10,7 @@
1110
"/js/admin/index.js": "/js/admin/index.js?id=505f34d21dc046de3d56",
1211
"/js/admin/pay.js": "/js/admin/pay.js?id=476f7157fca67c342d8c",
1312
"/plugins/User/js/order.js": "/plugins/User/js/order.js?id=75d4436e905e45647c23",
14-
"/plugins/Core/js/app.js": "/plugins/Core/js/app.js?id=802dc3d10d90c4074bfb",
13+
"/plugins/Core/js/app.js": "/plugins/Core/js/app.js?id=36611f1c6cc8ab6ed9cb",
1514
"/plugins/Topic/js/topic.js": "/plugins/Topic/js/topic.js?id=2441d18b977cde255036",
1615
"/plugins/Topic/js/core.js": "/plugins/Topic/js/core.js?id=931e8d42fabe735b4daf",
1716
"/plugins/Topic/css/app.css": "/plugins/Topic/css/app.css?id=7a04749a2ef2c33ea28f",

‎resources/js/alpine.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

‎resources/views/app.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<link rel="stylesheet" href="{{ mix('css/app.css') }}">
1616
<link rel="icon" href="{{get_options('theme_common_icon','/logo.svg')}}" type="image/x-icon" />
1717
<link rel="shortcut icon" href="{{get_options('theme_common_icon','/logo.svg')}}" type="image/x-icon" />
18-
<script>var csrf_token="{{recsrf_token()}}";</script>
18+
<script>var csrf_token="{{csrf_token()}}";</script>
1919
<link rel="stylesheet" href="{{ mix('iziToast/css/iziToast.min.css') }}">
2020
<script src="{{ mix('iziToast/js/iziToast.min.js') }}"></script>
2121
<!-- 自定义CSS -->

‎webpack.mix.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ mix.js(resources_path("js/install.js"), "js").version();
2323

2424
// vue.js
2525
mix.js(resources_path("js/vue.js"), "js").vue({version: 3})
26-
mix.js(resources_path("js/alpine.js"), "js")
2726
.webpackConfig((webpack) => {
2827
return {
2928
plugins: [

0 commit comments

Comments
 (0)
Please sign in to comment.