From 872b39aadd2bb38f2185222cbc3b2f4e91958b50 Mon Sep 17 00:00:00 2001 From: "Billy.Zheng" Date: Wed, 29 May 2024 11:52:57 +0800 Subject: [PATCH] Add clear chong/wen/bao --- src/actions/me/clear_bao.cr | 6 +++++ src/actions/me/clear_chong.cr | 11 ++++++++ src/actions/me/clear_wen.cr | 6 +++++ src/pages/me/show_page.cr | 48 +++++++++++++++++++++++++---------- 4 files changed, 58 insertions(+), 13 deletions(-) create mode 100644 src/actions/me/clear_bao.cr create mode 100644 src/actions/me/clear_chong.cr create mode 100644 src/actions/me/clear_wen.cr diff --git a/src/actions/me/clear_bao.cr b/src/actions/me/clear_bao.cr new file mode 100644 index 0000000..ca07c7a --- /dev/null +++ b/src/actions/me/clear_bao.cr @@ -0,0 +1,6 @@ +class Me::ClearBao < BrowserAction + put "/me/clear_bao" do + chong_wen_baos = ChongWenBaoQuery.new.user_id(current_user.id) + plain_text "ok" + end +end diff --git a/src/actions/me/clear_chong.cr b/src/actions/me/clear_chong.cr new file mode 100644 index 0000000..f3a8fd1 --- /dev/null +++ b/src/actions/me/clear_chong.cr @@ -0,0 +1,11 @@ +class Me::ClearChong < BrowserAction + put "/me/clear_chong" do + ChongWenBaoQuery.new.user_id(current_user.id).update( + chong_2023: false, + chong_2022: false, + chong_2021: false, + chong_2020: false + ) + plain_text "ok" + end +end diff --git a/src/actions/me/clear_wen.cr b/src/actions/me/clear_wen.cr new file mode 100644 index 0000000..25e4150 --- /dev/null +++ b/src/actions/me/clear_wen.cr @@ -0,0 +1,6 @@ +class Me::ClearWen < BrowserAction + put "/me/clear_wen" do + chong_wen_baos = ChongWenBaoQuery.new.user_id(current_user.id) + plain_text "ok" + end +end diff --git a/src/pages/me/show_page.cr b/src/pages/me/show_page.cr index cd3cf1a..f33c522 100644 --- a/src/pages/me/show_page.cr +++ b/src/pages/me/show_page.cr @@ -2,20 +2,42 @@ class Me::ShowPage < MainLayout def content h2 "个人信息" h3 "邮箱名: #{@current_user.email}" - # helpful_tips - end + link( + "清除用户冲数据", + Me::ClearChong, + class: "btn", + "hx-put": Me::ClearChong.path, + "hx-swap": "none", + "hx-include": "[name='_csrf']", + "hx-confirm": "确认要清除标记的冲数据吗?", + ) - private def helpful_tips - h3 "Next, you may want to:" - ul do - li { link_to_authentication_guides } - li "Modify this page: src/pages/me/show_page.cr" - li "Change where you go after sign in: src/actions/home/index.cr" - end - end + br + br + + link( + "清除用户稳数据", + Me::ClearWen, + class: "btn", + "hx-put": Me::ClearWen.path, + "hx-swap": "none", + "hx-include": "[name='_csrf']", + "hx-confirm": "确认要清除标记的稳数据吗?", + ) + + br + br + + link( + "清除用户保数据", + Me::ClearChong, + class: "btn", + "hx-put": Me::ClearBao.path, + "hx-swap": "none", + "hx-include": "[name='_csrf']", + "hx-confirm": "确认要清除标记的保数据吗?", + ) - private def link_to_authentication_guides - a "Check out the authentication guides", - href: "https://luckyframework.org/guides/authentication" + input(type: "hidden", value: context.session.get("X-CSRF-TOKEN"), name: "_csrf") end end