redirect to /login and redirect back, instead of showing small msg

This commit is contained in:
2026-04-09 15:20:02 +02:00
parent 3c111212f0
commit b93cdfba63
10 changed files with 217 additions and 211 deletions

View File

@@ -9,12 +9,14 @@ use crate::{
error::CompositeError,
logs::LogEntry,
users::{User, auth::UserAuthenticate, permissions::Permission},
web::{RedirectViaError, components::nav::nav, icons, pages::base},
web::{components::nav::nav, icons, pages::base},
};
pub async fn page(req: Request) -> Result<Response, CompositeError> {
let u = User::authenticate(req.headers())?
.ok_or(RedirectViaError(Redirect::to("/login?re=/logs")))?;
let u = match User::authenticate(req.headers())? {
Some(u) => u,
None => return Ok(Redirect::to(&format!("/login?r={}", req.uri().path())).into_response()),
};
let mut conn = database::conn()?;
let tx = conn.transaction()?;
let logs = LogEntry::get_all(&tx)?;
@@ -63,7 +65,7 @@ pub async fn page(req: Request) -> Result<Response, CompositeError> {
}
}
} @else {
p class="text-center p-2" {"You must have permission to view this page."}
p class="text-center p-2" {"You must have permission to view logs."}
}
),
)