ppaass_v3_common/user/
mod.rs1pub mod repo;
2use crate::crypto::RsaCrypto;
3use crate::error::CommonError;
4use std::any::Any;
5use std::collections::HashMap;
6use std::sync::Arc;
7use tokio::sync::RwLock;
8#[derive(Debug)]
9pub struct UserInfo {
10 rsa_crypto: RsaCrypto,
11 additional_info: HashMap<String, Arc<dyn Any + Send + Sync + 'static>>,
12}
13
14impl UserInfo {
15 pub fn new(rsa_crypto: RsaCrypto) -> Self {
16 Self {
17 rsa_crypto,
18 additional_info: Default::default(),
19 }
20 }
21
22 pub fn rsa_crypto(&self) -> &RsaCrypto {
23 &self.rsa_crypto
24 }
25
26 pub fn add_additional_info<T: Send + Sync + 'static>(&mut self, key: &str, value: T) {
27 self.additional_info
28 .insert(key.to_string(), Arc::new(value));
29 }
30
31 pub fn get_additional_info<T: Send + Sync + 'static>(&self, key: &str) -> Option<&T> {
32 match self.additional_info.get(key) {
33 None => None,
34 Some(additional_info) => additional_info.downcast_ref::<T>(),
35 }
36 }
37}
38
39#[async_trait::async_trait]
40pub trait UserInfoRepository {
41 async fn get_user(&self, username: &str) -> Result<Option<Arc<RwLock<UserInfo>>>, CommonError>;
42
43 async fn list_all_users(&self) -> Result<Vec<Arc<RwLock<UserInfo>>>, CommonError>;
44}