what the
This commit is contained in:
parent
407c62fc8a
commit
0e0cd0fdcd
@ -1,7 +1,12 @@
|
||||
exports.up = async knex => {
|
||||
return knex.schema.createTable('users', table => {
|
||||
table.uuid('id').primary();
|
||||
table.text('name');
|
||||
table.string('name', 42).notNullable().unique();
|
||||
table.string('password').notNullable();
|
||||
table.string('token', 64).notNullable();
|
||||
|
||||
table.index('name');
|
||||
table.index('id');
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@ -9,7 +9,9 @@ uuid = { version = "0.5", features = ["serde", "v4"] }
|
||||
serde = "1"
|
||||
serde_derive = "1"
|
||||
serde_cbor = "0.9"
|
||||
|
||||
ws = "*"
|
||||
bcrypt = "0.2"
|
||||
|
||||
dotenv = "0.9.0"
|
||||
env_logger = "*"
|
||||
|
||||
@ -82,7 +82,7 @@ pub fn test_battle() {
|
||||
|
||||
match outcome.winner() {
|
||||
Some(w) => println!("{:?} is the winner with {:?} hp remaining", w.name, w.hp),
|
||||
None => println!("{:?} was a draw", outcome),
|
||||
// None => println!("{:?} was a draw", outcome),
|
||||
};
|
||||
|
||||
return
|
||||
|
||||
@ -1,8 +1,6 @@
|
||||
use uuid::Uuid;
|
||||
use rand::prelude::*;
|
||||
use serde_cbor::*;
|
||||
use std::fs::File;
|
||||
use std::io::prelude::*;
|
||||
|
||||
use rpc::{GenerateParams};
|
||||
use skill::{Skill};
|
||||
@ -104,7 +102,7 @@ impl Cryp {
|
||||
};
|
||||
}
|
||||
|
||||
pub fn named(mut self, name: String) -> Cryp {
|
||||
pub fn named(self, name: String) -> Cryp {
|
||||
self.name = name.clone();
|
||||
self
|
||||
}
|
||||
|
||||
@ -14,6 +14,8 @@ extern crate serde_cbor;
|
||||
#[macro_use]
|
||||
extern crate serde_derive;
|
||||
|
||||
extern crate bcrypt;
|
||||
|
||||
mod cryp;
|
||||
mod battle;
|
||||
mod net;
|
||||
|
||||
@ -32,7 +32,7 @@ impl Handler for Server {
|
||||
fn on_close(&mut self, code: CloseCode, reason: &str) {
|
||||
match code {
|
||||
CloseCode::Normal => println!("The client is done with the connection."),
|
||||
CloseCode::Away => println!("The client is leaving the site."),
|
||||
// CloseCode::Away => println!("The client is leaving the site."),
|
||||
CloseCode::Abnormal => println!(
|
||||
"Closing handshake failed! Unable to obtain closing status from client."),
|
||||
_ => println!("The client encountered an error: {}", reason),
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
use std::result::Result as StdResult;
|
||||
use ws::{Message};
|
||||
use serde_cbor::{from_slice};
|
||||
use serde_cbor::error::Error as CborError;
|
||||
|
||||
use net::Db;
|
||||
use cryp::generate;
|
||||
@ -73,6 +72,7 @@ struct AccountCreateMsg {
|
||||
#[derive(Debug,Clone,Serialize,Deserialize)]
|
||||
pub struct AccountCreateParams {
|
||||
pub name: String,
|
||||
pub password: String,
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -3,22 +3,33 @@ use uuid::Uuid;
|
||||
|
||||
use net::Db;
|
||||
use rpc::{AccountCreateParams};
|
||||
use bcrypt::{DEFAULT_COST, hash};
|
||||
|
||||
struct User {
|
||||
name: String,
|
||||
password: String,
|
||||
id: Uuid,
|
||||
}
|
||||
|
||||
pub fn create(params: AccountCreateParams, db: Db) -> Vec<u8> {
|
||||
let pw_hash = hash(¶ms.password, DEFAULT_COST)
|
||||
.expect("unable to hash password");
|
||||
|
||||
let uuid = Uuid::new_v4();
|
||||
|
||||
let user = User {
|
||||
id: uuid,
|
||||
password: pw_hash,
|
||||
name: params.name,
|
||||
};
|
||||
|
||||
let entry = db.execute("INSERT INTO users (id, name)
|
||||
VALUES (?1, ?2)",
|
||||
&[&user.id.to_string(), &user.name]).unwrap();
|
||||
let query = "
|
||||
INSERT INTO users (id, name, password)
|
||||
VALUES ($1, $2, $3)
|
||||
";
|
||||
|
||||
let entry = db
|
||||
.query(query, &[&user.id.to_string(), &user.name]).unwrap();
|
||||
|
||||
println!("{:?}", entry);
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user