mirror of
https://github.com/mCaptcha/mCaptcha.git
synced 2026-02-11 10:05:41 +00:00
lazy element, settings: account delete and secret update
This commit is contained in:
@@ -63,7 +63,9 @@ mod tests {
|
||||
PAGES.panel.sitekey.add,
|
||||
PAGES.panel.sitekey.list,
|
||||
PAGES.panel.notifications,
|
||||
PAGES.panel.settings,
|
||||
PAGES.panel.settings.home,
|
||||
PAGES.panel.settings.delete_account,
|
||||
PAGES.panel.settings.update_secret,
|
||||
&delete_sitekey_url,
|
||||
&edit_sitekey_url,
|
||||
];
|
||||
|
||||
@@ -52,18 +52,20 @@ async fn panel(data: AppData, id: Identity) -> PageResult<impl Responder> {
|
||||
|
||||
pub fn services(cfg: &mut actix_web::web::ServiceConfig) {
|
||||
cfg.service(panel);
|
||||
cfg.service(settings::settings);
|
||||
settings::services(cfg);
|
||||
sitekey::services(cfg);
|
||||
cfg.service(notifications::notifications);
|
||||
}
|
||||
|
||||
pub mod routes {
|
||||
use super::settings::routes::Settings;
|
||||
use super::sitekey::routes::Sitekey;
|
||||
|
||||
pub struct Panel {
|
||||
pub home: &'static str,
|
||||
pub sitekey: Sitekey,
|
||||
pub notifications: &'static str,
|
||||
pub settings: &'static str,
|
||||
pub settings: Settings,
|
||||
}
|
||||
|
||||
impl Panel {
|
||||
@@ -72,7 +74,7 @@ pub mod routes {
|
||||
home: "/",
|
||||
sitekey: Sitekey::new(),
|
||||
notifications: "/notifications",
|
||||
settings: "/settings",
|
||||
settings: Settings::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,8 +19,35 @@ use actix_web::{HttpResponse, Responder};
|
||||
use sailfish::TemplateOnce;
|
||||
|
||||
use crate::errors::PageResult;
|
||||
use crate::pages::auth::sudo::SudoPage;
|
||||
use crate::AppData;
|
||||
|
||||
pub mod routes {
|
||||
pub struct Settings {
|
||||
pub home: &'static str,
|
||||
pub delete_account: &'static str,
|
||||
pub update_secret: &'static str,
|
||||
}
|
||||
|
||||
impl Settings {
|
||||
pub const fn new() -> Self {
|
||||
Settings {
|
||||
home: "/settings",
|
||||
delete_account: "/settings/account/delete",
|
||||
update_secret: "/settings/secret/update",
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn services(cfg: &mut actix_web::web::ServiceConfig) {
|
||||
cfg.service(settings);
|
||||
cfg.service(update_secret);
|
||||
cfg.service(delete_account);
|
||||
}
|
||||
|
||||
const PAGE: &str = "Settings";
|
||||
|
||||
#[derive(TemplateOnce, Clone)]
|
||||
#[template(path = "panel/settings/index.html")]
|
||||
pub struct IndexPage {
|
||||
@@ -28,10 +55,8 @@ pub struct IndexPage {
|
||||
secret: String,
|
||||
}
|
||||
|
||||
const PAGE: &str = "Settings";
|
||||
|
||||
#[my_codegen::get(path = "crate::PAGES.panel.settings", wrap = "crate::CheckLogin")]
|
||||
pub async fn settings(data: AppData, id: Identity) -> PageResult<impl Responder> {
|
||||
#[my_codegen::get(path = "crate::PAGES.panel.settings.home", wrap = "crate::CheckLogin")]
|
||||
async fn settings(data: AppData, id: Identity) -> PageResult<impl Responder> {
|
||||
let username = id.identity().unwrap();
|
||||
|
||||
let details = sqlx::query_as!(
|
||||
@@ -47,3 +72,29 @@ pub async fn settings(data: AppData, id: Identity) -> PageResult<impl Responder>
|
||||
.content_type("text/html; charset=utf-8")
|
||||
.body(body))
|
||||
}
|
||||
|
||||
#[my_codegen::get(
|
||||
path = "crate::PAGES.panel.settings.delete_account",
|
||||
wrap = "crate::CheckLogin"
|
||||
)]
|
||||
async fn delete_account() -> impl Responder {
|
||||
let page = SudoPage::<u8, u8>::new(crate::V1_API_ROUTES.account.delete, None)
|
||||
.render_once()
|
||||
.unwrap();
|
||||
HttpResponse::Ok()
|
||||
.content_type("text/html; charset=utf-8")
|
||||
.body(&page)
|
||||
}
|
||||
|
||||
#[my_codegen::get(
|
||||
path = "crate::PAGES.panel.settings.update_secret",
|
||||
wrap = "crate::CheckLogin"
|
||||
)]
|
||||
async fn update_secret() -> impl Responder {
|
||||
let page = SudoPage::<u8, u8>::new(crate::V1_API_ROUTES.account.update_secret, None)
|
||||
.render_once()
|
||||
.unwrap();
|
||||
HttpResponse::Ok()
|
||||
.content_type("text/html; charset=utf-8")
|
||||
.body(&page)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user