diff options
author | Tyler Murphy <tylermurphy534@gmail.com> | 2023-01-27 16:04:04 -0500 |
---|---|---|
committer | Tyler Murphy <tylermurphy534@gmail.com> | 2023-01-27 16:04:04 -0500 |
commit | 8536e41c64811630ce8c99eb49d81f89bfb69456 (patch) | |
tree | 4066f9e7dc47fbda4b6aa74871d26ebbe3a43d26 /src/api | |
parent | input length and range checking (diff) | |
download | xssbook-8536e41c64811630ce8c99eb49d81f89bfb69456.tar.gz xssbook-8536e41c64811630ce8c99eb49d81f89bfb69456.tar.bz2 xssbook-8536e41c64811630ce8c99eb49d81f89bfb69456.zip |
rusty boio finished
Diffstat (limited to 'src/api')
-rw-r--r-- | src/api/auth.rs | 2 | ||||
-rw-r--r-- | src/api/pages.rs | 1 | ||||
-rw-r--r-- | src/api/posts.rs | 8 |
3 files changed, 7 insertions, 4 deletions
diff --git a/src/api/auth.rs b/src/api/auth.rs index b469d4d..54c4e06 100644 --- a/src/api/auth.rs +++ b/src/api/auth.rs @@ -26,7 +26,7 @@ impl Check for RegistrationRequet { Self::assert_length(&self.gender, 1, 100, "Gender can only by 1-100 characters long")?; Self::assert_range(self.day as u64, 1, 255, "Birthday day can only be between 1-255")?; Self::assert_range(self.month as u64, 1, 255, "Birthday month can only be between 1-255")?; - Self::assert_range(self.year as u64, 1, 2147483647, "Birthday year can only be between 1-2147483647")?; + Self::assert_range(self.year as u64, 1, 4294967295, "Birthday year can only be between 1-4294967295")?; Ok(()) } } diff --git a/src/api/pages.rs b/src/api/pages.rs index 749a686..4701795 100644 --- a/src/api/pages.rs +++ b/src/api/pages.rs @@ -3,7 +3,6 @@ use axum::{Router, response::{Response, Redirect, IntoResponse}, routing::get}; use crate::types::{extract::AuthorizedUser, response::ResponseCode}; async fn root(user: Option<AuthorizedUser>) -> Response { - println!("{}", user.is_some()); if user.is_some() { return Redirect::to("/home").into_response() } else { diff --git a/src/api/posts.rs b/src/api/posts.rs index 85ff2b2..6830c1a 100644 --- a/src/api/posts.rs +++ b/src/api/posts.rs @@ -18,11 +18,15 @@ impl Check for PostCreateRequest { async fn create(AuthorizedUser(user): AuthorizedUser, Json(body): Json<PostCreateRequest>) -> Response { - let Ok(_post) = Post::new(user.user_id, body.content) else { + let Ok(post) = Post::new(user.user_id, body.content) else { return ResponseCode::InternalServerError.msg("Failed to create post") }; - ResponseCode::Created.msg("Successfully created new post") + let Ok(json) = serde_json::to_string(&post) else { + return ResponseCode::InternalServerError.msg("Failed to create post") + }; + + ResponseCode::Created.json(&json) } #[derive(Deserialize)] |