feat(otter): added sessions page template
parent
7de4897364
commit
32d70daab2
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -21,11 +21,11 @@ a:hover {
|
|||
</li>
|
||||
</ul>
|
||||
<ul>
|
||||
<li>
|
||||
{% if authenticated %}
|
||||
<a hx-post="/logout" hx-target="#inner">Logout</a>
|
||||
<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 %}
|
||||
<a hx-get="/login" hx-target="#inner" hx-push-url="true">Login</a>
|
||||
<li><a hx-get="/login" hx-target="#inner" hx-push-url="true">Login</a></li>
|
||||
{% endif %}
|
||||
</li>
|
||||
</ul>
|
||||
|
|
|
@ -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>
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue