Skip to content

Commit

Permalink
更新:优化发帖改帖
Browse files Browse the repository at this point in the history
  • Loading branch information
zhuchunshu committed Dec 24, 2022
1 parent 6f10ed6 commit c7bdce0
Show file tree
Hide file tree
Showing 20 changed files with 123 additions and 3,208 deletions.
1 change: 0 additions & 1 deletion app/Middleware/CsrfMiddleware.php
Expand Up @@ -36,7 +36,6 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
if(request()->isMethod("post") && csrf_token() !== request()->input("_token")) {
return admin_abort(["msg" => "会话超时,请刷新后重新提交"],419);
}

return $handler->handle($request);
}

Expand Down
31 changes: 24 additions & 7 deletions app/Plugins/Topic/resources/views/create.blade.php
Expand Up @@ -52,13 +52,30 @@
<h3 class="card-title">附加信息</h3>
</div>
<div class="card-body">
<div class="row">
@foreach(Itf()->get('topic-create-options') as $k=>$v)
@if(call_user_func($v['enable'])===true)
@include($v['view'])
@endif
@endforeach
</div>
<div class="row">
@foreach(Itf()->get('topic-create-options') as $k=>$v)
@if(call_user_func($v['enable'])===true)
@include($v['view'])
@endif
@endforeach
</div>
</div>
</div>
</div>
<div class="col-12">
<div class="row row-cards">
<div class="col-lg-9">
<div class="card card-body">
<label for="" class="form-label">验证码</label>
<div class="input-group">
<input type="text" name="captcha" class="form-control" placeholder="captcha"
autocomplete="off" required>
<span class="input-group-link">
<img class="captcha" src="{{captcha()->inline()}}" alt=""
onclick="this.src='/captcha?id='+Math.random()">
</span>
</div>
</div>
</div>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion app/Plugins/Topic/resources/views/create/basis.blade.php
Expand Up @@ -12,7 +12,7 @@
</option>
@foreach(\App\Plugins\Topic\src\Models\TopicTag::query()->where('status','=',null)->get() as $topic_tags)
<option value="{{$topic_tags->id}}"
data-custom-properties="&lt;span class=&quot;badge&quot; style=&quot;background-color: {{$topic_tags->color}} &quot; &gt;{{$topic_tags->icon}}&lt;/span&gt;">
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>
{{$topic_tags->name}}
</option>
@endforeach
Expand Down
2 changes: 1 addition & 1 deletion app/Plugins/Topic/resources/views/create/preview.blade.php
Expand Up @@ -23,7 +23,7 @@
<link href="{{ file_hash("css/diy.css") }}" rel="stylesheet"/>
<link rel="stylesheet" href="{{mix('css/app.css')}}">
<script>
var csrf_token = "{{ recsrf_token() }}";
var csrf_token = "{{ csrf_token() }}";
var ws_url = "{{ws_url()}}";
var _token = "{{auth()->token()}}";
var imageUpUrl = "/user/upload/image?_token={{ csrf_token() }}";
Expand Down
19 changes: 18 additions & 1 deletion app/Plugins/Topic/resources/views/edit.blade.php
Expand Up @@ -64,9 +64,26 @@
</div>
</div>
</div>
<div class="col-12">
<div class="row row-cards">
<div class="col-lg-9">
<div class="card card-body">
<label for="" class="form-label">验证码</label>
<div class="input-group">
<input type="text" name="captcha" class="form-control" placeholder="captcha"
autocomplete="off" required>
<span class="input-group-link">
<img class="captcha" src="{{captcha()->inline()}}" alt=""
onclick="this.src='/captcha?id='+Math.random()">
</span>
</div>
</div>
</div>
</div>
</div>
<div class="col-12">
@csrf()
<button class="btn btn-primary" type="submit">提交</button>
<button timeout="1500" auto-event="disabled" class="btn btn-primary" type="submit">提交</button>
</div>
</div>
</form>
Expand Down
2 changes: 2 additions & 0 deletions app/Plugins/Topic/src/Controllers/TopicController.php
Expand Up @@ -24,6 +24,7 @@
use Hyperf\HttpServer\Annotation\GetMapping;
use Hyperf\HttpServer\Annotation\Middleware;
use Hyperf\HttpServer\Annotation\PostMapping;
use Hyperf\RateLimit\Annotation\RateLimit;

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

#[PostMapping(path: '/topic/update')]
#[RateLimit(create:1, capacity:1, consume:1)]
public function edit_post()
{
$quanxian = false;
Expand Down
@@ -0,0 +1,26 @@
<?php

declare(strict_types=1);
/**
* This file is part of zhuchunshu.
* @link https://github.com/zhuchunshu
* @document https://github.com/zhuchunshu/super-forum
* @contact laravel@88.com
* @license https://github.com/zhuchunshu/super-forum/blob/master/LICENSE
*/
namespace App\Plugins\Topic\src\Handler\Topic\Middleware\Create;

use App\Plugins\Topic\src\Handler\Topic\Middleware\MiddlewareInterface;

#[\App\Plugins\Topic\src\Annotation\Topic\CreateFirstMiddleware]
class CaptchaMiddleware implements MiddlewareInterface
{
public function handler($data, \Closure $next)
{
if (! captcha()->check(request()->input('captcha'))) {
unset($data['basis']['content']);
return redirect()->with('danger', '验证码错误')->url('topic/create?' . http_build_query($data))->go();
}
return $next($data);
}
}
Expand Up @@ -36,6 +36,7 @@ public function handler($data, \Closure $next)
'title' => 'required|string|min:' . get_options('topic_create_title_min', 1) . '|max:' . get_options('topic_create_title_max', 200),
'tag' => 'required|exists:topic_tag,id',
],
[],
[
'content' => '内容',
'title' => '标题',
Expand Down
@@ -0,0 +1,25 @@
<?php

declare(strict_types=1);
/**
* This file is part of zhuchunshu.
* @link https://github.com/zhuchunshu
* @document https://github.com/zhuchunshu/super-forum
* @contact laravel@88.com
* @license https://github.com/zhuchunshu/super-forum/blob/master/LICENSE
*/
namespace App\Plugins\Topic\src\Handler\Topic\Middleware\Update;

use App\Plugins\Topic\src\Handler\Topic\Middleware\MiddlewareInterface;

#[\App\Plugins\Topic\src\Annotation\Topic\UpdateFirstMiddleware]
class CaptchaMiddleware implements MiddlewareInterface
{
public function handler($data, \Closure $next)
{
if (! captcha()->check(request()->input('captcha'))) {
return redirect()->url('/' . $data['basis']['topic_id'] . '.html')->with('danger', '验证码错误')->go();
}
return $next($data);
}
}
Expand Up @@ -38,6 +38,7 @@ public function handler($data, \Closure $next)
'title' => 'required|string|min:' . get_options('topic_create_title_min', 1) . '|max:' . get_options('topic_create_title_max', 200),
'tag' => 'required|exists:topic_tag,id',
],
[],
[
'topic_id' => '帖子id',
'content' => '正文内容',
Expand Down
2 changes: 1 addition & 1 deletion app/Themes/CodeFec/resources/views/app.blade.php
Expand Up @@ -16,7 +16,7 @@
<link href="{{ file_hash("css/diy.css") }}" rel="stylesheet" />
<link rel="stylesheet" href="{{mix('css/app.css')}}">
<script>
var csrf_token = "{{ recsrf_token() }}";
var csrf_token = "{{ csrf_token() }}";
var ws_url = "{{ws_url()}}";
var _token = "{{auth()->token()}}";
var imageUpUrl = "/user/upload/image?_token={{ csrf_token() }}";
Expand Down
Expand Up @@ -17,7 +17,7 @@
{{__('app.essence')}}
</div>
@endif
<div class="row">
<div class="row" style="margin-top: -10px">
{{-- 标题--}}
<div class="col-md-12" id="title">
<h1 data-bs-toggle="tooltip" data-bs-placement="left" title="{{__('topic.title')}}">
Expand Down
2 changes: 1 addition & 1 deletion app/Themes/CodeFec/resources/views/user/sign.blade.php
Expand Up @@ -22,7 +22,7 @@
<link rel="stylesheet" href="{{mix("plugins/Core/css/core.css")}}">
<link href="{{ file_hash("css/diy.css") }}" rel="stylesheet" />
<script>
var csrf_token = "{{ recsrf_token() }}";
var csrf_token = "{{ csrf_token() }}";
var ws_url = "{{ws_url()}}";
var login_token = "{{auth()->token()}}";
</script>
Expand Down
2 changes: 1 addition & 1 deletion app/View/Component/CsrfToken.php
Expand Up @@ -10,7 +10,7 @@ class CsrfToken extends Component
public $token;
public function __construct()
{
$this->token = recsrf_token();
$this->token = csrf_token();
}
public function render()
{
Expand Down
24 changes: 18 additions & 6 deletions app/helpers.php
Expand Up @@ -498,15 +498,27 @@ function csrf_token()
}
}

if (! function_exists('csrf_token')) {
function csrf_token()
{
if (! session()->has('csrf_token')) {
session()->set('csrf_token', Str::random());
}
if (! cache()->has('csrf_token.' . session()->get('csrf_token'))) {
cache()->set('csrf_token.' . session()->get('csrf_token'), Str::random());
}
return cache()->get('csrf_token.' . session()->get('csrf_token'));
}
}

if (! function_exists('recsrf_token')) {
function recsrf_token()
{
return csrf_token();
// if(!session()->has("csrf_token")){
// session()->set("csrf_token",Str::random());
// }
// cache()->set("csrf_token".session()->get("csrf_token"),Str::random(),300);
// return cache()->get("csrf_token".session()->get("csrf_token"));
if (! session()->has('csrf_token')) {
session()->set('csrf_token', Str::random());
}
cache()->set('csrf_token.' . session()->get('csrf_token'), Str::random());
return cache()->get('csrf_token.' . session()->get('csrf_token'));
}
}

Expand Down

0 comments on commit c7bdce0

Please sign in to comment.