Browse Source

修改管理员密码后出发退出登陆

master
wanghongjun 2 years ago
parent
commit
637f3890d3
  1. 5
      app/controller/AdminUser.php
  2. 3
      app/event.php
  3. 13
      app/event/AdminPasswordChange.php
  4. 28
      app/listener/LogoutAdmin.php

5
app/controller/AdminUser.php

@ -4,11 +4,13 @@ declare (strict_types = 1);
namespace app\controller;
use app\BaseController;
use app\event\AdminPasswordChange;
use app\middleware\CheckAdmin;
use app\model\RebateRecords;
use think\exception\ValidateException;
use think\facade\Cache;
use think\facade\Db;
use think\facade\Event;
use think\facade\Filesystem;
use think\facade\Request;
use app\model\AdminUser as AdminModel;
@ -70,6 +72,9 @@ class AdminUser extends BaseController
$user = $AdminModel->modifyPassword($data,$adminData['id']);
if ($user['status']) {
$event = new AdminPasswordChange($adminData['id']);
Event::trigger(AdminPasswordChange::class,$event);
return $this->renderSuccess('修改成功');
} else {
return $this->renderError($user['msg']);

3
app/event.php

@ -16,6 +16,9 @@ return [
'app\event\AgentPasswordChange' => [
'app\listener\LogoutAgent',
],
'app\event\AdminPasswordChange' => [
'app\listener\LogoutAdmin',
],
],
'subscribe' => [

13
app/event/AdminPasswordChange.php

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

28
app/listener/LogoutAdmin.php

@ -0,0 +1,28 @@
<?php
namespace app\listener;
use app\event\AdminPasswordChange;
use think\facade\Cache;
use think\facade\Session;
class LogoutAdmin
{
/**
* 监听用户登陆状态
* @param AdminPasswordChange $event
* @throws \Psr\SimpleCache\InvalidArgumentException
*/
public function handle(AdminPasswordChange $event)
{
$aid = $event->aid;
$adminData = Cache::store('redis')->get('login_admin_user_data');
if ($adminData) {
$adminData = unserialize($adminData);
if ($adminData['id'] == $aid) {
Session::delete('login_admin_user_data');
}
}
}
}
Loading…
Cancel
Save