From 11b2a272b2fc71782db5732c6d7b6d18bf1bf87e Mon Sep 17 00:00:00 2001 From: Peter Cai Date: Thu, 20 Feb 2020 20:15:54 +0800 Subject: [PATCH] api: implement auth/params --- src/api.rs | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/src/api.rs b/src/api.rs index a656132..3e0e5a5 100644 --- a/src/api.rs +++ b/src/api.rs @@ -7,7 +7,10 @@ use serde::Serialize; use std::vec::Vec; pub fn routes() -> impl Into> { - routes![auth] + routes![ + auth, + auth_params + ] } #[derive(Serialize)] @@ -46,4 +49,30 @@ fn auth(db: DbConn, new_user: Json) -> Custom error_resp(Status::InternalServerError, vec![e]) } +} + +#[derive(Serialize)] +struct AuthParams { + pw_cost: String, + pw_nonce: String, + version: String +} + +impl Into for user::User { + fn into(self) -> AuthParams { + AuthParams { + pw_cost: self.pw_cost, + pw_nonce: self.pw_nonce, + version: self.version + } + } +} + +#[get("/auth/params?")] +fn auth_params(db: DbConn, email: String) -> Custom> { + match user::User::find_user_by_email(&db, &email) { + Ok(u) => success_resp(u.into()), + Err(user::UserOpError(e)) => + error_resp(Status::InternalServerError, vec![e]) + } } \ No newline at end of file