Skip to content

Commit

Permalink
Fix:在cdn状态下,异步上传文件失效的Bug
Browse files Browse the repository at this point in the history
  • Loading branch information
zhuchunshu committed Jan 12, 2023
1 parent 2eb465b commit d49745f
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 6 deletions.
1 change: 1 addition & 0 deletions app/Plugins/Comment/resources/views/topic/create.blade.php
Expand Up @@ -62,6 +62,7 @@
const formData = new FormData();
formData.append('file', blobInfo.blob(), blobInfo.filename());
formData.append('_token', csrf_token);
formData.append('_session', _token);
axios.post("/user/upload/image",formData,{
'Content-type' : 'multipart/form-data'
}).then(function(r){
Expand Down
1 change: 1 addition & 0 deletions app/Plugins/Comment/resources/views/topic/edit.blade.php
Expand Up @@ -69,6 +69,7 @@
const formData = new FormData();
formData.append('file', blobInfo.blob(), blobInfo.filename());
formData.append('_token', csrf_token);
formData.append('_session', _token);
axios.post("/user/upload/image",formData,{
'Content-type' : 'multipart/form-data'
}).then(function(r){
Expand Down
1 change: 1 addition & 0 deletions app/Plugins/Topic/resources/views/create/basis.blade.php
Expand Up @@ -71,6 +71,7 @@
const formData = new FormData();
formData.append('file', blobInfo.blob(), blobInfo.filename());
formData.append('_token', csrf_token);
formData.append('_session', _token);
axios.post("/user/upload/image",formData,{
'Content-type' : 'multipart/form-data'
}).then(function(r){
Expand Down
1 change: 1 addition & 0 deletions app/Plugins/Topic/resources/views/edit/basis.blade.php
Expand Up @@ -40,6 +40,7 @@
const formData = new FormData();
formData.append('file', blobInfo.blob(), blobInfo.filename());
formData.append('_token', csrf_token);
formData.append('_session', _token);
axios.post("/user/upload/image",formData,{
'Content-type' : 'multipart/form-data'
}).then(function(r){
Expand Down
16 changes: 11 additions & 5 deletions app/Plugins/User/src/AuthGuard.php
Expand Up @@ -8,7 +8,6 @@
* @contact laravel@88.com
* @license https://github.com/zhuchunshu/super-forum/blob/master/LICENSE
*/

namespace App\Plugins\User\src;

use App\Plugins\User\src\Models\UsersAuth;
Expand Down Expand Up @@ -44,20 +43,27 @@ public function logout(): bool
'user_id' => $this->user()->getId(),
'token' => session()->get('AUTH_TOKEN'),
])->delete();
return (bool)$this->session->remove($this->sessionKey()) && $this->session->remove('AUTH_TOKEN');
return (bool) $this->session->remove($this->sessionKey()) && $this->session->remove('AUTH_TOKEN');
}

public function check(): bool
public function check(string $token = null): bool
{
try {
return $this->user() instanceof Authenticatable && call_user_func(function () {
return $this->user() instanceof Authenticatable && call_user_func(function () use ($token) {
if ($token === null) {
return UsersAuth::query()->where([
'user_id' => $this->user()->getId(),
'user_ip' => get_client_ip(),
'token' => session()->get('AUTH_TOKEN'),
'user_agent' => get_user_agent(),
])->exists();
}) === true;
}
return UsersAuth::query()->where([
'user_id' => $this->user()->getId(),
'token' => session()->get('AUTH_TOKEN'),
'user_agent' => get_user_agent(),
])->exists();
}) === true;
} catch (AuthException $exception) {
return false;
}
Expand Down
3 changes: 2 additions & 1 deletion app/Plugins/User/src/Middleware/LoginMiddleware.php
Expand Up @@ -34,7 +34,8 @@ public function __construct(ContainerInterface $container)

public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
{
if (! auth()->check()) {
$token = request()->input('_session', null);
if (! auth()->check($token)) {
throw new UnauthorizedException('Without authorization');
}

Expand Down

0 comments on commit d49745f

Please sign in to comment.