Skip to content

Commit

Permalink
feat: reject submits that are not object
Browse files Browse the repository at this point in the history
  • Loading branch information
zrll12 committed Jan 27, 2025
1 parent 86f7d02 commit 3ff5122
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
16 changes: 8 additions & 8 deletions src/controller/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ use axum::response::{IntoResponse, Response};

#[derive(Debug)]
pub enum ErrorMessage {
// InvalidParams(String),
InvalidParams(String),
InvalidToken,
TokenNotActivated,
// TokenNotActivated,
PermissionDenied,
TooManySubmit,
NotFound,
Expand All @@ -20,17 +20,17 @@ impl IntoResponse for ErrorMessage {
let builder = Response::builder();

match self {
// ErrorMessage::InvalidParams(name) => {
// builder.status(StatusCode::BAD_REQUEST).body(format!("Invalid params: {}.", name).into()).unwrap()
// }
ErrorMessage::InvalidParams(name) => {
builder.status(StatusCode::BAD_REQUEST).body(format!("Invalid params: {}.", name).into()).unwrap()
}

ErrorMessage::InvalidToken => {
builder.status(StatusCode::UNAUTHORIZED).body("Invalid token.".into()).unwrap()
}

ErrorMessage::TokenNotActivated => {
builder.status(StatusCode::UNAUTHORIZED).body("Token not activated.".into()).unwrap()
}
// ErrorMessage::TokenNotActivated => {
// builder.status(StatusCode::UNAUTHORIZED).body("Token not activated.".into()).unwrap()
// }

ErrorMessage::PermissionDenied => {
builder.status(StatusCode::FORBIDDEN).body("Permission denied.".into()).unwrap()
Expand Down
4 changes: 4 additions & 0 deletions src/controller/score/submit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ pub async fn submit(TokenInfo(user): TokenInfo, Json(request): Json<SubmitBody>)
struct SurveyAllowReSubmit {
allow_re_submit: bool,
}

if !request.content.is_object() {
return Err(ErrorMessage::InvalidParams("content".to_string()));
}

let score = match request.id {
None => {
Expand Down
2 changes: 1 addition & 1 deletion src/controller/survey/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub async fn query_surveys(Query(query): Query<QueryParams>, TokenInfo(user): To
debug!("User {} (admin: {admin}) is trying to get surveys", user.uid);

let size = query.size.unwrap_or(10);
let page = query.page.unwrap_or(1);
let page = query.page.unwrap_or(0);

let current_time = chrono::Local::now().naive_local();

Expand Down

0 comments on commit 3ff5122

Please sign in to comment.