api: implement auth/params

This commit is contained in:
Peter Cai 2020-02-20 20:15:54 +08:00
parent fd2fd263d1
commit 11b2a272b2
No known key found for this signature in database
GPG Key ID: 71F5FB4E4F3FD54F
1 changed files with 30 additions and 1 deletions

View File

@ -7,7 +7,10 @@ use serde::Serialize;
use std::vec::Vec;
pub fn routes() -> impl Into<Vec<rocket::Route>> {
routes![auth]
routes![
auth,
auth_params
]
}
#[derive(Serialize)]
@ -46,4 +49,30 @@ fn auth(db: DbConn, new_user: Json<user::NewUser>) -> Custom<JsonResp<AuthResult
Err(user::UserOpError(e)) =>
error_resp(Status::InternalServerError, vec![e])
}
}
#[derive(Serialize)]
struct AuthParams {
pw_cost: String,
pw_nonce: String,
version: String
}
impl Into<AuthParams> for user::User {
fn into(self) -> AuthParams {
AuthParams {
pw_cost: self.pw_cost,
pw_nonce: self.pw_nonce,
version: self.version
}
}
}
#[get("/auth/params?<email>")]
fn auth_params(db: DbConn, email: String) -> Custom<JsonResp<AuthParams>> {
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])
}
}