Skip to content

Commit

Permalink
adjust status codes
Browse files Browse the repository at this point in the history
  • Loading branch information
huangcheng committed Dec 1, 2023
1 parent de7f498 commit 8aa8e13
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
8 changes: 5 additions & 3 deletions src/handlers/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ pub async fn login(
.map_err(|e| {
error!("Failed to query user: {}", e);

ServiceError::InternalServerError
ServiceError::BadRequest(String::from("Invalid username or password"))
})?;

let valid = verify(user.password, &record.password).map_err(|e| {
error!("Failed to verify password: {}", e);

ServiceError::Unauthorized
ServiceError::BadRequest(String::from("Invalid username or password"))
})?;

if valid {
Expand All @@ -55,6 +55,8 @@ pub async fn login(

Ok(token)
} else {
Err(ServiceError::Unauthorized)
Err(ServiceError::BadRequest(String::from(
"Invalid username or password",
)))
}
}
21 changes: 17 additions & 4 deletions src/handlers/site.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use rocket::form::validate::Len;
use rocket_db_pools::Connection;
use sqlx::{query, query_as, Row};

Expand Down Expand Up @@ -129,22 +130,34 @@ pub async fn update_site(
})?;

let name = match site.name {
Some(name) => String::from(name),
Some(name) => match name.len() {
0 => record.name,
_ => String::from(name),
},
None => record.name,
};

let url = match site.url {
Some(url) => String::from(url),
Some(url) => match url.len() {
0 => record.url,
_ => String::from(url),
},
None => record.url,
};

let description = match site.description {
Some(description) => String::from(description),
Some(description) => match description.len() {
0 => record.description,
_ => String::from(description),
},
None => record.description,
};

let icon = match site.icon {
Some(icon) => String::from(icon),
Some(icon) => match icon.len() {
0 => record.icon,
_ => String::from(icon),
},
None => record.icon,
};

Expand Down

0 comments on commit 8aa8e13

Please sign in to comment.