pub trait SaTokenListener: Send + Sync {
// Provided methods
fn on_login<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
login_id: &'life1 str,
token: &'life2 str,
login_type: &'life3 str,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where 'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
Self: 'async_trait { ... }
fn on_logout<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
login_id: &'life1 str,
token: &'life2 str,
login_type: &'life3 str,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where 'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
Self: 'async_trait { ... }
fn on_kick_out<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
login_id: &'life1 str,
token: &'life2 str,
login_type: &'life3 str,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where 'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
Self: 'async_trait { ... }
fn on_renew_timeout<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
login_id: &'life1 str,
token: &'life2 str,
login_type: &'life3 str,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where 'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
Self: 'async_trait { ... }
fn on_replaced<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
login_id: &'life1 str,
token: &'life2 str,
login_type: &'life3 str,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where 'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
Self: 'async_trait { ... }
fn on_banned<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
login_id: &'life1 str,
login_type: &'life2 str,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where 'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Self: 'async_trait { ... }
fn on_event<'life0, 'life1, 'async_trait>(
&'life0 self,
event: &'life1 SaTokenEvent,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where 'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait { ... }
}Expand description
事件监听器 trait | Event Listener Trait
实现此 trait 来自定义事件处理逻辑 Implement this trait to customize event handling logic
§使用示例 | Usage Example
ⓘ
use async_trait::async_trait;
use sa_token_core::SaTokenListener;
struct MyListener;
#[async_trait]
impl SaTokenListener for MyListener {
async fn on_login(&self, login_id: &str, token: &str, login_type: &str) {
// 自定义登录处理 | Custom login handling
println!("User {} logged in", login_id);
}
}Provided Methods§
Sourcefn on_login<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
login_id: &'life1 str,
token: &'life2 str,
login_type: &'life3 str,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
Self: 'async_trait,
fn on_login<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
login_id: &'life1 str,
token: &'life2 str,
login_type: &'life3 str,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
Self: 'async_trait,
登录事件 | Login Event
当用户成功登录时触发 | Triggered when user successfully logs in
§参数 | Parameters
login_id: 登录 ID | Login IDtoken: Token 值 | Token valuelogin_type: 登录类型(如 “web”, “websocket”)| Login type (e.g., “web”, “websocket”)
Sourcefn on_logout<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
login_id: &'life1 str,
token: &'life2 str,
login_type: &'life3 str,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
Self: 'async_trait,
fn on_logout<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
login_id: &'life1 str,
token: &'life2 str,
login_type: &'life3 str,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
Self: 'async_trait,
登出事件 | Logout Event
当用户主动登出时触发 | Triggered when user actively logs out
§参数 | Parameters
login_id: 登录 ID | Login IDtoken: Token 值 | Token valuelogin_type: 登录类型 | Login type
Sourcefn on_kick_out<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
login_id: &'life1 str,
token: &'life2 str,
login_type: &'life3 str,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
Self: 'async_trait,
fn on_kick_out<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
login_id: &'life1 str,
token: &'life2 str,
login_type: &'life3 str,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
Self: 'async_trait,
踢出下线事件 | Kick Out Event
当用户被强制踢出下线时触发 | Triggered when user is forcefully kicked out
§参数 | Parameters
login_id: 登录 ID | Login IDtoken: Token 值 | Token valuelogin_type: 登录类型 | Login type
Sourcefn on_renew_timeout<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
login_id: &'life1 str,
token: &'life2 str,
login_type: &'life3 str,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
Self: 'async_trait,
fn on_renew_timeout<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
login_id: &'life1 str,
token: &'life2 str,
login_type: &'life3 str,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
Self: 'async_trait,
Token 续期事件 | Token Renewal Event
当 Token 有效期被延长时触发 | Triggered when token validity is extended
§参数 | Parameters
login_id: 登录 ID | Login IDtoken: Token 值 | Token valuelogin_type: 登录类型 | Login type
Sourcefn on_replaced<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
login_id: &'life1 str,
token: &'life2 str,
login_type: &'life3 str,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
Self: 'async_trait,
fn on_replaced<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
login_id: &'life1 str,
token: &'life2 str,
login_type: &'life3 str,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
Self: 'async_trait,
被顶下线事件 | Replaced Event
当用户在其他设备登录导致当前设备被顶下线时触发 Triggered when user logs in on another device and current device is replaced
§参数 | Parameters
login_id: 登录 ID | Login IDtoken: Token 值 | Token valuelogin_type: 登录类型 | Login type
Sourcefn on_banned<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
login_id: &'life1 str,
login_type: &'life2 str,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Self: 'async_trait,
fn on_banned<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
login_id: &'life1 str,
login_type: &'life2 str,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Self: 'async_trait,
被封禁事件 | Banned Event
当用户账号被封禁时触发 | Triggered when user account is banned
§参数 | Parameters
login_id: 登录 ID | Login IDlogin_type: 登录类型 | Login type
Sourcefn on_event<'life0, 'life1, 'async_trait>(
&'life0 self,
event: &'life1 SaTokenEvent,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
fn on_event<'life0, 'life1, 'async_trait>(
&'life0 self,
event: &'life1 SaTokenEvent,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
通用事件处理(所有事件都会触发此方法) Generic Event Handler (triggered by all events)
§参数 | Parameters
event: 事件对象 | Event object