From 3d8d55ecc531f6db73fcf86ac44ce28b9bf097c9 Mon Sep 17 00:00:00 2001 From: curly Date: Tue, 27 Aug 2024 15:25:27 -0600 Subject: UID 0000 can be registered with --- TODO | 5 ++++- src/main.rs | 43 +++++++++++++++++++++---------------------- src/uid.rs | 1 - 3 files changed, 25 insertions(+), 24 deletions(-) diff --git a/TODO b/TODO index cc8ac62..4643273 100644 --- a/TODO +++ b/TODO @@ -4,4 +4,7 @@ Token Stock Prices (Values) Config Trade Requests Admin user recovery -user recovery \ No newline at end of file +user recovery +Email +Bets/Requests +Testing \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 6135e97..88123df 100644 --- a/src/main.rs +++ b/src/main.rs @@ -74,15 +74,11 @@ async fn get_all_users(db: &State>) -> (Status, Result UID { - uid::EMPTY_UID -} #[derive(Deserialize)] struct RegisterForm { name: String, password: String, - #[serde(default = "default_id")] - id: UID, + id: Option, key: String, } #[post("/register", data="", format="json")] @@ -96,26 +92,29 @@ async fn new_user(data: Json, db: &State>) -> (Status, R return (Status::BadRequest, Err("Invalid Username".to_string().into())) } - if data.id == uid::EMPTY_UID { - match db.uid_generator.new_uid() { - // Gotten a new UID to make a new user with - Ok(n) => id = Some(n), - // Did not get a new UID - Err(n) => return (Status::InternalServerError, Err(n.clone().into())), - }; - } else { - if db.uid_generator.is_taken(data.id) { - // UID is taken - return (Status::BadRequest, Err("UID is taken".to_string().into())); - } else { - // UID is not taken - match db.uid_generator.add_uid(data.id) { - // Could not add UID for some reason - Err(n) => return (Status::InternalServerError, Err(n.into())), - // Made + match data.id { + None => { + match db.uid_generator.new_uid() { + // Gotten a new UID to make a new user with Ok(n) => id = Some(n), + // Did not get a new UID + Err(n) => return (Status::InternalServerError, Err(n.clone().into())), }; } + Some(n) => { + if db.uid_generator.is_taken(n) { + // UID is taken + return (Status::BadRequest, Err("UID is taken".to_string().into())); + } else { + // UID is not taken + match db.uid_generator.add_uid(n) { + // Could not add UID for some reason + Err(n) => return (Status::InternalServerError, Err(n.into())), + // Made + Ok(n) => id = Some(n), + }; + } + } } match id { diff --git a/src/uid.rs b/src/uid.rs index ad18b7e..8b6f129 100644 --- a/src/uid.rs +++ b/src/uid.rs @@ -4,7 +4,6 @@ use serde::{de::{IntoDeserializer, Visitor}, Deserialize, Deserializer, Serializ #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub struct UID(u8, u8); -pub const EMPTY_UID: UID = UID(0,0); struct UIDVisitor; impl<'de> Visitor<'de> for UIDVisitor { type Value = UID; -- cgit v1.2.3