From 739ee81002f4e4411e7038636189a5f0ecd26e2a Mon Sep 17 00:00:00 2001 From: MathMan05 Date: Thu, 13 Mar 2025 19:56:55 -0500 Subject: [PATCH] add account deletion --- src/webpage/localuser.ts | 31 +++++++++++++++++++++++++++++++ src/webpage/settings.ts | 2 +- src/webpage/utils/utils.ts | 5 +++++ translations/en.json | 7 ++++++- translations/qqq.json | 9 +++------ 5 files changed, 46 insertions(+), 8 deletions(-) diff --git a/src/webpage/localuser.ts b/src/webpage/localuser.ts index 7541657..3ed3528 100644 --- a/src/webpage/localuser.ts +++ b/src/webpage/localuser.ts @@ -1699,6 +1699,37 @@ class Localuser { devPortal.addHTMLArea(appListContainer); }); } + { + const deleteAccount = settings.addButton(I18n.localuser.deleteAccount()).addForm( + "", + () => { + this.userinfo.remove(); + window.location.href = "/"; + }, + { + headers: this.headers, + method: "POST", + fetchURL: this.info.api + "/users/@me/delete/", + traditionalSubmit: false, + submitText: I18n.localuser.deleteAccountButton(), + }, + ); + const shrek = deleteAccount.addTextInput( + I18n.localuser.areYouSureDelete(I18n.localuser.sillyDeleteConfirmPhrase()), + "shrek", + ); + deleteAccount.addTextInput(I18n.localuser["password:"](), "password"); + deleteAccount.addPreprocessor((obj) => { + if ("shrek" in obj) { + if (obj.shrek !== I18n.localuser.sillyDeleteConfirmPhrase()) { + throw new FormError(shrek, I18n.localuser.mustTypePhrase()); + } + delete obj.shrek; + } else { + throw new FormError(shrek, I18n.localuser.mustTypePhrase()); + } + }); + } settings.show(); } readonly botTokens: Map = new Map(); diff --git a/src/webpage/settings.ts b/src/webpage/settings.ts index ca5d790..695e4dd 100644 --- a/src/webpage/settings.ts +++ b/src/webpage/settings.ts @@ -790,7 +790,7 @@ class Options implements OptionsElement { onSubmit: (arg1: object, sent: object) => void, { ltr = false, - submitText = "Submit", + submitText = I18n.getTranslation("submit"), fetchURL = "", headers = {}, method = "POST", diff --git a/src/webpage/utils/utils.ts b/src/webpage/utils/utils.ts index 942da21..144f0fa 100644 --- a/src/webpage/utils/utils.ts +++ b/src/webpage/utils/utils.ts @@ -89,6 +89,11 @@ export class Specialuser { console.error("There are fundamentally missing pieces of info missing from this user"); } } + remove() { + const info = getBulkInfo(); + delete info.users[this.uid]; + localStorage.setItem("userinfos", JSON.stringify(info)); + } set pfpsrc(e) { this.json.pfpsrc = e; this.updateLocal(); diff --git a/translations/en.json b/translations/en.json index 3fa1603..b95739c 100644 --- a/translations/en.json +++ b/translations/en.json @@ -316,7 +316,12 @@ "advancedBot": "Advanced Bot Settings", "botInviteCreate": "Bot Invite Creator", "language": "Language:", - "connections": "Connections" + "connections": "Connections", + "deleteAccount": "Account Deletion", + "areYouSureDelete": "Are you sure you want to delete your account? If so enter the phrase $1", + "sillyDeleteConfirmPhrase": "Shrek is love, Shrek is life", + "deleteAccountButton": "Delete account", + "mustTypePhrase": "To delete your account you must type the phrase" }, "message": { "reactionAdd": "Add reaction", diff --git a/translations/qqq.json b/translations/qqq.json index 216daf3..c64b29d 100644 --- a/translations/qqq.json +++ b/translations/qqq.json @@ -3,11 +3,7 @@ "last-updated": "2024/11/4", "locale": "en", "comment": "Don't know how often I'll update this top part lol", - "authors": [ - "MathMan05", - "McDutchie", - "Vl1" - ] + "authors": ["MathMan05", "McDutchie", "Vl1"] }, "readableName": "{{doc-important|This should be the name of the language you are translating into, in that language. Please DO NOT translate this into your language’s word for “English”!}}", "typing": "$1 is the number of people typing and $2 is the names of the people typing separated by commas", @@ -22,7 +18,8 @@ }, "localuser": { "updateSettings": "Title of a page that allows you to adjust the update settings", - "description": "This object contains strings related to the logged in user, which is mostly the settings for the user" + "description": "This object contains strings related to the logged in user, which is mostly the settings for the user", + "sillyDeleteConfirmPhrase": "This is a silly phrase, do not translate this directly, make a joke that is easy to type in your language" }, "errorReconnect": "Uses MarkDown" }