pub struct Model {
pub id: i64,
pub username: String,
pub email: String,
pub password_hash: String,
pub admin: bool,
pub created_at: DateTime<Utc>,
pub updated_at: DateTime<Utc>,
pub profile_picture_path: Option<String>,
}
Expand description
Represents a user in the users
table.
Fields§
§id: i64
Primary key ID (auto-incremented).
username: String
Unique student number.
email: String
User’s unique email address.
password_hash: String
Securely hashed password string.
admin: bool
Whether the user has admin privileges.
created_at: DateTime<Utc>
Timestamp when the user was created.
updated_at: DateTime<Utc>
Timestamp when the user was last updated.
profile_picture_path: Option<String>
Implementations§
Source§impl Model
impl Model
Sourcepub async fn create(
db: &DatabaseConnection,
username: &str,
email: &str,
password: &str,
admin: bool,
) -> Result<Model, DbErr>
pub async fn create( db: &DatabaseConnection, username: &str, email: &str, password: &str, admin: bool, ) -> Result<Model, DbErr>
Creates a new user with hashed password and returns the inserted model.
§Arguments
db
- Database connection reference.username
- Unique student number.email
- Email address.password
- Plaintext password to hash.admin
- Whether the user is an admin.
Sourcepub async fn create_fake_user_with_no_hashed_password_do_not_use(
db: &DatabaseConnection,
username: &str,
email: &str,
password: &str,
admin: bool,
) -> Result<Model, DbErr>
pub async fn create_fake_user_with_no_hashed_password_do_not_use( db: &DatabaseConnection, username: &str, email: &str, password: &str, admin: bool, ) -> Result<Model, DbErr>
Creates a new user with no hashed password and returns the inserted model. NOTE: FOR SEEDING PURPOSES ONLY DO NOT USE
§Arguments
db
- Database connection reference.username
- Unique student number.email
- Email address.password
- Plaintext password to hash.admin
- Whether the user is an admin.
Sourcepub async fn get_by_username(
db: &DatabaseConnection,
username: &str,
) -> Result<Option<Model>, DbErr>
pub async fn get_by_username( db: &DatabaseConnection, username: &str, ) -> Result<Option<Model>, DbErr>
Sourcepub async fn verify_credentials(
db: &DatabaseConnection,
username: &str,
password: &str,
) -> Result<Option<Model>, DbErr>
pub async fn verify_credentials( db: &DatabaseConnection, username: &str, password: &str, ) -> Result<Option<Model>, DbErr>
Sourcepub async fn get_module_roles(
db: &DatabaseConnection,
user_id: i64,
) -> Result<Vec<UserModuleRole>, DbErr>
pub async fn get_module_roles( db: &DatabaseConnection, user_id: i64, ) -> Result<Vec<UserModuleRole>, DbErr>
Sourcepub async fn is_in_role(
db: &DatabaseConnection,
user_id: i64,
module_id: i64,
role: &str,
) -> Result<bool, DbErr>
pub async fn is_in_role( db: &DatabaseConnection, user_id: i64, module_id: i64, role: &str, ) -> Result<bool, DbErr>
Sourcepub fn hash_password(password: &str) -> String
pub fn hash_password(password: &str) -> String
Sourcepub fn verify_password(&self, password: &str) -> bool
pub fn verify_password(&self, password: &str) -> bool
Verifies a plaintext password against the stored hash
Trait Implementations§
Source§impl From<Model> for ActiveModel
impl From<Model> for ActiveModel
Source§impl FromQueryResult for Model
impl FromQueryResult for Model
Source§fn from_query_result(row: &QueryResult, pre: &str) -> Result<Self, DbErr>
fn from_query_result(row: &QueryResult, pre: &str) -> Result<Self, DbErr>
Instantiate a Model from a [QueryResult] Read more
§fn from_query_result_optional(
res: &QueryResult,
pre: &str,
) -> Result<Option<Self>, DbErr>
fn from_query_result_optional( res: &QueryResult, pre: &str, ) -> Result<Option<Self>, DbErr>
Transform the error from instantiating a Model from a [QueryResult]
and converting it to an Option
§fn from_query_result_nullable(
res: &QueryResult,
pre: &str,
) -> Result<Self, TryGetError>
fn from_query_result_nullable( res: &QueryResult, pre: &str, ) -> Result<Self, TryGetError>
§fn find_by_statement(stmt: Statement) -> SelectorRaw<SelectModel<Self>>
fn find_by_statement(stmt: Statement) -> SelectorRaw<SelectModel<Self>>
Source§impl IntoActiveModel<ActiveModel> for Model
impl IntoActiveModel<ActiveModel> for Model
Source§fn into_active_model(self) -> ActiveModel
fn into_active_model(self) -> ActiveModel
Method to call to perform the conversion
Source§impl ModelTrait for Model
impl ModelTrait for Model
type Entity = Entity
Source§fn get(&self, c: <Self::Entity as EntityTrait>::Column) -> Value
fn get(&self, c: <Self::Entity as EntityTrait>::Column) -> Value
Get the [Value] of a column from an Entity
Source§fn set(&mut self, c: <Self::Entity as EntityTrait>::Column, v: Value)
fn set(&mut self, c: <Self::Entity as EntityTrait>::Column, v: Value)
Set the [Value] of a column in an Entity
Find related Models
§fn find_linked<L>(&self, l: L) -> Select<<L as Linked>::ToEntity>where
L: Linked<FromEntity = Self::Entity>,
fn find_linked<L>(&self, l: L) -> Select<<L as Linked>::ToEntity>where
L: Linked<FromEntity = Self::Entity>,
Find linked Models
§fn delete<'a, 'async_trait, A, C>(
self,
db: &'a C,
) -> Pin<Box<dyn Future<Output = Result<DeleteResult, DbErr>> + Send + 'async_trait>>where
'a: 'async_trait,
Self: IntoActiveModel<A> + 'async_trait,
C: ConnectionTrait + 'async_trait,
A: ActiveModelTrait<Entity = Self::Entity> + ActiveModelBehavior + Send + 'a + 'async_trait,
fn delete<'a, 'async_trait, A, C>(
self,
db: &'a C,
) -> Pin<Box<dyn Future<Output = Result<DeleteResult, DbErr>> + Send + 'async_trait>>where
'a: 'async_trait,
Self: IntoActiveModel<A> + 'async_trait,
C: ConnectionTrait + 'async_trait,
A: ActiveModelTrait<Entity = Self::Entity> + ActiveModelBehavior + Send + 'a + 'async_trait,
Delete a model
Source§impl TryFrom<ActiveModel> for Model
impl TryFrom<ActiveModel> for Model
Source§impl TryIntoModel<Model> for ActiveModel
impl TryIntoModel<Model> for ActiveModel
Source§fn try_into_model(self) -> Result<Model, DbErr>
fn try_into_model(self) -> Result<Model, DbErr>
Method to call to perform the conversion
impl StructuralPartialEq for Model
Auto Trait Implementations§
impl Freeze for Model
impl RefUnwindSafe for Model
impl Send for Model
impl Sync for Model
impl Unpin for Model
impl UnwindSafe for Model
Blanket Implementations§
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
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§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>
Converts
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>
Converts
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§impl<M> TryIntoModel<M> for Mwhere
M: ModelTrait,
impl<M> TryIntoModel<M> for Mwhere
M: ModelTrait,
§fn try_into_model(self) -> Result<M, DbErr>
fn try_into_model(self) -> Result<M, DbErr>
Method to call to perform the conversion