4 changed files with 55 additions and 0 deletions
@ -0,0 +1,14 @@ |
|||
<?php |
|||
|
|||
namespace app\event; |
|||
|
|||
class UserPasswordChange |
|||
{ |
|||
|
|||
public $userId; |
|||
|
|||
public function __construct($userId) |
|||
{ |
|||
$this->userId = $userId; |
|||
} |
|||
} |
|||
@ -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'); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,12 @@ |
|||
<?php |
|||
// 事件监听 |
|||
|
|||
return [ |
|||
// ... |
|||
'listen' => [ |
|||
// ... |
|||
'app\event\UserPasswordChange' => [ |
|||
'app\listener\LogoutUser', |
|||
], |
|||
], |
|||
]; |
|||
Loading…
Reference in new issue