From aa84768e5810e17722cc17f0e95f806d64f1e811 Mon Sep 17 00:00:00 2001 From: jake Date: Sun, 12 Nov 2023 00:47:59 -0700 Subject: [PATCH] this file has never been used why is it here --- src/login/models.rs | 92 --------------------------------------------- 1 file changed, 92 deletions(-) delete mode 100644 src/login/models.rs diff --git a/src/login/models.rs b/src/login/models.rs deleted file mode 100644 index c5fb059..0000000 --- a/src/login/models.rs +++ /dev/null @@ -1,92 +0,0 @@ -use std::time::SystemTime; -use std::io::Write; -//use diesel::sql_types::Timestamp; -use diesel::{Insertable, Queryable, Identifiable, Associations, AsExpression, FromSqlRow}; -//use bcrypt::{DEFAULT_COST, hash}; -use diesel::pg::Pg; -use diesel::sql_types; -use diesel::deserialize::{self, FromSql}; -use diesel::serialize::{self, ToSql, Output, IsNull}; -use diesel::backend::Backend; - -use libpso::character::settings; - -use elseware::schema::*; - -//const ELSEWHERE_COST: u32 = bcrypt::DEFAULT_COST; -const ELSEWHERE_COST: u32 = 5; - -#[derive(Debug, AsExpression, FromSqlRow)] -#[sql_type="sql_types::Binary"] -pub struct EUserSettings(pub settings::UserSettings); - -impl std::ops::Deref for EUserSettings { - type Target = settings::UserSettings; - - fn deref(&self) -> &Self::Target { - &self.0 - } -} - -#[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, ELSEWHERE_COST).expect("could not hash password?"); - NewUser { - username: username, - password: crypt_password, - } - } -} - -#[derive(Queryable, Identifiable, Associations)] -#[belongs_to(UserAccount, foreign_key="user_id")] -#[table_name="user_settings"] -pub struct UserSettings { - pub id: i32, - pub user_id: i32, - //settings: Vec, - pub settings: EUserSettings, -} - -#[derive(Insertable, Debug)] -#[table_name="user_settings"] -pub struct NewUserSettings { - pub user_id: i32, - pub settings: EUserSettings, -} - -impl ToSql for EUserSettings { - fn to_sql(&self, out: &mut Output) -> serialize::Result { - out.write_all(&self.0.as_bytes()[..]) - .map(|_| IsNull::No) - .map_err(|e| Box::new(e) as Box) - } -} - -impl FromSql for EUserSettings { - fn from_sql(bytes: Option<&[u8]>) -> deserialize::Result { - let bytes_vec: Vec = as FromSql>::from_sql(bytes)?; - let mut static_bytes = [0u8; 0x1160]; - static_bytes[..0x1160].clone_from_slice(&bytes_vec); - Ok(EUserSettings(settings::UserSettings::from_bytes(static_bytes))) - } -}