sa_token_plugin_ntex/
lib.rs

1// Author: 金书记
2//
3// 中文 | English
4// Ntex 框架集成 | Ntex Framework Integration
5//
6//! # sa-token-plugin-ntex
7//! 
8//! 为 Ntex 框架提供 sa-token 认证和授权支持
9//! Provides sa-token authentication and authorization support for Ntex framework
10//! 
11//! ## 特性 | Features
12//! 
13//! - ✨ 一行导入所有功能 | One-line import for all functionalities
14//! - 🔧 支持多种存储后端 | Support for multiple storage backends
15//! - 🚀 简化的中间件集成 | Simplified middleware integration
16//! - 📦 包含核心、宏、存储 | Includes core, macros, and storage
17//! 
18//! ## 快速开始 | Quick Start
19//! 
20//! ```toml
21//! [dependencies]
22//! sa-token-plugin-ntex = "0.1.5"
23//! ```
24//! 
25//! ```rust,ignore
26//! use sa_token_plugin_ntex::*;
27//! use std::sync::Arc;
28//! 
29//! #[ntex::main]
30//! async fn main() -> std::io::Result<()> {
31//!     let storage = Arc::new(MemoryStorage::new());
32//!     let state = SaTokenState::builder()
33//!         .storage(storage)
34//!         .timeout(7200)
35//!         .build();
36//!     
37//!     ntex::web::HttpServer::new(move || {
38//!         ntex::web::App::new()
39//!             // 基础 token 提取中间件
40//!             .wrap(SaTokenMiddleware::new(state.clone()))
41//!             .route("/login", ntex::web::post().to(login_handler))
42//!             .service(
43//!                 ntex::web::scope("/api")
44//!                     // 需要登录的路由
45//!                     .wrap(SaCheckLoginMiddleware::new(state.clone()))
46//!                     .route("/user", ntex::web::get().to(user_handler))
47//!                     .service(
48//!                         ntex::web::scope("/admin")
49//!                             // 需要管理员权限的路由
50//!                             .wrap(SaCheckPermissionMiddleware::new(state.clone(), "admin"))
51//!                             .route("/users", ntex::web::get().to(admin_users_handler))
52//!                     )
53//!             )
54//!     })
55//!     .bind("127.0.0.1:8080")?
56//!     .run()
57//!     .await
58//! }
59//! ```
60
61pub mod adapter;
62pub mod extractor;
63pub mod middleware;
64pub mod layer;
65pub mod state;
66
67pub use sa_token_core::{self, prelude::*};
68pub use sa_token_adapter::{self, storage::SaStorage, framework::FrameworkAdapter};
69pub use sa_token_macro::*;
70
71// 重新导出存储实现(通过 feature 控制)
72// Re-export storage implementations (controlled by features)
73#[cfg(feature = "memory")]
74pub use sa_token_storage_memory::*;
75
76#[cfg(feature = "redis")]
77pub use sa_token_storage_redis::*;
78
79#[cfg(feature = "database")]
80pub use sa_token_storage_database::*;
81
82// 重新导出本模块的适配器 | Re-export adapters from this module
83pub use adapter::*;
84pub use extractor::*;
85pub use middleware::*;
86pub use layer::SaTokenLayer;
87pub use state::{SaTokenState, SaTokenStateBuilder};
88