api: implement auth/params
This commit is contained in:
parent
fd2fd263d1
commit
11b2a272b2
31
src/api.rs
31
src/api.rs
|
@ -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])
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue