Skip to main content

SaLogic

Struct SaLogic 

Source
pub struct SaLogic { /* private fields */ }
Expand description

绑定某一 login_type 的账号逻辑门面 Account-logic facade bound to one login_type

Implementations§

Source§

impl SaLogic

Source

pub fn new(login_type: impl AsRef<str>, manager: SaTokenManager) -> SaLogic

创建门面(廉价 Clone) Create facade (cheap to Clone)

Source

pub fn login_type(&self) -> &str

Account system / login type | 账号体系/登录类型

Source

pub fn manager(&self) -> &SaTokenManager

Underlying manager | 底层管理器

Source

pub fn keys(&self) -> &SaKeys

Key layout helper | 键布局辅助

Source

pub async fn login( &self, login_id: impl Into<String>, ) -> Result<TokenValue, SaTokenError>

Login and issue a token | 登录并签发 Token

Source

pub async fn login_with_device( &self, login_id: impl Into<String>, device: Option<String>, extra: Option<Value>, ) -> Result<TokenValue, SaTokenError>

Login with device label | 带设备标识登录

Source

pub async fn logout(&self, token: &TokenValue) -> Result<(), SaTokenError>

Logout current token | 登出当前 Token

Source

pub async fn logout_by_login_id( &self, login_id: &str, ) -> Result<(), SaTokenError>

Logout all tokens of a login id | 登出某登录 ID 的全部 Token

Source

pub async fn kick_out(&self, login_id: &str) -> Result<(), SaTokenError>

Kick out and optionally notify | 踢下线并可通知

Source

pub async fn get_login_id( &self, token: &TokenValue, ) -> Result<String, SaTokenError>

Resolve login id from token | 从 Token 解析登录 ID

Source

pub async fn is_valid(&self, token: &TokenValue) -> bool

Whether the token is valid | Token 是否有效

Source

pub async fn get_session( &self, login_id: &str, ) -> Result<SaSession, SaTokenError>

Load account session | 加载账号 Session

Source

pub async fn save_session( &self, login_id: &str, session: &SaSession, ) -> Result<(), SaTokenError>

Persist account session | 持久化账号 Session

Source

pub async fn delete_session(&self, login_id: &str) -> Result<(), SaTokenError>

Delete account session | 删除账号 Session

Source

pub async fn get_terminal_list( &self, login_id: &str, device_type: Option<&str>, ) -> Result<Vec<SaTerminalInfo>, SaTokenError>

List terminals for the account | 列出账号终端

Source

pub async fn get_terminal_info_by_token( &self, token: &TokenValue, ) -> Result<Option<SaTerminalInfo>, SaTokenError>

Terminal info for a token | 按 Token 查终端信息

Source

pub async fn get_permissions( &self, login_id: &str, ) -> Result<Vec<String>, SaTokenError>

获取权限列表 | Permission list

Source

pub async fn set_permissions( &self, login_id: &str, perms: Vec<String>, ) -> Result<(), SaTokenError>

覆盖权限列表 | Overwrite the permission list

Source

pub async fn add_permission( &self, login_id: &str, permission: impl Into<String>, ) -> Result<(), SaTokenError>

追加单个权限(B2-35 新增)| Append one permission (new)

Source

pub async fn remove_permission( &self, login_id: &str, permission: &str, ) -> Result<(), SaTokenError>

移除单个权限(B2-35 新增)| Remove one permission (new)

Source

pub async fn clear_permissions( &self, login_id: &str, ) -> Result<(), SaTokenError>

清空权限(B2-35 新增)| Clear permissions (new)

Source

pub async fn has_permission( &self, login_id: &str, permission: &str, ) -> Result<bool, SaTokenError>

单个权限校验(B2-27 新增)| Single permission check (new)

Source

pub async fn check_permission( &self, login_id: &str, permission: &str, ) -> Result<(), SaTokenError>

权限校验,不足则返回 Err(B2-27 新增)| Permission check returning Err (new)

Source

pub async fn has_all_permissions( &self, login_id: &str, permissions: &[&str], ) -> Result<bool, SaTokenError>

批量权限校验(AND,B2-27 新增)| Batch AND permission check (new)

Source

pub async fn has_any_permission( &self, login_id: &str, permissions: &[&str], ) -> Result<bool, SaTokenError>

批量权限校验(OR,B2-27 新增)| Batch OR permission check (new)

Source

pub async fn get_roles( &self, login_id: &str, ) -> Result<Vec<String>, SaTokenError>

获取角色列表 | Role list

Source

pub async fn set_roles( &self, login_id: &str, roles: Vec<String>, ) -> Result<(), SaTokenError>

覆盖角色列表 | Overwrite the role list

Source

pub async fn add_role( &self, login_id: &str, role: impl Into<String>, ) -> Result<(), SaTokenError>

追加单个角色(B2-35 新增)| Append one role (new)

Source

pub async fn remove_role( &self, login_id: &str, role: &str, ) -> Result<(), SaTokenError>

移除单个角色(B2-35 新增)| Remove one role (new)

Source

pub async fn clear_roles(&self, login_id: &str) -> Result<(), SaTokenError>

清空角色(B2-35 新增)| Clear roles (new)

Source

pub async fn has_role( &self, login_id: &str, role: &str, ) -> Result<bool, SaTokenError>

单个角色校验(B2-27 新增)| Single role check (new)

Source

pub async fn check_role( &self, login_id: &str, role: &str, ) -> Result<(), SaTokenError>

角色校验,不足则返回 Err(B2-27 新增)| Role check returning Err (new)

Source

pub async fn has_all_roles( &self, login_id: &str, roles: &[&str], ) -> Result<bool, SaTokenError>

批量角色校验(AND,B2-27 新增)| Batch AND role check (new)

Source

pub async fn has_any_role( &self, login_id: &str, roles: &[&str], ) -> Result<bool, SaTokenError>

批量角色校验(OR,B2-27 新增)| Batch OR role check (new)

Source

pub async fn disable( &self, login_id: &str, time: i64, ) -> Result<(), SaTokenError>

Disable account/service | 禁用账号或服务

Source

pub async fn disable_level( &self, login_id: &str, service: &str, level: i32, time: i64, ) -> Result<(), SaTokenError>

Disable at a level (default login type) | 分级禁用(默认登录类型)

Source

pub async fn check_disable(&self, login_id: &str) -> Result<(), SaTokenError>

Fail if account is disabled | 账号被禁用则报错

Source

pub async fn get_disable_level( &self, login_id: &str, service: &str, ) -> Result<i32, SaTokenError>

Read disable level | 读取禁用等级

Source

pub async fn untie_disable( &self, login_id: &str, service: &str, ) -> Result<(), SaTokenError>

Clear disable flag | 解除禁用

Source

pub async fn open_safe( &self, token: &TokenValue, service: &str, safe_time: i64, ) -> Result<(), SaTokenError>

Open secondary auth window | 开启二级认证窗口

Source

pub async fn check_safe( &self, token: &TokenValue, service: &str, ) -> Result<(), SaTokenError>

Fail if secondary auth missing | 未通过二级认证则报错

Source

pub async fn is_safe( &self, token: &TokenValue, service: &str, ) -> Result<bool, SaTokenError>

Whether secondary auth is active | 二级认证是否有效

Source

pub async fn close_safe( &self, token: &TokenValue, service: &str, ) -> Result<(), SaTokenError>

Close secondary auth window | 关闭二级认证窗口

Source

pub async fn get_token_session( &self, token: &TokenValue, ) -> Result<SaSession, SaTokenError>

Load token-scoped session | 加载 Token 级 Session

Source

pub async fn get_anon_token_session( &self, token: &TokenValue, ) -> Result<SaSession, SaTokenError>

Load anonymous token session | 加载匿名 Token Session

Source

pub async fn save_token_session( &self, token: &TokenValue, session: &SaSession, ) -> Result<(), SaTokenError>

save_token_session — save token session | save_token_session

Source

pub async fn delete_token_session( &self, token: &TokenValue, ) -> Result<(), SaTokenError>

delete_token_session — delete token session | delete_token_session

Source

pub fn switch_to(&self, login_id: impl Into<String>)

必须走 B3 单轨突变,否则 task-local 路径静默失效。 Must use B3 single-track mutation or task-local switch silently fails.

Source

pub fn end_switch(&self)

End identity switch | 结束身份切换

Source

pub fn is_switch(&self) -> bool

Whether identity is switched | 是否处于身份切换中

Trait Implementations§

Source§

impl Clone for SaLogic

Source§

fn clone(&self) -> SaLogic

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for SaLogic

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more