use serde::{Deserialize, Serialize}; use sqlx::FromRow; use crate::core::*; use crate::model::AccountId; use crate::util::keys::PrivateKeyDer; use crate::util::password::HashedPassword; use crate::util::validate::{ResultBuilder, Validate}; pub type UserId = Id; #[derive(Clone, Deserialize, Serialize, FromRow)] pub struct User { pub id: UserId, pub account_id: AccountId, pub email: String, pub password: HashedPassword, pub reason: Option, pub locale: String, pub activated: bool, pub private_key: PrivateKeyDer, } pub struct NewUser { pub account_id: AccountId, pub email: String, pub password: HashedPassword, pub reason: Option, pub locale: String, pub private_key: PrivateKeyDer, } impl From for UserId { fn from(user: User) -> UserId { user.id } } impl Validate for NewUser { fn validate(&self, builder: ResultBuilder) -> ResultBuilder { builder.field(&self.email, "email", |f| { f.check("Email must not be empty", |v| !v.is_empty()) }) } }