All checks were successful
Release Tagging / release (push) Successful in 31s
Rust Build / Check (push) Successful in 28s
Rust Build / Test Suite (push) Successful in 32s
Rust Build / Rustfmt (push) Successful in 32s
Rust Build / Clippy (push) Successful in 31s
Rust Build / build (push) Successful in 33s
Reviewed-on: #27 Co-authored-by: phoenix <kundeng94@gmail.com> Co-committed-by: phoenix <kundeng94@gmail.com>
88 lines
2.5 KiB
Rust
88 lines
2.5 KiB
Rust
use std::default::Default;
|
|
|
|
use crate::init;
|
|
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
#[derive(Clone, Debug, Deserialize, Serialize)]
|
|
pub struct User {
|
|
#[serde(skip_serializing_if = "init::is_uuid_nil")]
|
|
pub id: uuid::Uuid,
|
|
#[serde(skip_serializing_if = "String::is_empty")]
|
|
pub username: String,
|
|
#[serde(skip_serializing_if = "String::is_empty")]
|
|
pub password: String,
|
|
#[serde(skip_serializing_if = "String::is_empty")]
|
|
pub email: String,
|
|
#[serde(skip_serializing_if = "String::is_empty")]
|
|
pub phone: String,
|
|
#[serde(skip_serializing_if = "String::is_empty")]
|
|
pub firstname: String,
|
|
#[serde(skip_serializing_if = "String::is_empty")]
|
|
pub lastname: String,
|
|
pub email_verified: bool,
|
|
#[serde(skip_serializing_if = "String::is_empty")]
|
|
pub date_created: String,
|
|
#[serde(skip_serializing_if = "String::is_empty")]
|
|
pub status: String,
|
|
#[serde(skip_serializing_if = "String::is_empty")]
|
|
pub last_login: String,
|
|
#[serde(skip_serializing_if = "init::is_uuid_nil")]
|
|
pub salt_id: uuid::Uuid,
|
|
}
|
|
|
|
impl Default for User {
|
|
fn default() -> Self {
|
|
User {
|
|
id: uuid::Uuid::new_v4(),
|
|
username: String::new(),
|
|
password: String::new(),
|
|
email: String::new(),
|
|
phone: String::new(),
|
|
firstname: String::new(),
|
|
lastname: String::new(),
|
|
email_verified: false,
|
|
date_created: String::new(),
|
|
status: String::new(),
|
|
last_login: String::new(),
|
|
salt_id: uuid::Uuid::nil(),
|
|
}
|
|
}
|
|
}
|
|
|
|
impl User {
|
|
pub fn to_json(&self, output_pretty: bool) -> Result<String, serde_json::Error> {
|
|
if output_pretty {
|
|
serde_json::to_string_pretty(&self)
|
|
} else {
|
|
serde_json::to_string(&self)
|
|
}
|
|
}
|
|
}
|
|
|
|
pub mod salt {
|
|
use std::default::Default;
|
|
|
|
use crate::init;
|
|
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
|
|
pub struct Salt {
|
|
#[serde(skip_serializing_if = "init::is_uuid_nil")]
|
|
pub id: uuid::Uuid,
|
|
#[serde(skip_serializing_if = "String::is_empty")]
|
|
pub salt: String,
|
|
}
|
|
|
|
impl Salt {
|
|
pub fn to_json(&self, output_pretty: bool) -> Result<String, serde_json::Error> {
|
|
if output_pretty {
|
|
serde_json::to_string_pretty(&self)
|
|
} else {
|
|
serde_json::to_string(&self)
|
|
}
|
|
}
|
|
}
|
|
}
|