From 0917ef441d9ec46cecfee4496447295f39e45433 Mon Sep 17 00:00:00 2001 From: Jake Probst Date: Tue, 20 Aug 2019 17:59:56 -0700 Subject: [PATCH] db models init --- src/login/models.rs | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 src/login/models.rs diff --git a/src/login/models.rs b/src/login/models.rs new file mode 100644 index 0000000..0f92987 --- /dev/null +++ b/src/login/models.rs @@ -0,0 +1,44 @@ +use std::time::SystemTime; +//use diesel::sql_types::Timestamp; +use diesel::{Insertable, Queryable, Identifiable, Associations}; +//use bcrypt::{DEFAULT_COST, hash}; +//use diesel::serialize::ToSql; +use libpso:: + +use elseware::schema::*; + +#[derive(Queryable, Identifiable, Debug)] +pub struct UserAccount { + pub id: i32, + pub username: String, + pub password: String, + pub guildcard: Option, + pub team_id: Option, + pub banned: bool, + pub muted_until: SystemTime, + pub created_at: SystemTime, +} + +#[derive(Insertable)] +#[table_name="user_accounts"] +pub struct NewUser { + username: String, + password: String, +} + +impl NewUser { + pub fn new(username: String, password: String) -> NewUser { + let crypt_password = bcrypt::hash(password, bcrypt::DEFAULT_COST).expect("could not hash password?"); + NewUser { + username: username, + password: crypt_password, + } + } +} + +#[derive(Queryable, Identifiable, Associations, Debug)] +pub struct UserSettings { + id: i32, + user_id: i32, + settings_blob: [u32; 0x1160], +}