Skip to content

Commit

Permalink
feat: delete account
Browse files Browse the repository at this point in the history
  • Loading branch information
tiensonqin committed Feb 15, 2021
1 parent c13cf6a commit 7c586ec
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 15 deletions.
33 changes: 32 additions & 1 deletion src/main/frontend/components/settings.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,25 @@
(util/stop e))}
svg/external-link " release channel"]])])]))

(rum/defc delete-account-confirm
[close-fn]
(rum/with-context [[t] i18n/*tongue-context*]
[:div
(ui/admonition
:important
[:p.text-gray-700 (t :user/delete-account-notice)])
[:div.mt-5.sm:mt-4.sm:flex.sm:flex-row-reverse
[:span.flex.w-full.rounded-md.shadow-sm.sm:ml-3.sm:w-auto
[:button.inline-flex.justify-center.w-full.rounded-md.border.border-transparent.px-4.py-2.bg-indigo-600.text-base.leading-6.font-medium.text-white.shadow-sm.hover:bg-indigo-500.focus:outline-none.focus:border-indigo-700.focus:shadow-outline-indigo.transition.ease-in-out.duration-150.sm:text-sm.sm:leading-5
{:type "button"
:on-click user-handler/delete-account!}
(t :user/delete-account)]]
[:span.mt-3.flex.w-full.rounded-md.shadow-sm.sm:mt-0.sm:w-auto
[:button.inline-flex.justify-center.w-full.rounded-md.border.border-gray-300.px-4.py-2.bg-white.text-base.leading-6.font-medium.text-gray-700.shadow-sm.hover:text-gray-500.focus:outline-none.focus:border-blue-300.focus:shadow-outline-blue.transition.ease-in-out.duration-150.sm:text-sm.sm:leading-5
{:type "button"
:on-click close-fn}
"Cancel"]]]]))

(rum/defcs settings < rum/reactive
[]
(let [preferred-format (state/get-preferred-format)
Expand Down Expand Up @@ -329,4 +348,16 @@
:on-click #(state/set-developer-mode! (not developer-mode?)))]]]

[:br]
(t :settings-page/developer-mode-desc)]]])))
(t :settings-page/developer-mode-desc)

[:hr]

(when logged?
[:div.sm:grid.sm:grid-cols-3.sm:gap-4.sm:items-start.sm:pt-5
[:label.block.text-sm.font-medium.leading-5.sm:mt-px.sm:pt-2.opacity-70.text-red-600
{:for "delete account"}
(t :user/delete-account)]
[:div.mt-1.sm:mt-0.sm:col-span-2
[:div.max-w-lg.rounded-md.shadow-sm.sm:max-w-xs
(ui/button (t :user/delete-your-account)
:on-click #(state/set-modal! delete-account-confirm))]]])]]])))
14 changes: 10 additions & 4 deletions src/main/frontend/dicts.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -341,8 +341,11 @@ title: How to take dummy notes?
:dark "Dark"
:remove-background "Remove background"
:open "Open"
:open-a-directory "Open a local directory"}

:open-a-directory "Open a local directory"
:user/delete-account "Delete account"
:user/delete-your-account "Delete your account"
:user/delete-account-notice "All your published pages on logseq.com will be deleted."}

:de {:help/about "Über Logseq"
:help/bug "Fehlerbericht"
:help/feature "Feature-Anfrage"
Expand Down Expand Up @@ -571,7 +574,7 @@ title: How to take dummy notes?
:remove-background "Hintergrund entfernen"
:open "Öffnen"
:open-a-directory "Öffne ein lokales Verzeichnis"}

:fr {:help/about "A propos de Logseq"
:help/bug "Signaler une anomalie"
:help/feature "Demander une fonctionnalité"
Expand Down Expand Up @@ -1055,7 +1058,10 @@ title: How to take dummy notes?
:dark "暗黑"
:remove-background "去除背景"
:open "打开"
:open-a-directory "打开本地文件夹"}
:open-a-directory "打开本地文件夹"
:user/delete-account "删除帐号"
:user/delete-your-account "删除你的帐号"
:user/delete-account-notice "你在 logseq.com 发布的页面(假如有的话)也会被删除。"}

:zh-Hant {:on-boarding/title "你好,歡迎使用 Logseq!"
:on-boarding/sharing "分享"
Expand Down
33 changes: 23 additions & 10 deletions src/main/frontend/handler/user.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
[promesa.core :as p]
[goog.object :as gobj]
[frontend.handler.notification :as notification]
[frontend.handler.config :as config-handler])
[frontend.handler.config :as config-handler]
[lambdaisland.glogi :as log])
(:import [goog.format EmailAddress]))

(defn email? [v]
Expand Down Expand Up @@ -63,12 +64,24 @@
(fn [_e])))))

(defn sign-out!
[_e]
(when (js/confirm "Your local notes will be completely removed after signing out. Continue?")
(->
(idb/clear-local-storage-and-idb!)
(p/catch (fn [e]
(println "sign out error: ")
(js/console.dir e)))
(p/finally (fn []
(set! (.-href js/window.location) "/logout"))))))
([]
(sign-out! true))
([confirm?]
(when (or (not confirm?)
(js/confirm "Your local notes will be completely removed after signing out. Continue?"))
(->
(idb/clear-local-storage-and-idb!)
(p/catch (fn [e]
(println "sign out error: ")
(js/console.dir e)))
(p/finally (fn []
(set! (.-href js/window.location) "/logout")))))))

(defn delete-account!
[]
(p/let [_ (idb/clear-local-storage-and-idb!)]
(util/delete (str config/api "account")
(fn []
(sign-out! false))
(fn [error]
(log/error :user/delete-account-failed error)))))

0 comments on commit 7c586ec

Please sign in to comment.