Browse Source

用户修改密码删除登陆缓存

master
wanghongjun 3 years ago
parent
commit
8166d1dbdb
  1. 5
      app/controller/AdminUserTeam.php
  2. 14
      app/event/UserPasswordChange.php
  3. 24
      app/listener/LogoutUser.php
  4. 12
      config/event.php

5
app/controller/AdminUserTeam.php

@ -4,6 +4,7 @@ declare (strict_types = 1);
namespace app\controller;
use app\BaseController;
use app\event\UserPasswordChange;
use app\middleware\CheckAdmin;
use app\model\AdminDownScoresRecords;
use app\model\AdminUpScoresRecords;
@ -11,6 +12,7 @@ use app\model\RechargeRecords;
use app\model\User;
use app\model\WithdrawalRecords;
use think\facade\Db;
use think\facade\Event;
use think\facade\Request;
use think\facade\Session;
use app\validate\Admin;
@ -113,6 +115,9 @@ class AdminUserTeam extends BaseController
if (!$result['status']) throw new ValidateException($result['msg']);
$event = new UserPasswordChange($param['user_id']);
Event::trigger(UserPasswordChange::class,$event);
return $this->renderSuccess($result['msg']);
} catch (ValidateException $validateException) {
return $this->renderError($validateException->getMessage());

14
app/event/UserPasswordChange.php

@ -0,0 +1,14 @@
<?php
namespace app\event;
class UserPasswordChange
{
public $userId;
public function __construct($userId)
{
$this->userId = $userId;
}
}

24
app/listener/LogoutUser.php

@ -0,0 +1,24 @@
<?php
namespace app\listener;
use app\event\UserPasswordChange;
use think\facade\Cache;
class LogoutUser
{
/**
* 监听用户登陆状态
* @param UserPasswordChange $event
* @throws \Psr\SimpleCache\InvalidArgumentException
*/
public function handle(UserPasswordChange $event)
{
$userId = $event->userId;
$userData = Cache::store('redis')->get('login_user_data');
if ($userData && $userData['id'] == $userId) {
Cache::store('redis')->delete('login_user_data');
}
}
}

12
config/event.php

@ -0,0 +1,12 @@
<?php
// 事件监听
return [
// ...
'listen' => [
// ...
'app\event\UserPasswordChange' => [
'app\listener\LogoutUser',
],
],
];
Loading…
Cancel
Save