aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcurly <curly@infernal.garden>2024-08-27 15:25:27 -0600
committercurly <curly@infernal.garden>2024-08-27 15:25:27 -0600
commit3d8d55ecc531f6db73fcf86ac44ce28b9bf097c9 (patch)
treead50642ed610c846d1736c48b9059cb6f783d109
parent22072ec07daabaa46352c764d7b62d3cf32251cc (diff)
downloadpoko_server-3d8d55ecc531f6db73fcf86ac44ce28b9bf097c9.tar.gz
poko_server-3d8d55ecc531f6db73fcf86ac44ce28b9bf097c9.tar.bz2
poko_server-3d8d55ecc531f6db73fcf86ac44ce28b9bf097c9.zip
UID 0000 can be registered with
-rw-r--r--TODO5
-rw-r--r--src/main.rs43
-rw-r--r--src/uid.rs1
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<Mutex<DB>>) -> (Status, Result<Json<Vec<UserOu
}
}
-fn default_id() -> UID {
- uid::EMPTY_UID
-}
#[derive(Deserialize)]
struct RegisterForm {
name: String,
password: String,
- #[serde(default = "default_id")]
- id: UID,
+ id: Option<UID>,
key: String,
}
#[post("/register", data="<data>", format="json")]
@@ -96,26 +92,29 @@ async fn new_user(data: Json<RegisterForm>, db: &State<Mutex<DB>>) -> (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;