Struct UserService

Source
pub struct UserService<TAuthUser: AuthUser + Debug + Send + Sync> { /* private fields */ }
Expand description

Provides access logic for specified AuthUser

Implementations§

Source§

impl<TAuthUser: AuthUser + Debug + Send + Sync> UserService<TAuthUser>

Source

pub async fn create_user( &self, username: String, password: String, ) -> Result<i32, AuthError>

Creates new user and returns created id

Source

pub async fn get_users(&self) -> Result<Vec<TAuthUser>, AuthError>

Gets all existing users

Source

pub async fn update_own_password( &self, access_token: &str, old_password: &str, new_password: String, ) -> Result<(), AuthError>

Updates password for user with provided access_token

Source

pub async fn update_other_user_password( &self, target_user_id: i32, target_user_new_password: String, ) -> Result<(), AuthError>

Updates other user’s password

Note that this method doesn’t use CredentialValidator for a new password validation to reset password to some default value for example Also, this method is not recommended for self-update, use [update_own_password] instead

Source

pub async fn block_user(&self, username: &str) -> Result<(), AuthError>

Blocks user with provided username

Source

pub async fn generate_tokens( &self, username: &str, password: &str, ) -> Result<TokenPair, AuthError>

Generates TokenPair (refresh and access tokens) by credentials

Source

pub async fn refresh_tokens( &self, refresh_token: &str, ) -> Result<TokenPair, AuthError>

Refreshes TokenPair by refresh token

Source

pub async fn create_role(&self, role_name: String) -> Result<i32, AuthError>

Creates new role

Source

pub async fn update_role_name( &self, role_id: i32, new_name: String, ) -> Result<(), AuthError>

Updates role name

Source

pub async fn get_roles(&self) -> Result<Vec<Role>, AuthError>

Gets all existing roles

Source

pub async fn update_user_roles( &self, user_id: i32, roles: &Vec<i32>, ) -> Result<(), AuthError>

Updates user’s roles with new set of roles and clears all existing user’s roles if they are not present in roles param.

Source

pub async fn get_user_roles(&self, user_id: i32) -> Result<Vec<Role>, AuthError>

Gets all user’s roles

Auto Trait Implementations§

§

impl<TAuthUser> Freeze for UserService<TAuthUser>

§

impl<TAuthUser> !RefUnwindSafe for UserService<TAuthUser>

§

impl<TAuthUser> Send for UserService<TAuthUser>

§

impl<TAuthUser> Sync for UserService<TAuthUser>

§

impl<TAuthUser> Unpin for UserService<TAuthUser>

§

impl<TAuthUser> !UnwindSafe for UserService<TAuthUser>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Any for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Source§

fn type_name(&self) -> &'static str

Source§

impl<T> AnySync for T
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send>

Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.