user module
This commit is contained in:
parent
7c53550895
commit
899240bdbc
38
src/main.rs
38
src/main.rs
@ -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
36
src/user.rs
Normal 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>,
|
||||
}
|
Loading…
Reference in New Issue
Block a user