update GET /account error messages
This commit is contained in:
parent
6e69be35b8
commit
2c128a1e1f
15
src/main.rs
15
src/main.rs
|
@ -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()),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue