Trait actix_loginmanager::UserMinix
source · pub trait UserMinix: Sized {
type Future: Future<Output = Option<Self>>;
type Key: Serialize + DeserializeOwned;
// Required methods
fn get_user(id: &Self::Key, req: &HttpRequest) -> Self::Future;
fn get_id(&self) -> &Self::Key;
// Provided methods
fn is_authenticated(&self) -> bool { ... }
fn is_actived(&self) -> bool { ... }
}
Expand description
the base user trait
Example: Get user from database
type Pool = sqlx::SqlitePool;
#[derive(Serialize, Deserialize)]
pub struct User { ... }
impl UserMinix for User {
type Future = Pin<Box<dyn Future<Output = Option<Self>>>>;
type Key = i32;
fn get_user(id: &i32, req: &HttpRequest) -> Self::Future {
let req = req.clone();
let id = id.clone();
Box::pin(async move {
if let Some(pool) = req.app_data::<Data<Pool>>(){
let pool = pool.get_ref();
todo!() // get user from pool instance,return Some(user) or None
}else{
None
}
})
}
fn get_id(&self) -> i32 {
self.id
}
}
Required Associated Types§
sourcetype Key: Serialize + DeserializeOwned
type Key: Serialize + DeserializeOwned
The type of User, must be same as Loginmanager. Otherwise no user will be returned.
Required Methods§
sourcefn get_user(id: &Self::Key, req: &HttpRequest) -> Self::Future
fn get_user(id: &Self::Key, req: &HttpRequest) -> Self::Future
Get user from id and req,Tip:can use req.app_data to obtain database connection defined in Web app.
Provided Methods§
sourcefn is_authenticated(&self) -> bool
fn is_authenticated(&self) -> bool
return user’s actual authentication status, default True.
sourcefn is_actived(&self) -> bool
fn is_actived(&self) -> bool
return user’s actual active status, default True.