From d8f80c973159813a5937395a0f53c042b0c738c2 Mon Sep 17 00:00:00 2001 From: curly Date: Wed, 17 Jul 2024 16:28:00 -0600 Subject: make new keys with admin user --- src/main.rs | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs index 63a497d..81b416c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -22,11 +22,12 @@ async fn index() -> &'static str { struct AuthUserOut { name: String, id: UID, + is_admin: bool, tokovec: Vec, } impl Into for User { fn into(self) -> AuthUserOut { - AuthUserOut { name: self.get_name(), id: self.get_id(), tokovec: self.get_tokovec() } + AuthUserOut { name: self.get_name(), id: self.get_id(), is_admin: self.is_admin(), tokovec: self.get_tokovec() } } } #[derive(Serialize)] @@ -222,6 +223,33 @@ async fn update_name(data: Json, db: &State>) -> ( } } +#[derive(Deserialize)] +struct NewRegistrationKeyForm { + id: UID, + session: String, + key: String, +} + +#[post("/regkey/new", data="", format="json")] +async fn new_registration_key(data: Json, db: &State>) -> (Status, Result<(), Json>) { + let mut db = db.lock().await; + match db.new_registration_key(data.id, &data.session, &data.key).await { + Ok(_) => (Status::Ok, Ok(())), + Err(n) => (Status::InternalServerError, Err(n.into())) + } +} + +#[post("/regkey/list", data="", format="json")] +async fn list_registration_keys(data: Json, db: &State>) -> (Status, Result<(), Json>) { + (Status::NotFound, Err("NOT IMPLEMENTED".to_string().into())) +} + +#[post("/regkey/del", data="", format="json")] +async fn del_registration_key(data: Json, db: &State>) -> (Status, Result<(), Json>) { + (Status::NotFound, Err("NOT IMPLEMENTED".to_string().into())) +} + + #[derive(Deserialize, Debug)] struct TransferForm { id: UID, @@ -259,5 +287,6 @@ fn rocket() -> _ { .mount("/user", routes![login, get_users_by_name, get_user_authenticated, get_user, new_user, get_all_users, logout, logout_all, get_sessions, delete]) .mount("/user/update", routes![update_name, update_password]) .mount("/transfer", routes![transfer_out]) + .mount("/admin", routes![new_registration_key, list_registration_keys, del_registration_key]) .attach(cors) } \ No newline at end of file -- cgit v1.2.3