feat(otter): added sessions page template

main
Jef Roosens 2025-06-15 15:30:02 +02:00
parent 7de4897364
commit 32d70daab2
No known key found for this signature in database
GPG Key ID: 21FD3D77D56BAF49
5 changed files with 55 additions and 7 deletions

View File

@ -22,6 +22,11 @@ const SESSION_ID_COOKIE: &str = "sessionid";
pub fn router(ctx: Context) -> Router<Context> {
Router::new()
.route("/sessions", get(get_sessions))
.route_layer(axum::middleware::from_fn_with_state(
ctx.clone(),
auth_web_middleware,
))
.route("/", get(get_index))
// .layer(middleware::from_fn_with_state(
// ctx.clone(),
@ -161,3 +166,14 @@ pub async fn auth_web_middleware(
Err(err) => err.into_response(),
}
}
pub async fn get_sessions(
State(ctx): State<Context>,
headers: HeaderMap,
) -> TemplateResponse<Page<View>> {
View::Sessions(Vec::new())
.page(&headers)
.headers(&headers)
.authenticated(true)
.response(&ctx.tera)
}

View File

@ -79,6 +79,10 @@ pub fn initialize_tera() -> tera::Result<tera::Tera> {
View::Login.template(),
include_str!("templates/views/login.html"),
),
(
View::Sessions(Vec::new()).template(),
include_str!("templates/views/sessions.html"),
),
])?;
Ok(tera)

View File

@ -21,12 +21,12 @@ a:hover {
</li>
</ul>
<ul>
<li>
{% if authenticated %}
<a hx-post="/logout" hx-target="#inner">Logout</a>
{% else %}
<a hx-get="/login" hx-target="#inner" hx-push-url="true">Login</a>
{% endif %}
{% if authenticated %}
<li><a hx-get="/sessions" hx-target="#inner" hx-push-url="true">Sessions</a></li>
<li><a hx-post="/logout" hx-target="#inner">Logout</a></li>
{% else %}
<li><a hx-get="/login" hx-target="#inner" hx-push-url="true">Login</a></li>
{% endif %}
</li>
</ul>
</nav>

View File

@ -0,0 +1,18 @@
<h1>Sessions</h1>
<table>
<thead>
<tr>
<th>User Agent</th>
<th>Last seen</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<tr>
<th>Firefox</th>
<th>yesterday</th>
<th>Remove</th>
</tr>
</tbody>
</table>

View File

@ -3,6 +3,7 @@ use super::Template;
pub enum View {
Index,
Login,
Sessions(Vec<gpodder::Session>),
}
impl Template for View {
@ -10,10 +11,19 @@ impl Template for View {
match self {
Self::Index => "views/index.html",
Self::Login => "views/login.html",
Self::Sessions(_) => "views/sessions.html",
}
}
fn render(&self, tera: &tera::Tera) -> tera::Result<String> {
tera.render(self.template(), &tera::Context::new())
let mut ctx = tera::Context::new();
// match self {
// Self::Sessions(sessions) => {
// ctx.insert("sessions", sessions);
// }
// };
tera.render(self.template(), &ctx)
}
}