From 8ae799a7716549d25a21004daab099fe05e03be7 Mon Sep 17 00:00:00 2001 From: Nils Mittler Date: Mon, 20 Feb 2023 16:39:56 +0100 Subject: [PATCH] Add function to fetch user by email address --- src/api/admin.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/api/admin.rs b/src/api/admin.rs index f22d3bc2..f791d779 100644 --- a/src/api/admin.rs +++ b/src/api/admin.rs @@ -33,6 +33,7 @@ pub fn routes() -> Vec { routes![ get_users_json, get_user_json, + get_user_by_mail_json, post_admin_login, admin_page, invite_user, @@ -331,6 +332,18 @@ async fn users_overview(_token: AdminToken, mut conn: DbConn) -> ApiResult")] +async fn get_user_by_mail_json(mail: String, _token: AdminToken, mut conn: DbConn) -> JsonResult { + if let Some(u) = User::find_by_mail(&mail, &mut conn).await { + let mut usr = u.to_json(&mut conn).await; + usr["UserEnabled"] = json!(u.enabled); + usr["CreatedAt"] = json!(format_naive_datetime_local(&u.created_at, DT_FMT)); + Ok(Json(usr)) + } else { + err_code!("User doesn't exist", Status::NotFound.code); + } +} + #[get("/users/")] async fn get_user_json(uuid: String, _token: AdminToken, mut conn: DbConn) -> JsonResult { let u = get_user_or_404(&uuid, &mut conn).await?;