update GET /adminpanel error messages

This commit is contained in:
SadlyNotSappho 2024-03-19 13:19:24 -07:00
parent 68e18b89a1
commit c5934c6fb8
1 changed files with 7 additions and 7 deletions

View File

@ -158,25 +158,25 @@ async fn logout(cookies: &CookieJar<'_>) -> status::Custom<&'static str> {
} }
#[get("/adminpanel")] #[get("/adminpanel")]
async fn adminpanel(mut db: Connection<Db>, cookies: &CookieJar<'_>) -> RawHtml<String> { async fn adminpanel(mut db: Connection<Db>, cookies: &CookieJar<'_>) -> status::Custom<RawHtml<String>> {
let token = cookies.get_private("token"); let token = cookies.get_private("token");
match token { match token {
Some(t) => match User::get_by_token(&mut db, t).await { Some(t) => match User::get_by_token(&mut db, t).await {
Some(user) => match user.admin { Some(user) => match user.admin {
true => RawHtml( true => status::Custom(Status::Ok, RawHtml(
fs::read_to_string("/srv/web/adminpanel.html") fs::read_to_string("/srv/web/adminpanel.html")
.unwrap() .unwrap()
.replace("{{username}}", &user.username[..]), .replace("{{username}}", &user.username[..])),
), ),
false => RawHtml(fs::read_to_string("/srv/web/invalidperms.html").unwrap()), false => status::Custom(Status::Unauthorized, RawHtml(fs::read_to_string("/srv/web/invalidperms.html").unwrap())),
}, },
None => RawHtml( None => status::Custom(Status::Unauthorized, RawHtml(
fs::read_to_string("/srv/web/error.html") fs::read_to_string("/srv/web/error.html")
.unwrap() .unwrap()
.replace("{{errorcode}}", "498"), .replace("{{errorcode}}", "401")),
), ),
}, },
None => RawHtml(fs::read_to_string("/srv/web/invalidperms.html").unwrap()), None => status::Custom(Status::Unauthorized, RawHtml(fs::read_to_string("/srv/web/invalidperms.html").unwrap())),
} }
} }