You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

46 lines
1.0 KiB
Rust

use serde::{Deserialize, Serialize};
use sqlx::FromRow;
use crate::core::*;
use crate::model::AccountId;
use crate::util::crypto::PrivKey;
use crate::util::password::HashedPassword;
use crate::util::validate::{ResultBuilder, Validate};
pub type UserId = Id<User>;
#[derive(Clone, Deserialize, Serialize, FromRow)]
pub struct User {
pub id: UserId,
pub account_id: AccountId,
pub email: String,
pub password: HashedPassword,
pub reason: Option<String>,
pub locale: String,
pub activated: bool,
pub private_key: PrivKey,
}
pub struct NewUser {
pub account_id: AccountId,
pub email: String,
pub password: HashedPassword,
pub reason: Option<String>,
pub locale: String,
pub private_key: PrivKey,
}
impl From<User> 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())
})
}
}