From cd20baa188599dd1832c695f93408ff8bce7cb50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=83=86=E3=82=AF=E3=83=8B=E3=82=AB=E3=83=AB=E8=AB=8F?= =?UTF-8?q?=E8=A8=AA=E5=AD=90?= Date: Mon, 24 Jan 2022 22:25:19 +0900 Subject: [PATCH] =?UTF-8?q?=E5=90=8C=E6=99=82=E3=83=AD=E3=82=B0=E3=82=A4?= =?UTF-8?q?=E3=83=B3=E6=A9=9F=E8=83=BD=EF=BC=88BE=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/.env.example | 2 +- backend/.env.release | 2 +- .../Controllers/Api/AuthenticationTrait.php | 23 ++++++++++++------- backend/config/session.php | 2 +- 4 files changed, 18 insertions(+), 11 deletions(-) diff --git a/backend/.env.example b/backend/.env.example index 01066b0d..2fb79d46 100644 --- a/backend/.env.example +++ b/backend/.env.example @@ -19,7 +19,7 @@ BROADCAST_DRIVER=log CACHE_DRIVER=file QUEUE_CONNECTION=sync SESSION_DRIVER=file -SESSION_LIFETIME=120 +SESSION_LIFETIME=150 MEMCACHED_HOST=127.0.0.1 diff --git a/backend/.env.release b/backend/.env.release index a73a171d..b0d685af 100644 --- a/backend/.env.release +++ b/backend/.env.release @@ -19,7 +19,7 @@ BROADCAST_DRIVER=log CACHE_DRIVER=file QUEUE_CONNECTION=sync SESSION_DRIVER=file -SESSION_LIFETIME=120 +SESSION_LIFETIME=150 MEMCACHED_HOST=127.0.0.1 diff --git a/backend/app/Http/Controllers/Api/AuthenticationTrait.php b/backend/app/Http/Controllers/Api/AuthenticationTrait.php index 0d2c51f8..bf3588dc 100644 --- a/backend/app/Http/Controllers/Api/AuthenticationTrait.php +++ b/backend/app/Http/Controllers/Api/AuthenticationTrait.php @@ -10,11 +10,9 @@ use Illuminate\Support\Facades\Log; use App\Models\LoginLimits; -// use App\Models\LoginLimits; - trait AuthenticationTrait { private function makeSession ($guard, $db) { - session()->regenerate(); + //session()->regenerate(); if (!session()->has($guard)) { // 認証されたデータのpasswordとremember_token以外を把握する @@ -36,6 +34,15 @@ trait AuthenticationTrait { return ['status_code' => 200, 'params' => ['id' => $login_user_datum['id']]]; } } + if (session()->has($this->getGuard())) { + if (null !== ($get = $this->getModel()->where('id', session()->get($this->getGuard())['id'])->first())) { // トークンがある場合 + // セッションを想像する + $login_user_datum = $this->makeSession($this->getGuard(), $get->toArray()); + + return ['status_code' => 200, 'params' => ['id' => $login_user_datum['id']]]; + } + + } return ['status_code' => 202]; } @@ -98,11 +105,11 @@ trait AuthenticationTrait { } // 既にセッションがあれば、ログアウトします。 - if (Session::has('children')) Session::forget('children'); - if (Session::has('fathers')) Session::forget('fathers'); - if (Session::has('admins')) Session::forget('admins'); - unset($_COOKIE['remember_token']); - setcookie('remember_token', '', time() - 3600, '/', $_SERVER['HTTP_HOST'], 0, 1); + //if (Session::has('children')) Session::forget('children'); + //if (Session::has('fathers')) Session::forget('fathers'); + //if (Session::has('admins')) Session::forget('admins'); + //unset($_COOKIE['remember_token']); + //setcookie('remember_token', '', time() - 3600, '/', $_SERVER['HTTP_HOST'], 0, 1); if ($r->remember_token == 'true') { $token = bin2hex(random_bytes(24)); diff --git a/backend/config/session.php b/backend/config/session.php index 53c17f91..801a9ebe 100644 --- a/backend/config/session.php +++ b/backend/config/session.php @@ -31,7 +31,7 @@ return [ | */ - 'lifetime' => env('SESSION_LIFETIME', 120), + 'lifetime' => env('SESSION_LIFETIME', 150), 'expire_on_close' => true,