user module

This commit is contained in:
Greg Shuflin 2025-02-01 20:07:32 -08:00
parent 7c53550895
commit 899240bdbc
2 changed files with 40 additions and 34 deletions

View File

@ -1,13 +1,16 @@
#[macro_use]
extern crate rocket;
mod user;
use rocket::fs::FileServer;
use rocket::http::Status;
use rocket::serde::{json::Json, Deserialize, Serialize};
use rocket::serde::{json::Json, Serialize};
use rocket_db_pools::{sqlx, Connection, Database};
use rocket_dyn_templates::{context, Template};
use uuid::Uuid;
use bcrypt;
use user::{User, NewUser};
#[derive(Database)]
#[database("rss_data")]
@ -20,39 +23,6 @@ struct Message {
b: String,
}
#[derive(Debug, Serialize)]
#[serde(crate = "rocket::serde")]
struct User {
id: Uuid,
username: String,
password_hash: String,
email: Option<String>,
display_name: Option<String>,
created_at: chrono::DateTime<chrono::Utc>,
}
impl User {
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")]
struct NewUser {
username: String,
password: String,
email: Option<String>,
display_name: Option<String>,
}
#[get("/message")]
fn message() -> Json<Message> {
Json(Message {

36
src/user.rs Normal file
View File

@ -0,0 +1,36 @@
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>,
}