\App\ListenersWriteUserLoginLog

登录日志监听器

职责:把登录认证生命周期事实落 td_log_user_login。登录成功插行 (绑定会话标识);失败插行(记真实失败原因);登出回填原会话行 logout_time;被踢下线回填 logout_time 并置 login_status=2, 无原会话行时补记(如跨实例)。写库失败仅告警,绝不阻断认证主链路。

┌────────────────── 分区导航(按此顺序阅读)──────────────────┐ 分区 1 · 事件处理 handle 分区 2 · 分类型落库 recordSuccess / recordFailed / closeSession 分区 3 · 内部辅助 row / browser / os └────────────────────────────────────────────────────────────┘

Summary

Methods
Properties
Constants
handle()
No public properties found
No constants found
No protected methods found
No protected properties found
N/A
recordSuccess()
recordFailed()
closeSession()
row()
browser()
os()
No private properties found
N/A

Methods

handle()

handle(\App\Events\LogUserLoginEvent  $event) : void

处理登录事件。

流程:① 按事件类型分派落库策略 ② 写库异常仅告警吞掉, 认证主链路(登录/登出)不因审计落库失败而中断。

Parameters

\App\Events\LogUserLoginEvent $event

recordSuccess()

recordSuccess(\App\Events\LogUserLoginEvent  $event) : void

登录成功:插入会话行(会话指纹绑定,供登出/被踢回填)

Parameters

\App\Events\LogUserLoginEvent $event

recordFailed()

recordFailed(\App\Events\LogUserLoginEvent  $event) : void

登录失败:插入失败行(记真实失败原因;用户不存在时 user_id 为空)

Parameters

\App\Events\LogUserLoginEvent $event

closeSession()

closeSession(\App\Events\LogUserLoginEvent  $event, bool  $kicked) : void

会话闭合:登出/被踢回填原会话行 logout_time,被踢同时置 login_status=2; 无会话标识或原会话行缺失(如跨实例)时,被踢补记一行保审计完整。

Parameters

\App\Events\LogUserLoginEvent $event
bool $kicked

row()

row(\App\Events\LogUserLoginEvent  $event, array  $extra) : array

组装公共行:登录方式 + 请求上下文(公共字段单源 + 登录专属 ip_location/browser/os)

Parameters

\App\Events\LogUserLoginEvent $event
array $extra

Returns

array —

browser()

browser(string  $userAgent) : string

从 UA 提取浏览器名(正则粗判,日志用途足够;Edge 需先于 Chrome 判定)

Parameters

string $userAgent

Returns

string —

os()

os(string  $userAgent) : string

从 UA 提取操作系统名

Parameters

string $userAgent

Returns

string —