pub trait UserDetailsManager: UserDetailsService {
// Required methods
fn create_user<'life0, 'life1, 'async_trait>(
&'life0 self,
user: &'life1 User,
) -> Pin<Box<dyn Future<Output = Result<(), UserDetailsError>> + Send + 'async_trait>>
where 'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait;
fn update_user<'life0, 'life1, 'async_trait>(
&'life0 self,
user: &'life1 User,
) -> Pin<Box<dyn Future<Output = Result<(), UserDetailsError>> + Send + 'async_trait>>
where 'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait;
fn delete_user<'life0, 'life1, 'async_trait>(
&'life0 self,
username: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<(), UserDetailsError>> + Send + 'async_trait>>
where 'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait;
fn change_password<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
username: &'life1 str,
old_password: &'life2 str,
new_password: &'life3 str,
) -> Pin<Box<dyn Future<Output = Result<(), UserDetailsError>> + Send + 'async_trait>>
where 'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
Self: 'async_trait;
}Expand description
Extended trait for managing users (CRUD operations).
§Spring Security Equivalent
Similar to UserDetailsManager in Spring Security.
§Example
ⓘ
#[async_trait]
impl UserDetailsManager for DatabaseUserDetailsService {
async fn create_user(&self, user: &User) -> Result<(), UserDetailsError> {
sqlx::query!("INSERT INTO users ...")
.execute(&self.pool)
.await
.map_err(|e| UserDetailsError::StorageError(e.to_string()))?;
Ok(())
}
// ... other methods
}Required Methods§
Sourcefn create_user<'life0, 'life1, 'async_trait>(
&'life0 self,
user: &'life1 User,
) -> Pin<Box<dyn Future<Output = Result<(), UserDetailsError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
fn create_user<'life0, 'life1, 'async_trait>(
&'life0 self,
user: &'life1 User,
) -> Pin<Box<dyn Future<Output = Result<(), UserDetailsError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
Create a new user.
Sourcefn update_user<'life0, 'life1, 'async_trait>(
&'life0 self,
user: &'life1 User,
) -> Pin<Box<dyn Future<Output = Result<(), UserDetailsError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
fn update_user<'life0, 'life1, 'async_trait>(
&'life0 self,
user: &'life1 User,
) -> Pin<Box<dyn Future<Output = Result<(), UserDetailsError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
Update an existing user.
Sourcefn delete_user<'life0, 'life1, 'async_trait>(
&'life0 self,
username: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<(), UserDetailsError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
fn delete_user<'life0, 'life1, 'async_trait>(
&'life0 self,
username: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<(), UserDetailsError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
Delete a user by username.
Sourcefn change_password<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
username: &'life1 str,
old_password: &'life2 str,
new_password: &'life3 str,
) -> Pin<Box<dyn Future<Output = Result<(), UserDetailsError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
Self: 'async_trait,
fn change_password<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
username: &'life1 str,
old_password: &'life2 str,
new_password: &'life3 str,
) -> Pin<Box<dyn Future<Output = Result<(), UserDetailsError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
Self: 'async_trait,
Change user’s password.
§Arguments
username- The usernameold_password- The current password (for verification)new_password- The new password (should be encoded)