Sfoglia il codice sorgente

update: banned user remove session

v2board 2 anni fa
parent
commit
2429ff6d58

+ 6 - 0
app/Http/Controllers/Admin/UserController.php

@@ -7,6 +7,7 @@ use App\Http\Requests\Admin\UserGenerate;
 use App\Http\Requests\Admin\UserSendMail;
 use App\Http\Requests\Admin\UserUpdate;
 use App\Jobs\SendEmailJob;
+use App\Services\AuthService;
 use App\Services\UserService;
 use App\Utils\Helper;
 use Illuminate\Http\Request;
@@ -128,6 +129,11 @@ class UserController extends Controller
             $params['invite_user_id'] = null;
         }
 
+        if (isset($params['banned']) && (int)$params['banned'] === 1) {
+            $authService = new AuthService($user);
+            $authService->removeAllSession();
+        }
+
         try {
             $user->update($params);
         } catch (\Exception $e) {

+ 1 - 1
app/Http/Controllers/User/UserController.php

@@ -39,7 +39,7 @@ class UserController extends Controller
         }
         $authService = new AuthService($user);
         return response([
-            'data' => $authService->delSession($request->input('session_id'))
+            'data' => $authService->removeSession($request->input('session_id'))
         ]);
     }
 

+ 7 - 1
app/Services/AuthService.php

@@ -84,7 +84,7 @@ class AuthService
         return (array)Cache::get(CacheKey::get("USER_SESSIONS", $this->user->id), []);
     }
 
-    public function delSession($sessionId)
+    public function removeSession($sessionId)
     {
         $cacheKey = CacheKey::get("USER_SESSIONS", $this->user->id);
         $sessions = (array)Cache::get($cacheKey, []);
@@ -95,4 +95,10 @@ class AuthService
         )) return false;
         return true;
     }
+
+    public function removeAllSession()
+    {
+        $cacheKey = CacheKey::get("USER_SESSIONS", $this->user->id);
+        return Cache::forget($cacheKey);
+    }
 }