Attempt to create a simple database call.
This commit is contained in:
parent
85341141e7
commit
13198c9f5f
26
src/main.rs
26
src/main.rs
|
@ -6,8 +6,9 @@ extern crate hyper;
|
|||
|
||||
use docopt::Docopt;
|
||||
use actix_web::{server, App, HttpRequest, Responder, Json, HttpResponse};
|
||||
use actix_web::http::{Method, StatusCode};
|
||||
use hyper::Client;
|
||||
use actix_web::http::StatusCode;
|
||||
use hyper::{Body, Client, Method, Request};
|
||||
use hyper::header::HeaderValue;
|
||||
use hyper::rt::{self, Future, Stream};
|
||||
|
||||
const USAGE: &'static str = "
|
||||
|
@ -93,7 +94,6 @@ fn status(_req: HttpRequest) -> impl Responder {
|
|||
|
||||
fn auth(credentials: Json<UserCredentialsRequest>) -> impl Responder {
|
||||
|
||||
// TODO: Check against the application credentials listed in the application or database.
|
||||
let db_connection = std::env::var_os("ROOKERIES_COUCHDB");
|
||||
if db_connection.is_none() {
|
||||
return json_error_message(
|
||||
|
@ -102,6 +102,26 @@ fn auth(credentials: Json<UserCredentialsRequest>) -> impl Responder {
|
|||
);
|
||||
}
|
||||
|
||||
// TODO: Clean up this entire thing.
|
||||
let client = Client::new();
|
||||
|
||||
let couchdb_uri : hyper::Uri = format!("{}/_find/", db_connection.unwrap().into_string().unwrap()).parse().unwrap();
|
||||
let json = r#"{"selector": {"username": credentials.username}}"#;
|
||||
let mut req = Request::new(Body::from(json));
|
||||
*req.method_mut() = Method::POST;
|
||||
*req.uri_mut() = couchdb_uri.clone();
|
||||
req.headers_mut().insert("content-type", HeaderValue::from_str("application/json").unwrap());
|
||||
|
||||
let post = client.request(req).and_then(|res| {
|
||||
println!("POST: {}", res.status());
|
||||
res.into_body().concat2()
|
||||
});
|
||||
|
||||
|
||||
|
||||
// client.post(couchdb_uri)
|
||||
|
||||
// TODO: Check against the application credentials listed in the application or database.
|
||||
json_error_message(StatusCode::UNAUTHORIZED, "Invalid credentials provided.")
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue