update GET /account error messages

This commit is contained in:
SadlyNotSappho 2024-03-19 13:15:15 -07:00
parent 6e69be35b8
commit 2c128a1e1f
1 changed files with 9 additions and 6 deletions

View File

@ -96,17 +96,20 @@ async fn createuser(
}
#[get("/account")]
async fn account(mut db: Connection<Db>, cookies: &CookieJar<'_>) -> String {
async fn account(mut db: Connection<Db>, cookies: &CookieJar<'_>) -> status::Custom<String> {
let token = cookies.get_private("token");
match token {
Some(t) => match User::get_by_token(&mut db, t).await {
Some(user) => format!(
"Username: {}\nAdmin: {}\nMake Posts: {}\nComment: {}",
user.username, user.admin, user.make_posts, user.comment
Some(user) => status::Custom(
Status::Ok,
format!(
"Username: {}\nAdmin: {}\nMake Posts: {}\nComment: {}",
user.username, user.admin, user.make_posts, user.comment
),
),
None => "User doesn't exist.".to_string(),
None => status::Custom(Status::NotFound, "User doesn't exist.".to_string()),
},
None => "Not logged in".to_string(),
None => status::Custom(Status::Unauthorized, "Not logged in".to_string()),
}
}