update: banned user remove session

This commit is contained in:
v2board 2023-02-03 23:39:31 +08:00
parent 10861856b5
commit 2429ff6d58
3 changed files with 14 additions and 2 deletions

View File

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

View File

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

View File

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