mirror of
https://github.com/mCaptcha/mCaptcha.git
synced 2025-03-29 04:38:59 +03:00
panel: overview
This commit is contained in:
parent
527724ecda
commit
95bc1feef7
4 changed files with 50 additions and 21 deletions
|
@ -15,32 +15,36 @@
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
use actix_web::{HttpResponse, Responder};
|
use actix_identity::Identity;
|
||||||
use lazy_static::lazy_static;
|
use actix_web::{web, HttpResponse, Responder};
|
||||||
use sailfish::TemplateOnce;
|
use sailfish::TemplateOnce;
|
||||||
|
|
||||||
pub mod sitekey;
|
pub mod sitekey;
|
||||||
|
|
||||||
|
use crate::errors::PageResult;
|
||||||
|
use crate::Data;
|
||||||
|
use sitekey::list::{get_list_sitekeys, SiteKeys};
|
||||||
|
|
||||||
#[derive(TemplateOnce, Clone)]
|
#[derive(TemplateOnce, Clone)]
|
||||||
#[template(path = "panel/index.html")]
|
#[template(path = "panel/index.html")]
|
||||||
pub struct IndexPage;
|
pub struct IndexPage {
|
||||||
|
sitekeys: SiteKeys,
|
||||||
|
}
|
||||||
|
|
||||||
const PAGE: &str = "Dashboard";
|
impl IndexPage {
|
||||||
|
fn new(sitekeys: SiteKeys) -> Self {
|
||||||
impl Default for IndexPage {
|
IndexPage { sitekeys }
|
||||||
fn default() -> Self {
|
|
||||||
IndexPage
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
lazy_static! {
|
const PAGE: &str = "Dashboard";
|
||||||
static ref INDEX: String = IndexPage::default().render_once().unwrap();
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn panel() -> impl Responder {
|
async fn panel(data: web::Data<Data>, id: Identity) -> PageResult<impl Responder> {
|
||||||
HttpResponse::Ok()
|
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")
|
.content_type("text/html; charset=utf-8")
|
||||||
.body(&*INDEX)
|
.body(body))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn services(cfg: &mut actix_web::web::ServiceConfig) {
|
pub fn services(cfg: &mut actix_web::web::ServiceConfig) {
|
||||||
|
|
|
@ -37,7 +37,17 @@ impl IndexPage {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// render a list of all sitekeys that a user has
|
||||||
pub async fn list_sitekeys(data: web::Data<Data>, id: Identity) -> PageResult<impl Responder> {
|
pub async fn list_sitekeys(data: web::Data<Data>, id: Identity) -> PageResult<impl Responder> {
|
||||||
|
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<SiteKeys> {
|
||||||
let username = id.identity().unwrap();
|
let username = id.identity().unwrap();
|
||||||
let res = sqlx::query_as!(
|
let res = sqlx::query_as!(
|
||||||
MCaptchaDetails,
|
MCaptchaDetails,
|
||||||
|
@ -47,14 +57,10 @@ pub async fn list_sitekeys(data: web::Data<Data>, id: Identity) -> PageResult<im
|
||||||
)
|
)
|
||||||
.fetch_all(&data.db)
|
.fetch_all(&data.db)
|
||||||
.await?;
|
.await?;
|
||||||
|
Ok(res)
|
||||||
let body = IndexPage::new(res).render_once().unwrap();
|
|
||||||
Ok(HttpResponse::Ok()
|
|
||||||
.content_type("text/html; charset=utf-8")
|
|
||||||
.body(body))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type SiteKeys = Vec<MCaptchaDetails>;
|
pub type SiteKeys = Vec<MCaptchaDetails>;
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
mod add;
|
mod add;
|
||||||
mod list;
|
pub mod list;
|
||||||
mod view;
|
mod view;
|
||||||
|
|
||||||
pub mod routes {
|
pub mod routes {
|
||||||
|
|
|
@ -6,5 +6,24 @@
|
||||||
<. include!("./help-banner/index.html"); .>
|
<. include!("./help-banner/index.html"); .>
|
||||||
<div class="inner-container">
|
<div class="inner-container">
|
||||||
|
|
||||||
|
<ul class="sitekey-list__box">
|
||||||
|
<h1 class="sitekey-list__title">Your Sitekeys</h1>
|
||||||
|
<. for sitekey in sitekeys.iter() { .>
|
||||||
|
<a href="/sitekey/<.= sitekey.key .>/view" class="sitekey-list__item-container">
|
||||||
|
<li class="sitekey-list__item">
|
||||||
|
|
||||||
|
<span class="sitekey-list__name">
|
||||||
|
<.= sitekey.name .>
|
||||||
|
</span>
|
||||||
|
<span class="sitekey-list__key">
|
||||||
|
<.= sitekey.key .>
|
||||||
|
</span>
|
||||||
|
</li>
|
||||||
|
</a>
|
||||||
|
|
||||||
|
<. } .>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
<. include!("../components/footers.html"); .>
|
<. include!("../components/footers.html"); .>
|
||||||
|
|
Loading…
Add table
Reference in a new issue