Browse Source

代理修改密码删除登陆缓存

master
wanghongjun 2 years ago
parent
commit
4556fd657b
  1. 5
      app/controller/AdminAgentTeam.php
  2. 5
      app/event.php
  3. 13
      app/event/AgentPasswordChange.php
  4. 27
      app/listener/LogoutAgent.php
  5. 1
      app/listener/LogoutUser.php

5
app/controller/AdminAgentTeam.php

@ -4,6 +4,7 @@ declare (strict_types = 1);
namespace app\controller;
use app\BaseController;
use app\event\AgentPasswordChange;
use app\middleware\CheckAdmin;
use app\model\AdminDownScoresRecords;
use app\model\AdminUpScoresRecords;
@ -13,6 +14,7 @@ use app\validate\Admin;
use app\validate\Agent;
use think\exception\ValidateException;
use think\facade\Db;
use think\facade\Event;
use think\facade\Request;
class AdminAgentTeam extends BaseController
@ -165,6 +167,9 @@ class AdminAgentTeam extends BaseController
if (!$result['status']) throw new ValidateException($result['msg']);
$event = new AgentPasswordChange($param['aid']);
Event::trigger(AgentPasswordChange::class,$event);
return $this->renderSuccess($result['msg']);
} catch (ValidateException $validateException) {
return $this->renderError($validateException->getMessage());

5
app/event.php

@ -12,7 +12,10 @@ return [
'LogWrite' => [],
'app\event\UserPasswordChange' => [
'app\listener\LogoutUser',
]
],
'app\event\AgentPasswordChange' => [
'app\listener\LogoutAgent',
],
],
'subscribe' => [

13
app/event/AgentPasswordChange.php

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

27
app/listener/LogoutAgent.php

@ -0,0 +1,27 @@
<?php
namespace app\listener;
use app\event\AgentPasswordChange;
use think\facade\Cache;
class LogoutAgent
{
/**
* 监听用户登陆状态
* @param AgentPasswordChange $event
* @throws \Psr\SimpleCache\InvalidArgumentException
*/
public function handle(AgentPasswordChange $event)
{
$aid = $event->aid;
$agentData = Cache::store('redis')->get('login_agent_user_data');
if ($agentData) {
$agentData = unserialize($agentData);
if ($agentData['id'] == $aid) {
Cache::store('redis')->delete('login_agent_user_data');
}
}
}
}

1
app/listener/LogoutUser.php

@ -4,7 +4,6 @@ namespace app\listener;
use app\event\UserPasswordChange;
use think\facade\Cache;
use think\facade\Log;
class LogoutUser
{

Loading…
Cancel
Save