diff --git a/src/pages/panel/mod.rs b/src/pages/panel/mod.rs
index 45cb2f8a..dea76452 100644
--- a/src/pages/panel/mod.rs
+++ b/src/pages/panel/mod.rs
@@ -15,32 +15,36 @@
* along with this program. If not, see .
*/
-use actix_web::{HttpResponse, Responder};
-use lazy_static::lazy_static;
+use actix_identity::Identity;
+use actix_web::{web, HttpResponse, Responder};
use sailfish::TemplateOnce;
pub mod sitekey;
+use crate::errors::PageResult;
+use crate::Data;
+use sitekey::list::{get_list_sitekeys, SiteKeys};
+
#[derive(TemplateOnce, Clone)]
#[template(path = "panel/index.html")]
-pub struct IndexPage;
+pub struct IndexPage {
+ sitekeys: SiteKeys,
+}
-const PAGE: &str = "Dashboard";
-
-impl Default for IndexPage {
- fn default() -> Self {
- IndexPage
+impl IndexPage {
+ fn new(sitekeys: SiteKeys) -> Self {
+ IndexPage { sitekeys }
}
}
-lazy_static! {
- static ref INDEX: String = IndexPage::default().render_once().unwrap();
-}
+const PAGE: &str = "Dashboard";
-async fn panel() -> impl Responder {
- HttpResponse::Ok()
+async fn panel(data: web::Data, id: Identity) -> PageResult {
+ let sitekeys = get_list_sitekeys(&data, &id).await?;
+ let body = IndexPage::new(sitekeys).render_once().unwrap();
+ Ok(HttpResponse::Ok()
.content_type("text/html; charset=utf-8")
- .body(&*INDEX)
+ .body(body))
}
pub fn services(cfg: &mut actix_web::web::ServiceConfig) {
diff --git a/src/pages/panel/sitekey/list.rs b/src/pages/panel/sitekey/list.rs
index 54363407..1072927b 100644
--- a/src/pages/panel/sitekey/list.rs
+++ b/src/pages/panel/sitekey/list.rs
@@ -37,7 +37,17 @@ impl IndexPage {
}
}
+/// render a list of all sitekeys that a user has
pub async fn list_sitekeys(data: web::Data, id: Identity) -> PageResult {
+ let res = get_list_sitekeys(&data, &id).await?;
+ let body = IndexPage::new(res).render_once().unwrap();
+ Ok(HttpResponse::Ok()
+ .content_type("text/html; charset=utf-8")
+ .body(body))
+}
+
+/// utility function to get a list of all sitekeys that a user owns
+pub async fn get_list_sitekeys(data: &Data, id: &Identity) -> PageResult {
let username = id.identity().unwrap();
let res = sqlx::query_as!(
MCaptchaDetails,
@@ -47,14 +57,10 @@ pub async fn list_sitekeys(data: web::Data, id: Identity) -> PageResult;
+pub type SiteKeys = Vec;
#[cfg(test)]
mod test {
diff --git a/src/pages/panel/sitekey/mod.rs b/src/pages/panel/sitekey/mod.rs
index 6945defb..22840c34 100644
--- a/src/pages/panel/sitekey/mod.rs
+++ b/src/pages/panel/sitekey/mod.rs
@@ -16,7 +16,7 @@
*/
mod add;
-mod list;
+pub mod list;
mod view;
pub mod routes {
diff --git a/templates/panel/index.html b/templates/panel/index.html
index 267b23ef..ef449257 100644
--- a/templates/panel/index.html
+++ b/templates/panel/index.html
@@ -6,5 +6,24 @@
<. include!("./help-banner/index.html"); .>
<. include!("../components/footers.html"); .>