Skip to content

Commit

Permalink
Return 404 when user public_key is empty
Browse files Browse the repository at this point in the history
  • Loading branch information
Timshel committed Jan 26, 2024
1 parent 2aa5777 commit 9bc5cf8
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/api/core/accounts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,14 +340,17 @@ async fn put_avatar(data: JsonUpcase<AvatarData>, headers: Headers, mut conn: Db
async fn get_public_keys(uuid: &str, _headers: Headers, mut conn: DbConn) -> JsonResult {
let user = match User::find_by_uuid(uuid, &mut conn).await {
Some(user) => user,
None => err!("User doesn't exist"),
None => err_code!("User doesn't exist", Status::NotFound.code),
};

Ok(Json(json!({
"UserId": user.uuid,
"PublicKey": user.public_key,
"Object":"userKey"
})))
match user.public_key {
None => err_code!("User has no public_key", Status::NotFound.code),
Some(public_key) => Ok(Json(json!({
"UserId": user.uuid,
"PublicKey": public_key,
"Object":"userKey"
}))),
}
}

#[post("/accounts/keys", data = "<data>")]
Expand Down

0 comments on commit 9bc5cf8

Please sign in to comment.