From f903e653d59fa923210f5a583f7f8adc663a5dd5 Mon Sep 17 00:00:00 2001 From: Katharina Fey Date: Mon, 2 Jul 2018 21:53:59 +0200 Subject: This doesn't work --- lockchain-http/src/handlers.rs | 51 +++++++++++++++------------------- lockchain-http/src/lib.rs | 8 ------ lockchain-http/src/models/inputs.rs | 7 ----- lockchain-http/src/models/responses.rs | 22 +++++++++++---- 4 files changed, 39 insertions(+), 49 deletions(-) (limited to 'lockchain-http') diff --git a/lockchain-http/src/handlers.rs b/lockchain-http/src/handlers.rs index 369f888..2b220a2 100644 --- a/lockchain-http/src/handlers.rs +++ b/lockchain-http/src/handlers.rs @@ -174,43 +174,38 @@ where } /// PUT /authenticate -pub fn authenticate(_req: HttpRequestState>) -> impl Responder -where - B: Body, - V: Vault, -{ - Json(OperationFailed { - reason: "Not implemented".into(), - code: 255, - }) -} - -/// PUT /de-authenticate -pub fn deauthenticate(_req: HttpRequestState>) -> impl Responder +pub fn authenticate( + (item, req): (Json, HttpRequestState>), +) -> impl Responder where B: Body, V: Vault, { - Json(OperationFailed { - reason: "Not implemented".into(), - code: 255, - }) -} + use lockchain::users::*; + let Authenticate { username, password } = item.into_inner(); -/// PUT /de-authenticate -pub fn register(_req: HttpRequestState>) -> impl Responder -where - B: Body, - V: Vault, -{ - Json(OperationFailed { - reason: "Not implemented".into(), - code: 255, + Json(match pam_authenticate(&username, &password) { + Ok(()) => CarrierMessage { + error: Ok(()), + data: Some(TokenMessage { + username, + token: String::new(), + }), + }, + Err(e) => CarrierMessage { + error: Err(e.into()), + data: Some(OperationFailed { + reason: "Meh!".into(), + code: 1, + }), + }, }) } /// PUT /de-authenticate -pub fn get_all_users(_req: HttpRequestState>) -> impl Responder +pub fn deauthenticate( + (item, req): (Json, HttpRequestState>), +) -> impl Responder where B: Body, V: Vault, diff --git a/lockchain-http/src/lib.rs b/lockchain-http/src/lib.rs index 95d27d2..dfe1211 100644 --- a/lockchain-http/src/lib.rs +++ b/lockchain-http/src/lib.rs @@ -114,14 +114,6 @@ where // Hand-in active auth token r.method(http::Method::POST).with(handlers::deauthenticate) }) - .resource("/users/register", |r| { - // Register a new user (if allowed) - r.method(http::Method::POST).with(handlers::register); - }) - .resource("/users/", |r| { - // Get all available users - r.method(http::Method::GET).with(handlers::get_all_users); - }) .resource("/api", |r| { r.method(http::Method::GET).with(handlers::api_data); }), diff --git a/lockchain-http/src/models/inputs.rs b/lockchain-http/src/models/inputs.rs index 172b204..4e1ae79 100644 --- a/lockchain-http/src/models/inputs.rs +++ b/lockchain-http/src/models/inputs.rs @@ -76,10 +76,3 @@ pub struct Authenticate { pub struct Deauthenticate { pub token: String, } - -#[derive(Serialize, Deserialize)] -pub struct Register { - pub username: String, - pub password: String, - pub requested_role: Option, -} diff --git a/lockchain-http/src/models/responses.rs b/lockchain-http/src/models/responses.rs index ac4e74b..436d3e6 100644 --- a/lockchain-http/src/models/responses.rs +++ b/lockchain-http/src/models/responses.rs @@ -1,7 +1,5 @@ - - -use lockchain::errors::Error as LockError; use serde::{de::DeserializeOwned, Serialize}; +use std::error::Error; /// A generic container that json/error wraps lockchain-types /// @@ -9,8 +7,13 @@ use serde::{de::DeserializeOwned, Serialize}; /// to send both encrypted and cleartext data via the API endpoint, using /// the same code. #[derive(Serialize, Deserialize)] -pub struct CarrierMessage { - pub error: Result<(), LockError>, +pub struct CarrierMessage +where + T: Serialize + DeserializeOwned, + E: Error + Serialize + DeserializeOwned, +{ + #[serde(bound(deserialize = "E: Serialize + DeserializeOwned"))] + pub error: Result<(), E>, #[serde(bound(deserialize = "T: Serialize + DeserializeOwned"))] pub data: Option, } @@ -22,6 +25,13 @@ pub struct OperationFailed { pub code: u32, } +/// Message that returns a token +#[derive(Serialize, Deserialize)] +pub struct TokenMessage { + pub username: String, + pub token: String, +} + /// **Returns** Api information #[derive(Serialize, Deserialize)] pub struct ApiInformation { @@ -44,4 +54,4 @@ pub struct VaultCreateResponse { pub name: String, pub created: bool, pub error: Option, -} \ No newline at end of file +} -- cgit v1.2.3