pub struct UserOperations<'a> { /* private fields */ }Expand description
Focused user-management operations exposed from AuthFramework::users.
§Example
// Register
let uid = auth.users().register("alice", "alice@example.com", "P@ssw0rd!").await?;
// Look up
let user = auth.users().get(&uid).await?;
assert_eq!(user.username, "alice");
// Update password
auth.users().update_password_by_id(&uid, "NewP@ss!").await?;Implementations§
Source§impl UserOperations<'_>
impl UserOperations<'_>
Sourcepub async fn register(
&self,
username: &str,
email: &str,
password: &str,
) -> Result<String>
pub async fn register( &self, username: &str, email: &str, password: &str, ) -> Result<String>
Register a new user and return the generated user ID.
Sourcepub async fn list(
&self,
limit: Option<usize>,
offset: Option<usize>,
active_only: bool,
) -> Result<Vec<UserInfo>>
👎Deprecated since 0.6.0: use list_with_query(UserListQuery::new().limit(n).active_only()) instead
pub async fn list( &self, limit: Option<usize>, offset: Option<usize>, active_only: bool, ) -> Result<Vec<UserInfo>>
use list_with_query(UserListQuery::new().limit(n).active_only()) instead
List users from the canonical user index.
Prefer list_with_query which uses a
UserListQuery builder for better readability at call sites.
Sourcepub async fn list_with_query(
&self,
query: UserListQuery,
) -> Result<Vec<UserInfo>>
pub async fn list_with_query( &self, query: UserListQuery, ) -> Result<Vec<UserInfo>>
List users using a UserListQuery for better readability.
§Example
let active = auth.users()
.list_with_query(UserListQuery::new().limit(50).active_only())
.await?;Sourcepub async fn get(&self, user_id: &str) -> Result<UserInfo>
pub async fn get(&self, user_id: &str) -> Result<UserInfo>
Fetch a user record by canonical user ID.
Sourcepub async fn exists_by_username(&self, username: &str) -> Result<bool>
pub async fn exists_by_username(&self, username: &str) -> Result<bool>
Check whether a username exists.
Sourcepub async fn exists_by_email(&self, email: &str) -> Result<bool>
pub async fn exists_by_email(&self, email: &str) -> Result<bool>
Check whether an email exists.
Sourcepub async fn get_by_username(
&self,
username: &str,
) -> Result<HashMap<String, Value>>
pub async fn get_by_username( &self, username: &str, ) -> Result<HashMap<String, Value>>
Fetch a user record by username.
Sourcepub async fn profile(&self, user_id: &str) -> Result<ProviderProfile>
pub async fn profile(&self, user_id: &str) -> Result<ProviderProfile>
Fetch an application-level user profile.
Sourcepub async fn update_password(
&self,
username: &str,
new_password: &str,
) -> Result<()>
pub async fn update_password( &self, username: &str, new_password: &str, ) -> Result<()>
Update a user’s password.
Sourcepub async fn update_password_by_id(
&self,
user_id: &str,
new_password: &str,
) -> Result<()>
pub async fn update_password_by_id( &self, user_id: &str, new_password: &str, ) -> Result<()>
Update a user’s password by user ID.
Sourcepub async fn update_roles(&self, user_id: &str, roles: &[String]) -> Result<()>
pub async fn update_roles(&self, user_id: &str, roles: &[String]) -> Result<()>
Update the roles assigned to a user.
Sourcepub async fn set_active(&self, user_id: &str, active: bool) -> Result<()>
👎Deprecated since 0.5.0: use set_status(id, UserStatus) instead
pub async fn set_active(&self, user_id: &str, active: bool) -> Result<()>
use set_status(id, UserStatus) instead
Enable or disable a user.
Sourcepub async fn set_status(&self, user_id: &str, status: UserStatus) -> Result<()>
pub async fn set_status(&self, user_id: &str, status: UserStatus) -> Result<()>
Sourcepub async fn update_email(&self, user_id: &str, email: &str) -> Result<()>
pub async fn update_email(&self, user_id: &str, email: &str) -> Result<()>
Update a user’s email address.
Sourcepub async fn verify_password(
&self,
user_id: &str,
password: &str,
) -> Result<bool>
pub async fn verify_password( &self, user_id: &str, password: &str, ) -> Result<bool>
Verify a user’s password.
Sourcepub async fn username(&self, user_id: &str) -> Result<String>
pub async fn username(&self, user_id: &str) -> Result<String>
Resolve a username from a user ID.
Sourcepub async fn delete_by_id(&self, user_id: &str) -> Result<()>
pub async fn delete_by_id(&self, user_id: &str) -> Result<()>
Delete a user by user ID.
Sourcepub fn check_username(&self, username: &str) -> Result<()>
pub fn check_username(&self, username: &str) -> Result<()>
Validate a username against the configured format rules.
Returns Ok(()) when the username is acceptable, or
Err(AuthError::Validation { .. }) describing the policy violation.
§Example
auth.users().check_username("alice")?;
// Returns Err explaining why the name is invalid:
assert!(auth.users().check_username("").is_err());Sourcepub fn check_password_strength(&self, password: &str) -> Result<()>
pub fn check_password_strength(&self, password: &str) -> Result<()>
Validate a password against the active security policy.
Returns Ok(()) when the password meets production strength
requirements, or Err(AuthError::Validation { .. }) with feedback.
§Example
auth.users().check_password_strength("C0mpl3x!Pa$$word")?;
assert!(auth.users().check_password_strength("weak").is_err());Sourcepub fn check_email(&self, email: &str) -> Result<()>
pub fn check_email(&self, email: &str) -> Result<()>
Validate an email address against RFC 5322 format rules.
Returns Ok(()) when the email is acceptable, or
Err(AuthError::Validation { .. }) describing the issue.
§Example
auth.users().check_email("alice@example.com")?;
assert!(auth.users().check_email("not-an-email").is_err());Auto Trait Implementations§
impl<'a> Freeze for UserOperations<'a>
impl<'a> !RefUnwindSafe for UserOperations<'a>
impl<'a> Send for UserOperations<'a>
impl<'a> Sync for UserOperations<'a>
impl<'a> Unpin for UserOperations<'a>
impl<'a> UnsafeUnpin for UserOperations<'a>
impl<'a> !UnwindSafe for UserOperations<'a>
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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