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> {
|
pub fn router(ctx: Context) -> Router<Context> {
|
||||||
Router::new()
|
Router::new()
|
||||||
|
.route("/sessions", get(get_sessions))
|
||||||
|
.route_layer(axum::middleware::from_fn_with_state(
|
||||||
|
ctx.clone(),
|
||||||
|
auth_web_middleware,
|
||||||
|
))
|
||||||
.route("/", get(get_index))
|
.route("/", get(get_index))
|
||||||
// .layer(middleware::from_fn_with_state(
|
// .layer(middleware::from_fn_with_state(
|
||||||
// ctx.clone(),
|
// ctx.clone(),
|
||||||
|
@ -161,3 +166,14 @@ pub async fn auth_web_middleware(
|
||||||
Err(err) => err.into_response(),
|
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(),
|
View::Login.template(),
|
||||||
include_str!("templates/views/login.html"),
|
include_str!("templates/views/login.html"),
|
||||||
),
|
),
|
||||||
|
(
|
||||||
|
View::Sessions(Vec::new()).template(),
|
||||||
|
include_str!("templates/views/sessions.html"),
|
||||||
|
),
|
||||||
])?;
|
])?;
|
||||||
|
|
||||||
Ok(tera)
|
Ok(tera)
|
||||||
|
|
|
@ -21,12 +21,12 @@ a:hover {
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
<ul>
|
<ul>
|
||||||
<li>
|
{% if authenticated %}
|
||||||
{% if authenticated %}
|
<li><a hx-get="/sessions" hx-target="#inner" hx-push-url="true">Sessions</a></li>
|
||||||
<a hx-post="/logout" hx-target="#inner">Logout</a>
|
<li><a hx-post="/logout" hx-target="#inner">Logout</a></li>
|
||||||
{% else %}
|
{% 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 %}
|
{% endif %}
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</nav>
|
</nav>
|
||||||
|
|
|
@ -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 {
|
pub enum View {
|
||||||
Index,
|
Index,
|
||||||
Login,
|
Login,
|
||||||
|
Sessions(Vec<gpodder::Session>),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Template for View {
|
impl Template for View {
|
||||||
|
@ -10,10 +11,19 @@ impl Template for View {
|
||||||
match self {
|
match self {
|
||||||
Self::Index => "views/index.html",
|
Self::Index => "views/index.html",
|
||||||
Self::Login => "views/login.html",
|
Self::Login => "views/login.html",
|
||||||
|
Self::Sessions(_) => "views/sessions.html",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn render(&self, tera: &tera::Tera) -> tera::Result<String> {
|
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