Skip to content
This repository has been archived by the owner on Mar 19, 2021. It is now read-only.

Commit

Permalink
feat(lib): add create_account
Browse files Browse the repository at this point in the history
  • Loading branch information
sergeysova committed Jul 6, 2018
1 parent aa6a468 commit a16b2aa
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ extern crate failure;
extern crate ron;
extern crate rustbreak;

use actix_web::{server, App, HttpRequest, Responder};
use actix_web::{server, App, HttpRequest, Responder, Json, http};
use failure::Fail;
use std::collections::HashMap;
use std::sync::{Arc, Mutex};
Expand All @@ -26,7 +26,7 @@ fn index(req: HttpRequest<AppState>) -> impl Responder {
let count = db.tokens.len();
let token = format!("tok{}", count);
db.tokens.insert(count, String::from(token));
db.save();
let _ = db.save();

println!("after: {:?}", db.to_string());

Expand All @@ -37,6 +37,16 @@ fn index(req: HttpRequest<AppState>) -> impl Responder {
"Ok"
}

#[derive(Deserialize)]
struct NewAccount {
email: String,
password: String,
}

fn create_account(account: Json<NewAccount>) -> impl Responder {
format!("Form: email: {}, password: {}", account.email, account.password)
}

pub fn create_server() -> Result<(), failure::Error> {
// db::test_db().unwrap();
let database = db::Database::load()?;
Expand All @@ -47,6 +57,9 @@ pub fn create_server() -> Result<(), failure::Error> {
App::with_state(AppState {
db,
}).resource("/", |r| r.f(index))
.resource("/account", |r| {
r.method(http::Method::POST).with(create_account)
})
}).workers(2)
.bind("127.0.0.1:9000")
.expect("Can not bind to 127.0.0.1:9000");
Expand Down

0 comments on commit a16b2aa

Please sign in to comment.