lazy element, settings: account delete and secret update

This commit is contained in:
realaravinth
2021-07-21 20:44:22 +05:30
parent 2c2f79e1cd
commit 861998af75
15 changed files with 308 additions and 36 deletions

View File

@@ -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)
}