36 lines
1 KiB
Rust
36 lines
1 KiB
Rust
use argon2::{Argon2, PasswordHash, PasswordVerifier};
|
|
use sea_orm::entity::prelude::*;
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)]
|
|
#[sea_orm(table_name = "User")]
|
|
pub struct Model {
|
|
#[sea_orm(primary_key, auto_increment = true)]
|
|
pub id: u32,
|
|
#[sea_orm(unique)]
|
|
pub username: String,
|
|
pub hashed_password: String,
|
|
pub owner_id: Option<u32>,
|
|
pub current_bal_id: Option<u32>,
|
|
}
|
|
|
|
impl Model {
|
|
pub fn verify_password(&self, password: String) -> bool {
|
|
let parsed_hash = PasswordHash::new(&self.hashed_password).unwrap();
|
|
Argon2::default().verify_password(password.as_bytes(), &parsed_hash).is_ok()
|
|
}
|
|
}
|
|
|
|
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
|
pub enum Relation {
|
|
#[sea_orm(has_many = "super::owner::Entity")]
|
|
Owner,
|
|
}
|
|
|
|
impl Related<super::owner::Entity> for Entity {
|
|
fn to() -> RelationDef {
|
|
Relation::Owner.def()
|
|
}
|
|
}
|
|
|
|
impl ActiveModelBehavior for ActiveModel {}
|