|
8 | 8 | * @contact laravel@88.com
|
9 | 9 | * @license https://github.com/zhuchunshu/super-forum/blob/master/LICENSE
|
10 | 10 | */
|
11 |
| -use App\CodeFec\{Admin\Admin,Itf\Setting\SettingInterface,Menu\MenuInterface,Plugins,View\Beautify_Html}; |
| 11 | +use App\CodeFec\Admin\Admin; |
| 12 | +use App\CodeFec\Itf\Setting\SettingInterface; |
| 13 | +use App\CodeFec\Menu\MenuInterface; |
| 14 | +use App\CodeFec\Plugins; |
| 15 | +use App\CodeFec\View\Beautify_Html; |
12 | 16 | use App\Model\AdminOption;
|
13 | 17 | use Hyperf\Context\Context;
|
14 |
| -use Hyperf\Contract\{SessionInterface,StdoutLoggerInterface}; |
| 18 | +use Hyperf\Contract\SessionInterface; |
| 19 | +use Hyperf\Contract\StdoutLoggerInterface; |
15 | 20 | use Hyperf\HttpMessage\Stream\SwooleStream;
|
16 |
| -use Hyperf\HttpServer\{Contract\ResponseInterface,Response}; |
| 21 | +use Hyperf\HttpServer\Contract\ResponseInterface; |
| 22 | +use Hyperf\HttpServer\Response; |
17 | 23 | use Hyperf\Logger\LoggerFactory;
|
18 | 24 | use Hyperf\Paginator\UrlWindow;
|
19 | 25 | use Hyperf\Server\ServerFactory;
|
20 | 26 | use Hyperf\Utils\{ApplicationContext};
|
21 | 27 | use Hyperf\View\RenderInterface;
|
22 |
| -use Illuminate\Support\{Arr,Facades\File,Str}; |
| 28 | +use Illuminate\Support\Arr; |
| 29 | +use Illuminate\Support\Facades\File; |
| 30 | +use Illuminate\Support\Str; |
23 | 31 | use Overtrue\Http\Client;
|
24 |
| -use Psr\{Container\ContainerInterface,EventDispatcher\EventDispatcherInterface,Http\Message\ServerRequestInterface}; |
| 32 | +use Psr\Container\ContainerInterface; |
| 33 | +use Psr\EventDispatcher\EventDispatcherInterface; |
| 34 | +use Psr\Http\Message\ServerRequestInterface; |
25 | 35 |
|
26 | 36 | function public_path($path = ''): string
|
27 | 37 | {
|
@@ -488,37 +498,34 @@ function de_stringify(string $stringify): array
|
488 | 498 | if (! function_exists('csrf_token')) {
|
489 | 499 | function csrf_token()
|
490 | 500 | {
|
491 |
| - if (! session()->has('csrf_token')) { |
492 |
| - session()->set('csrf_token', Str::random()); |
| 501 | + if (! session()->has('CSRF_TOKEN')) { |
| 502 | + session()->set('CSRF_TOKEN', Str::random()); |
493 | 503 | }
|
494 |
| - if (! cache()->has('csrf_token' . session()->get('csrf_token'))) { |
495 |
| - cache()->set('csrf_token' . session()->get('csrf_token'), Str::random()); |
| 504 | + if (! cache()->has('CSRF_TOKEN' . session()->get('CSRF_TOKEN'))) { |
| 505 | + $k = sha1(json_encode([ |
| 506 | + request()->getHeader('host')[0], |
| 507 | + get_client_ip(), |
| 508 | + get_user_agent(), |
| 509 | + ], JSON_THROW_ON_ERROR)); |
| 510 | + cache()->set('CSRF_TOKEN' . session()->get('CSRF_TOKEN'), $k); |
496 | 511 | }
|
497 |
| - return cache()->get('csrf_token' . session()->get('csrf_token')); |
498 |
| - } |
499 |
| -} |
500 |
| - |
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')); |
| 512 | + return cache()->get('CSRF_TOKEN' . session()->get('CSRF_TOKEN')); |
511 | 513 | }
|
512 | 514 | }
|
513 | 515 |
|
514 | 516 | if (! function_exists('recsrf_token')) {
|
515 | 517 | function recsrf_token()
|
516 | 518 | {
|
517 |
| - if (! session()->has('csrf_token')) { |
518 |
| - session()->set('csrf_token', Str::random()); |
| 519 | + if (! session()->has('CSRF_TOKEN')) { |
| 520 | + session()->set('CSRF_TOKEN', Str::random()); |
519 | 521 | }
|
520 |
| - cache()->set('csrf_token.' . session()->get('csrf_token'), Str::random()); |
521 |
| - return cache()->get('csrf_token.' . session()->get('csrf_token')); |
| 522 | + $k = sha1(json_encode([ |
| 523 | + request()->getHeader('host')[0], |
| 524 | + get_client_ip(), |
| 525 | + get_user_agent(), |
| 526 | + ], JSON_THROW_ON_ERROR)); |
| 527 | + cache()->set('CSRF_TOKEN' . session()->get('CSRF_TOKEN'), $k); |
| 528 | + return cache()->get('CSRF_TOKEN' . session()->get('CSRF_TOKEN')); |
522 | 529 | }
|
523 | 530 | }
|
524 | 531 |
|
|
0 commit comments