diff --git a/src/bin/main.rs b/src/bin/main.rs index 640f6e8..fe379e0 100644 --- a/src/bin/main.rs +++ b/src/bin/main.rs @@ -53,6 +53,7 @@ fn main() { for i in 0..5 { let fake_user = NewUserAccountEntity { + email: format!("fake{}@email.com", i), username: if i == 0 { "hi".to_string() } else { format!("hi{}", i+1) }, password: bcrypt::hash("qwer", 5).unwrap(), guildcard: i + 1, diff --git a/src/entity/account.rs b/src/entity/account.rs index 60a23ac..d62f75e 100644 --- a/src/entity/account.rs +++ b/src/entity/account.rs @@ -17,6 +17,7 @@ pub struct GuildCardDataId(pub u32); #[derive(Clone, Debug)] pub struct NewUserAccountEntity { + pub email: String, pub username: String, pub password: String, pub guildcard: u32, diff --git a/src/entity/gateway/postgres/migrations/V0001__initial.sql b/src/entity/gateway/postgres/migrations/V0001__initial.sql index 6f9bba7..c5805f1 100644 --- a/src/entity/gateway/postgres/migrations/V0001__initial.sql +++ b/src/entity/gateway/postgres/migrations/V0001__initial.sql @@ -1,11 +1,15 @@ create table user_accounts ( id serial primary key not null, - name varchar(128) not null unique, + email varchar(128) not null unique, + username varchar(128) not null unique, password varchar(128) not null, banned timestamptz, muted timestamptz, created_at timestamptz default current_timestamp not null, - flags integer default 0 + flags integer default 0 not null, + activated boolean default false not null, + game_session integer, + interserver_session integer ); create table user_settings ( diff --git a/src/entity/gateway/postgres/models.rs b/src/entity/gateway/postgres/models.rs index fb1ccb6..7d508d6 100644 --- a/src/entity/gateway/postgres/models.rs +++ b/src/entity/gateway/postgres/models.rs @@ -19,7 +19,7 @@ use postgres::{Client, NoTls}; #[derive(Debug, sqlx::FromRow)] pub struct PgUserAccount { id: i32, - name: String, + username: String, password: String, banned: Option>, muted: Option>, @@ -31,7 +31,7 @@ impl Into for PgUserAccount { fn into(self) -> UserAccountEntity { UserAccountEntity { id: UserAccountId(self.id as u32), - username: self.name, + username: self.username, password: self.password, banned_until: self.banned, muted_until: self.muted, diff --git a/src/entity/gateway/postgres/postgres.rs b/src/entity/gateway/postgres/postgres.rs index 2e03a5a..c26650f 100644 --- a/src/entity/gateway/postgres/postgres.rs +++ b/src/entity/gateway/postgres/postgres.rs @@ -97,7 +97,8 @@ impl PostgresGateway { #[async_trait::async_trait] impl EntityGateway for PostgresGateway { async fn create_user(&mut self, user: NewUserAccountEntity) -> Option { - let new_user = sqlx::query_as::<_, PgUserAccount>("insert into user_accounts (name, password) values ($1, $2) returning *;") + let new_user = sqlx::query_as::<_, PgUserAccount>("insert into user_accounts (email, username, password) values ($1, $2, $3) returning *;") + .bind(user.email) .bind(user.username) .bind(user.password) .fetch_one(&self.pool).await.unwrap(); @@ -112,7 +113,7 @@ impl EntityGateway for PostgresGateway { } async fn get_user_by_name(&self, username: String) -> Option { - let user = sqlx::query_as::<_, PgUserAccount>("select * from user_accounts where name = $1") + let user = sqlx::query_as::<_, PgUserAccount>("select * from user_accounts where username = $1") .bind(username) .fetch_one(&self.pool).await.unwrap(); Some(user.into()) @@ -167,9 +168,9 @@ impl EntityGateway for PostgresGateway { async fn create_character(&mut self, char: NewCharacterEntity) -> Option { let q = r#"insert into player_character (user_account, slot, name, exp, class, section_id, costume, skin, face, head, hair, hair_r, hair_g, hair_b, prop_x, prop_y, techs, - config, infoboard, guildcard, power, mind, def, evade, luck, hp, tp, tech_menu, meseta, bank_meseta) + config, infoboard, guildcard, power, mind, def, evade, luck, hp, tp, tech_menu, meseta, bank_meseta, option_flags) values - ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23, $24, $25, $26, $27, $28, $29, $30) + ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23, $24, $25, $26, $27, $28, $29, $30, $31) returning *;"#; let character = sqlx::query_as::<_, PgCharacter>(q) //sqlx::query(q) @@ -203,6 +204,7 @@ impl EntityGateway for PostgresGateway { .bind(char.tech_menu.tech_menu.to_vec()) .bind(char.meseta as i32) .bind(char.bank_meseta as i32) + .bind(char.option_flags as i32) .fetch_one(&self.pool).await.unwrap(); sqlx::query("insert into inventory_slots (pchar) values ($1)")