rss-reader/src/user.rs

36 lines
895 B
Rust
Raw Normal View History

2025-02-01 20:07:32 -08:00
use chrono;
use rocket::serde::{Deserialize, Serialize};
use uuid::Uuid;
#[derive(Debug, Serialize)]
#[serde(crate = "rocket::serde")]
pub struct User {
pub id: Uuid,
pub username: String,
pub password_hash: String,
pub email: Option<String>,
pub display_name: Option<String>,
pub created_at: chrono::DateTime<chrono::Utc>,
}
impl User {
pub fn new(username: String, password_hash: String, email: Option<String>, display_name: Option<String>) -> Self {
User {
id: Uuid::new_v4(),
username,
password_hash,
email,
display_name,
created_at: chrono::Utc::now(),
}
}
}
#[derive(Debug, Deserialize)]
#[serde(crate = "rocket::serde")]
pub struct NewUser {
pub username: String,
pub password: String,
pub email: Option<String>,
pub display_name: Option<String>,
}