rename things
This commit is contained in:
parent
f2a6aa01c3
commit
a68c2c31ab
@ -14,7 +14,7 @@ function user_login(res) {
|
|||||||
user = created;
|
user = created;
|
||||||
|
|
||||||
console.log(created);
|
console.log(created);
|
||||||
return send({ method: 'cryp_generate', params: { level: 64 }});
|
return send({ method: 'cryp_spawn', params: { level: 64 }});
|
||||||
}
|
}
|
||||||
|
|
||||||
function new_cryp(cryp) {
|
function new_cryp(cryp) {
|
||||||
@ -22,7 +22,7 @@ function new_cryp(cryp) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const handlers = {
|
const handlers = {
|
||||||
'cryp_generate': new_cryp,
|
'cryp_spawn': new_cryp,
|
||||||
'user_login': user_login,
|
'user_login': user_login,
|
||||||
'user_create': user_login,
|
'user_create': user_login,
|
||||||
};
|
};
|
||||||
|
|||||||
@ -2,7 +2,7 @@ use uuid::Uuid;
|
|||||||
use rand::prelude::*;
|
use rand::prelude::*;
|
||||||
use serde_cbor::*;
|
use serde_cbor::*;
|
||||||
|
|
||||||
use rpc::{GenerateParams};
|
use rpc::{CrypSpawnParams};
|
||||||
use skill::{Skill};
|
use skill::{Skill};
|
||||||
|
|
||||||
#[derive(Debug,Clone,Copy,PartialEq,Serialize,Deserialize)]
|
#[derive(Debug,Clone,Copy,PartialEq,Serialize,Deserialize)]
|
||||||
@ -176,7 +176,7 @@ impl Cryp {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn generate(params: GenerateParams) -> Cryp {
|
pub fn spawn(params: CrypSpawnParams) -> Cryp {
|
||||||
Cryp::new()
|
Cryp::new()
|
||||||
.named("hatchling".to_string())
|
.named("hatchling".to_string())
|
||||||
.level(params.level)
|
.level(params.level)
|
||||||
|
|||||||
@ -4,7 +4,7 @@ use failure::Error;
|
|||||||
use failure::err_msg;
|
use failure::err_msg;
|
||||||
|
|
||||||
use net::Db;
|
use net::Db;
|
||||||
use cryp::{Cryp, generate};
|
use cryp::{Cryp, spawn};
|
||||||
use user::{User, create};
|
use user::{User, create};
|
||||||
|
|
||||||
pub struct Rpc;
|
pub struct Rpc;
|
||||||
@ -23,17 +23,17 @@ impl Rpc {
|
|||||||
// now we have the method name
|
// now we have the method name
|
||||||
// match on that to determine what fn to call
|
// match on that to determine what fn to call
|
||||||
match v.method.as_ref() {
|
match v.method.as_ref() {
|
||||||
"cryp_generate" => {
|
"cryp_spawn" => {
|
||||||
match from_slice::<GenerateMsg>(&data) {
|
match from_slice::<CrypSpawnMsg>(&data) {
|
||||||
Ok(v) => Ok(RpcResponse {
|
Ok(v) => Ok(RpcResponse {
|
||||||
method: v.method,
|
method: v.method,
|
||||||
params: RpcResult::Cryp(generate(v.params))
|
params: RpcResult::Cryp(spawn(v.params))
|
||||||
}),
|
}),
|
||||||
Err(_e) => Err(err_msg("invalid params")),
|
Err(_e) => Err(err_msg("invalid params")),
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"user_create" => {
|
"user_create" => {
|
||||||
match from_slice::<AccountCreateMsg>(&data) {
|
match from_slice::<UserCreateMsg>(&data) {
|
||||||
Ok(v) => Ok(RpcResponse {
|
Ok(v) => Ok(RpcResponse {
|
||||||
method: v.method,
|
method: v.method,
|
||||||
params: create(v.params, db)?
|
params: create(v.params, db)?
|
||||||
@ -69,28 +69,39 @@ pub struct RpcMessage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug,Clone,Serialize,Deserialize)]
|
#[derive(Debug,Clone,Serialize,Deserialize)]
|
||||||
struct GenerateMsg {
|
struct CrypSpawnMsg {
|
||||||
method: String,
|
method: String,
|
||||||
params: GenerateParams,
|
params: CrypSpawnParams,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug,Clone,Serialize,Deserialize)]
|
#[derive(Debug,Clone,Serialize,Deserialize)]
|
||||||
pub struct GenerateParams {
|
pub struct CrypSpawnParams {
|
||||||
pub level: u8,
|
pub level: u8,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug,Clone,Serialize,Deserialize)]
|
#[derive(Debug,Clone,Serialize,Deserialize)]
|
||||||
struct AccountCreateMsg {
|
struct UserCreateMsg {
|
||||||
method: String,
|
method: String,
|
||||||
params: AccountCreateParams,
|
params: UserCreateParams,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug,Clone,Serialize,Deserialize)]
|
#[derive(Debug,Clone,Serialize,Deserialize)]
|
||||||
pub struct AccountCreateParams {
|
pub struct UserCreateParams {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub password: String,
|
pub password: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug,Clone,Serialize,Deserialize)]
|
||||||
|
struct UserLoginMsg {
|
||||||
|
method: String,
|
||||||
|
params: UserLoginParams,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug,Clone,Serialize,Deserialize)]
|
||||||
|
pub struct UserLoginParams {
|
||||||
|
pub name: String,
|
||||||
|
pub password: String,
|
||||||
|
}
|
||||||
|
|
||||||
// #[cfg(test)]
|
// #[cfg(test)]
|
||||||
// mod tests {
|
// mod tests {
|
||||||
|
|||||||
4
server/src/user.rs
Normal file → Executable file
4
server/src/user.rs
Normal file → Executable file
@ -7,7 +7,7 @@ use std::iter;
|
|||||||
use std::str;
|
use std::str;
|
||||||
|
|
||||||
use net::Db;
|
use net::Db;
|
||||||
use rpc::{AccountCreateParams, RpcResult};
|
use rpc::{UserCreateParams, RpcResult};
|
||||||
|
|
||||||
use failure::Error;
|
use failure::Error;
|
||||||
use failure::err_msg;
|
use failure::err_msg;
|
||||||
@ -28,7 +28,7 @@ struct UserEntry {
|
|||||||
|
|
||||||
static PASSWORD_MIN_LEN: usize = 12;
|
static PASSWORD_MIN_LEN: usize = 12;
|
||||||
|
|
||||||
pub fn create(params: AccountCreateParams, db: Db) -> Result<RpcResult, Error> {
|
pub fn create(params: UserCreateParams, db: Db) -> Result<RpcResult, Error> {
|
||||||
let id = Uuid::new_v4();
|
let id = Uuid::new_v4();
|
||||||
|
|
||||||
if params.password.len() < PASSWORD_MIN_LEN {
|
if params.password.len() < PASSWORD_MIN_LEN {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user