add more fields to useraccount table
This commit is contained in:
parent
6d82751ed3
commit
89c91e9397
@ -53,6 +53,7 @@ fn main() {
|
|||||||
|
|
||||||
for i in 0..5 {
|
for i in 0..5 {
|
||||||
let fake_user = NewUserAccountEntity {
|
let fake_user = NewUserAccountEntity {
|
||||||
|
email: format!("fake{}@email.com", i),
|
||||||
username: if i == 0 { "hi".to_string() } else { format!("hi{}", i+1) },
|
username: if i == 0 { "hi".to_string() } else { format!("hi{}", i+1) },
|
||||||
password: bcrypt::hash("qwer", 5).unwrap(),
|
password: bcrypt::hash("qwer", 5).unwrap(),
|
||||||
guildcard: i + 1,
|
guildcard: i + 1,
|
||||||
|
@ -17,6 +17,7 @@ pub struct GuildCardDataId(pub u32);
|
|||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct NewUserAccountEntity {
|
pub struct NewUserAccountEntity {
|
||||||
|
pub email: String,
|
||||||
pub username: String,
|
pub username: String,
|
||||||
pub password: String,
|
pub password: String,
|
||||||
pub guildcard: u32,
|
pub guildcard: u32,
|
||||||
|
@ -1,11 +1,15 @@
|
|||||||
create table user_accounts (
|
create table user_accounts (
|
||||||
id serial primary key not null,
|
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,
|
password varchar(128) not null,
|
||||||
banned timestamptz,
|
banned timestamptz,
|
||||||
muted timestamptz,
|
muted timestamptz,
|
||||||
created_at timestamptz default current_timestamp not null,
|
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 (
|
create table user_settings (
|
||||||
|
@ -19,7 +19,7 @@ use postgres::{Client, NoTls};
|
|||||||
#[derive(Debug, sqlx::FromRow)]
|
#[derive(Debug, sqlx::FromRow)]
|
||||||
pub struct PgUserAccount {
|
pub struct PgUserAccount {
|
||||||
id: i32,
|
id: i32,
|
||||||
name: String,
|
username: String,
|
||||||
password: String,
|
password: String,
|
||||||
banned: Option<chrono::DateTime<chrono::Utc>>,
|
banned: Option<chrono::DateTime<chrono::Utc>>,
|
||||||
muted: Option<chrono::DateTime<chrono::Utc>>,
|
muted: Option<chrono::DateTime<chrono::Utc>>,
|
||||||
@ -31,7 +31,7 @@ impl Into<UserAccountEntity> for PgUserAccount {
|
|||||||
fn into(self) -> UserAccountEntity {
|
fn into(self) -> UserAccountEntity {
|
||||||
UserAccountEntity {
|
UserAccountEntity {
|
||||||
id: UserAccountId(self.id as u32),
|
id: UserAccountId(self.id as u32),
|
||||||
username: self.name,
|
username: self.username,
|
||||||
password: self.password,
|
password: self.password,
|
||||||
banned_until: self.banned,
|
banned_until: self.banned,
|
||||||
muted_until: self.muted,
|
muted_until: self.muted,
|
||||||
|
@ -97,7 +97,8 @@ impl PostgresGateway {
|
|||||||
#[async_trait::async_trait]
|
#[async_trait::async_trait]
|
||||||
impl EntityGateway for PostgresGateway {
|
impl EntityGateway for PostgresGateway {
|
||||||
async fn create_user(&mut self, user: NewUserAccountEntity) -> Option<UserAccountEntity> {
|
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.username)
|
||||||
.bind(user.password)
|
.bind(user.password)
|
||||||
.fetch_one(&self.pool).await.unwrap();
|
.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> {
|
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)
|
.bind(username)
|
||||||
.fetch_one(&self.pool).await.unwrap();
|
.fetch_one(&self.pool).await.unwrap();
|
||||||
Some(user.into())
|
Some(user.into())
|
||||||
@ -167,9 +168,9 @@ impl EntityGateway for PostgresGateway {
|
|||||||
async fn create_character(&mut self, char: NewCharacterEntity) -> Option<CharacterEntity> {
|
async fn create_character(&mut self, char: NewCharacterEntity) -> Option<CharacterEntity> {
|
||||||
let q = r#"insert into player_character
|
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,
|
(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
|
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 *;"#;
|
returning *;"#;
|
||||||
let character = sqlx::query_as::<_, PgCharacter>(q)
|
let character = sqlx::query_as::<_, PgCharacter>(q)
|
||||||
//sqlx::query(q)
|
//sqlx::query(q)
|
||||||
@ -203,6 +204,7 @@ impl EntityGateway for PostgresGateway {
|
|||||||
.bind(char.tech_menu.tech_menu.to_vec())
|
.bind(char.tech_menu.tech_menu.to_vec())
|
||||||
.bind(char.meseta as i32)
|
.bind(char.meseta as i32)
|
||||||
.bind(char.bank_meseta as i32)
|
.bind(char.bank_meseta as i32)
|
||||||
|
.bind(char.option_flags as i32)
|
||||||
.fetch_one(&self.pool).await.unwrap();
|
.fetch_one(&self.pool).await.unwrap();
|
||||||
|
|
||||||
sqlx::query("insert into inventory_slots (pchar) values ($1)")
|
sqlx::query("insert into inventory_slots (pchar) values ($1)")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user