Browse Source

add more fields to useraccount table

pbs
jake 4 years ago
parent
commit
89c91e9397
  1. 1
      src/bin/main.rs
  2. 1
      src/entity/account.rs
  3. 8
      src/entity/gateway/postgres/migrations/V0001__initial.sql
  4. 4
      src/entity/gateway/postgres/models.rs
  5. 10
      src/entity/gateway/postgres/postgres.rs

1
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,

1
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,

8
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 (

4
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<chrono::DateTime<chrono::Utc>>,
muted: Option<chrono::DateTime<chrono::Utc>>,
@ -31,7 +31,7 @@ impl Into<UserAccountEntity> 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,

10
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<UserAccountEntity> {
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<UserAccountEntity> {
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<CharacterEntity> {
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)")

Loading…
Cancel
Save