pub struct DefaultUser {Show 13 fields
pub id: Uuid,
pub username: String,
pub email: String,
pub first_name: String,
pub last_name: String,
pub password_hash: Option<String>,
pub last_login: Option<DateTime<Utc>>,
pub is_active: bool,
pub is_staff: bool,
pub is_superuser: bool,
pub date_joined: DateTime<Utc>,
pub user_permissions: Vec<String>,
pub groups: Vec<String>,
}Use the user attribute macro to define your own user struct instead
auth and argon2-hasher only.Expand description
DefaultUser struct - Django’s AbstractUser equivalent
A complete, ready-to-use user model that combines BaseUser, FullUser, and PermissionsMixin. This is the default user model provided by Reinhardt, suitable for most applications.
§Relationship with Django
This struct is equivalent to Django’s django.contrib.auth.models.AbstractUser.
It provides a full-featured user model with:
- Username-based authentication
- Email address
- First and last name
- Password hashing (Argon2id by default)
- Active/staff/superuser flags
- Timestamps (last_login, date_joined)
- Permissions and groups
§Database Schema
The default table name is auth_user with the following columns:
id(UUID, primary key)username(String, unique)email(String)first_name(String)last_name(String)password_hash(Option<String>)last_login(Option<DateTime<Utc>>)is_active(bool)is_staff(bool)is_superuser(bool)date_joined(DateTime<Utc>)user_permissions(Vec<String>)groups(Vec<String>)
§Examples
Creating a new user with automatic Argon2id password hashing:
use reinhardt_auth::{BaseUser, DefaultUser};
use uuid::Uuid;
use chrono::Utc;
let mut user = DefaultUser {
id: Uuid::new_v4(),
username: "alice".to_string(),
email: "alice@example.com".to_string(),
first_name: "Alice".to_string(),
last_name: "Smith".to_string(),
password_hash: None,
last_login: None,
is_active: true,
is_staff: false,
is_superuser: false,
date_joined: Utc::now(),
user_permissions: Vec::new(),
groups: Vec::new(),
};
// Password is automatically hashed with Argon2id
user.set_password("securepass123").unwrap();
// Verify password
assert!(user.check_password("securepass123").unwrap());
assert!(!user.check_password("wrongpass").unwrap());Using with permissions:
use reinhardt_auth::{DefaultUser, PermissionsMixin};
use uuid::Uuid;
use chrono::Utc;
let mut user = DefaultUser {
id: Uuid::new_v4(),
username: "bob".to_string(),
email: "bob@example.com".to_string(),
first_name: "Bob".to_string(),
last_name: "Johnson".to_string(),
password_hash: None,
last_login: None,
is_active: true,
is_staff: true,
is_superuser: false,
date_joined: Utc::now(),
user_permissions: vec![
"blog.add_post".to_string(),
"blog.change_post".to_string(),
],
groups: vec!["editors".to_string()],
};
// Check permissions
assert!(user.has_perm("blog.add_post"));
assert!(user.has_perm("blog.change_post"));
assert!(!user.has_perm("blog.delete_post"));
assert!(user.has_module_perms("blog"));Fields§
§id: UuidUse the user attribute macro to define your own user struct instead
Unique identifier (primary key)
username: StringUse the user attribute macro to define your own user struct instead
Username (unique, used for login)
email: StringUse the user attribute macro to define your own user struct instead
Email address
first_name: StringUse the user attribute macro to define your own user struct instead
First name
last_name: StringUse the user attribute macro to define your own user struct instead
Last name
password_hash: Option<String>Use the user attribute macro to define your own user struct instead
Password hash (hashed with Argon2id by default)
last_login: Option<DateTime<Utc>>Use the user attribute macro to define your own user struct instead
Last login timestamp
is_active: boolUse the user attribute macro to define your own user struct instead
Whether this user account is active
is_staff: boolUse the user attribute macro to define your own user struct instead
Whether this user can access the admin site
is_superuser: boolUse the user attribute macro to define your own user struct instead
Whether this user has all permissions (superuser)
date_joined: DateTime<Utc>Use the user attribute macro to define your own user struct instead
When this user account was created
user_permissions: Vec<String>Use the user attribute macro to define your own user struct instead
List of permissions (format: “app_label.permission_name”)
groups: Vec<String>Use the user attribute macro to define your own user struct instead
List of groups this user belongs to
Trait Implementations§
Source§impl User for DefaultUser
impl User for DefaultUser
Source§fn id(&self) -> String
fn id(&self) -> String
Use AuthIdentity + BaseUser/FullUser + PermissionsMixin instead
Source§fn username(&self) -> &str
fn username(&self) -> &str
Use AuthIdentity + BaseUser/FullUser + PermissionsMixin instead
Source§fn get_username(&self) -> &str
fn get_username(&self) -> &str
Use AuthIdentity + BaseUser/FullUser + PermissionsMixin instead
username()) Read moreSource§fn is_authenticated(&self) -> bool
fn is_authenticated(&self) -> bool
Use AuthIdentity + BaseUser/FullUser + PermissionsMixin instead
Source§fn is_active(&self) -> bool
fn is_active(&self) -> bool
Use AuthIdentity + BaseUser/FullUser + PermissionsMixin instead
Source§fn is_admin(&self) -> bool
fn is_admin(&self) -> bool
Use AuthIdentity + BaseUser/FullUser + PermissionsMixin instead
Source§fn is_staff(&self) -> bool
fn is_staff(&self) -> bool
Use AuthIdentity + BaseUser/FullUser + PermissionsMixin instead
Source§fn is_superuser(&self) -> bool
fn is_superuser(&self) -> bool
Use AuthIdentity + BaseUser/FullUser + PermissionsMixin instead
Source§impl BaseUser for DefaultUser
impl BaseUser for DefaultUser
Source§type PrimaryKey = Uuid
type PrimaryKey = Uuid
Source§type Hasher = Argon2Hasher
type Hasher = Argon2Hasher
Source§fn get_username_field() -> &'static str
fn get_username_field() -> &'static str
Source§fn get_username(&self) -> &str
fn get_username(&self) -> &str
Source§fn password_hash(&self) -> Option<&str>
fn password_hash(&self) -> Option<&str>
Source§fn set_password_hash(&mut self, hash: String)
fn set_password_hash(&mut self, hash: String)
Source§fn set_last_login(&mut self, time: DateTime<Utc>)
fn set_last_login(&mut self, time: DateTime<Utc>)
Source§fn normalize_username(username: &str) -> String
fn normalize_username(username: &str) -> String
Source§fn set_password(&mut self, password: &str) -> Result<(), Error>
fn set_password(&mut self, password: &str) -> Result<(), Error>
Source§fn check_password(&self, password: &str) -> Result<bool, Error>
fn check_password(&self, password: &str) -> Result<bool, Error>
Source§fn set_unusable_password(&mut self)
fn set_unusable_password(&mut self)
Source§fn has_usable_password(&self) -> bool
fn has_usable_password(&self) -> bool
Source§impl BaseUserManager<DefaultUser> for DefaultUserManager
impl BaseUserManager<DefaultUser> for DefaultUserManager
Source§fn create_user<'life0, 'life1, 'life2, 'async_trait>(
&'life0 mut self,
username: &'life1 str,
password: Option<&'life2 str>,
extra: HashMap<String, Value>,
) -> Pin<Box<dyn Future<Output = Result<DefaultUser, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
DefaultUserManager: 'async_trait,
fn create_user<'life0, 'life1, 'life2, 'async_trait>(
&'life0 mut self,
username: &'life1 str,
password: Option<&'life2 str>,
extra: HashMap<String, Value>,
) -> Pin<Box<dyn Future<Output = Result<DefaultUser, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
DefaultUserManager: 'async_trait,
Source§fn create_superuser<'life0, 'life1, 'life2, 'async_trait>(
&'life0 mut self,
username: &'life1 str,
password: Option<&'life2 str>,
extra: HashMap<String, Value>,
) -> Pin<Box<dyn Future<Output = Result<DefaultUser, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
DefaultUserManager: 'async_trait,
fn create_superuser<'life0, 'life1, 'life2, 'async_trait>(
&'life0 mut self,
username: &'life1 str,
password: Option<&'life2 str>,
extra: HashMap<String, Value>,
) -> Pin<Box<dyn Future<Output = Result<DefaultUser, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
DefaultUserManager: 'async_trait,
Source§impl Clone for DefaultUser
impl Clone for DefaultUser
Source§fn clone(&self) -> DefaultUser
fn clone(&self) -> DefaultUser
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for DefaultUser
impl Debug for DefaultUser
Source§impl Default for DefaultUser
impl Default for DefaultUser
Source§fn default() -> DefaultUser
fn default() -> DefaultUser
Source§impl<'de> Deserialize<'de> for DefaultUser
impl<'de> Deserialize<'de> for DefaultUser
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<DefaultUser, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<DefaultUser, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Source§impl FullUser for DefaultUser
impl FullUser for DefaultUser
Source§fn first_name(&self) -> &str
fn first_name(&self) -> &str
Source§fn is_superuser(&self) -> bool
fn is_superuser(&self) -> bool
Source§fn date_joined(&self) -> DateTime<Utc>
fn date_joined(&self) -> DateTime<Utc>
Source§fn get_full_name(&self) -> String
fn get_full_name(&self) -> String
Source§fn get_short_name(&self) -> &str
fn get_short_name(&self) -> &str
Source§impl Model for DefaultUser
impl Model for DefaultUser
Source§type PrimaryKey = Uuid
type PrimaryKey = Uuid
Source§type Fields = DefaultUserFields
type Fields = DefaultUserFields
Source§fn table_name() -> &'static str
fn table_name() -> &'static str
Source§fn new_fields() -> <DefaultUser as Model>::Fields
fn new_fields() -> <DefaultUser as Model>::Fields
Source§fn primary_key(&self) -> Option<<DefaultUser as Model>::PrimaryKey>
fn primary_key(&self) -> Option<<DefaultUser as Model>::PrimaryKey>
Source§fn set_primary_key(&mut self, value: <DefaultUser as Model>::PrimaryKey)
fn set_primary_key(&mut self, value: <DefaultUser as Model>::PrimaryKey)
Source§fn primary_key_field() -> &'static str
fn primary_key_field() -> &'static str
Source§fn composite_primary_key() -> Option<CompositePrimaryKey>
fn composite_primary_key() -> Option<CompositePrimaryKey>
Source§fn get_composite_pk_values(&self) -> HashMap<String, PkValue>
fn get_composite_pk_values(&self) -> HashMap<String, PkValue>
Source§fn relationship_metadata() -> Vec<RelationInfo>
fn relationship_metadata() -> Vec<RelationInfo>
Source§fn constraint_metadata() -> Vec<ConstraintInfo>
fn constraint_metadata() -> Vec<ConstraintInfo>
Source§fn objects() -> Manager<Self>where
Self: Sized,
fn objects() -> Manager<Self>where
Self: Sized,
Source§impl PermissionsMixin for DefaultUser
impl PermissionsMixin for DefaultUser
Source§fn is_superuser(&self) -> bool
fn is_superuser(&self) -> bool
Source§fn user_permissions(&self) -> &[String]
fn user_permissions(&self) -> &[String]
Source§fn get_user_permissions(&self) -> HashSet<String>
fn get_user_permissions(&self) -> HashSet<String>
Source§fn get_group_permissions(&self) -> HashSet<String>
fn get_group_permissions(&self) -> HashSet<String>
Source§fn get_all_permissions(&self) -> HashSet<String>
fn get_all_permissions(&self) -> HashSet<String>
Source§fn has_perm(&self, perm: &str) -> bool
fn has_perm(&self, perm: &str) -> bool
Source§impl Serialize for DefaultUser
impl Serialize for DefaultUser
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
Auto Trait Implementations§
impl Freeze for DefaultUser
impl RefUnwindSafe for DefaultUser
impl Send for DefaultUser
impl Sync for DefaultUser
impl Unpin for DefaultUser
impl UnsafeUnpin for DefaultUser
impl UnwindSafe for DefaultUser
Blanket Implementations§
Source§impl<T> AdminUser for Twhere
T: FullUser,
impl<T> AdminUser for Twhere
T: FullUser,
Source§fn is_superuser(&self) -> bool
fn is_superuser(&self) -> bool
Source§fn get_username(&self) -> &str
fn get_username(&self) -> &str
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> FmtForward for T
impl<T> FmtForward for T
Source§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self to use its Binary implementation when Debug-formatted.Source§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self to use its Display implementation when
Debug-formatted.Source§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self to use its LowerExp implementation when
Debug-formatted.Source§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self to use its LowerHex implementation when
Debug-formatted.Source§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self to use its Octal implementation when Debug-formatted.Source§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self to use its Pointer implementation when
Debug-formatted.Source§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self to use its UpperExp implementation when
Debug-formatted.Source§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self to use its UpperHex implementation when
Debug-formatted.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 moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::RequestSource§impl<T> IntoResult<T> for T
impl<T> IntoResult<T> for T
type Err = Infallible
fn into_result(self) -> Result<T, <T as IntoResult<T>>::Err>
Source§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.Source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.Source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian().Source§impl<E> ServerFnErrorAssertions<E> for Ewhere
E: Debug,
impl<E> ServerFnErrorAssertions<E> for Ewhere
E: Debug,
Source§fn should_contain_message(&self, expected: &str)where
E: Display,
fn should_contain_message(&self, expected: &str)where
E: Display,
Source§fn should_have_message(&self, expected: &str)where
E: Display,
fn should_have_message(&self, expected: &str)where
E: Display,
Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.Source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.Source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.Source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.