From 8e153cd92f8689dd398966997283515e00c0ea3b Mon Sep 17 00:00:00 2001 From: Harvey Tindall Date: Tue, 20 Jun 2023 16:44:12 +0100 Subject: [PATCH] userpage: unlink accounts --- api-userpage.go | 30 ++++++++++++++++++++++++++++++ lang/admin/da-dk.json | 1 - lang/admin/de-de.json | 1 - lang/admin/el-gr.json | 1 - lang/admin/en-gb.json | 1 - lang/admin/en-us.json | 1 - lang/admin/es-es.json | 1 - lang/admin/fr-fr.json | 1 - lang/admin/hu-hu.json | 1 - lang/admin/id-id.json | 1 - lang/admin/nl-nl.json | 1 - lang/admin/pl-pl.json | 1 - lang/admin/pt-br.json | 1 - lang/admin/sv-se.json | 1 - lang/admin/vi-vn.json | 1 - lang/admin/zh-hans.json | 1 - lang/admin/zh-hant.json | 1 - lang/common/da-dk.json | 3 ++- lang/common/de-de.json | 3 ++- lang/common/el-gr.json | 3 ++- lang/common/en-gb.json | 3 ++- lang/common/en-us.json | 7 +++---- lang/common/es-es.json | 3 ++- lang/common/fr-fr.json | 3 ++- lang/common/hu-hu.json | 3 ++- lang/common/id-id.json | 3 ++- lang/common/nl-nl.json | 3 ++- lang/common/pt-br.json | 3 ++- lang/common/sv-se.json | 3 ++- lang/common/vi-vn.json | 3 ++- lang/common/zh-hans.json | 3 ++- lang/common/zh-hant.json | 3 ++- lang/form/en-us.json | 2 +- router.go | 3 +++ scripts/langmover/common.json | 5 +++-- ts/user.ts | 35 +++++++++++++++++++++++++---------- 36 files changed, 93 insertions(+), 47 deletions(-) diff --git a/api-userpage.go b/api-userpage.go index 4a84949..718741a 100644 --- a/api-userpage.go +++ b/api-userpage.go @@ -449,3 +449,33 @@ func (app *appContext) MatrixCheckMyPIN(gc *gin.Context) { delete(app.matrix.tokens, pin) respondBool(200, true, gc) } + +// @Summary unlink the Discord account from your Jellyfin user. Always succeeds. +// @Produce json +// @Success 200 {object} boolResponse +// @Router /my/discord [delete] +// @Tags Users +func (app *appContext) UnlinkMyDiscord(gc *gin.Context) { + app.storage.DeleteDiscordKey(gc.GetString("jfId")) + respondBool(200, true, gc) +} + +// @Summary unlink the Telegram account from your Jellyfin user. Always succeeds. +// @Produce json +// @Success 200 {object} boolResponse +// @Router /my/telegram [delete] +// @Tags Users +func (app *appContext) UnlinkMyTelegram(gc *gin.Context) { + app.storage.DeleteTelegramKey(gc.GetString("jfId")) + respondBool(200, true, gc) +} + +// @Summary unlink the Matrix account from your Jellyfin user. Always succeeds. +// @Produce json +// @Success 200 {object} boolResponse +// @Router /my/matrix [delete] +// @Tags Users +func (app *appContext) UnlinkMyMatrix(gc *gin.Context) { + app.storage.DeleteMatrixKey(gc.GetString("jfId")) + respondBool(200, true, gc) +} diff --git a/lang/admin/da-dk.json b/lang/admin/da-dk.json index 3b117ce..da0e967 100644 --- a/lang/admin/da-dk.json +++ b/lang/admin/da-dk.json @@ -17,7 +17,6 @@ "inviteSendToEmail": "Send til", "create": "Opret", "apply": "Anvend", - "delete": "Slet", "select": "Vælg", "name": "Navn", "date": "Dato", diff --git a/lang/admin/de-de.json b/lang/admin/de-de.json index 1004d5c..bbcf259 100644 --- a/lang/admin/de-de.json +++ b/lang/admin/de-de.json @@ -15,7 +15,6 @@ "inviteSendToEmail": "Senden an", "create": "Erstellen", "apply": "Anwenden", - "delete": "Löschen", "name": "Name", "date": "Datum", "lastActiveTime": "Zuletzt aktiv", diff --git a/lang/admin/el-gr.json b/lang/admin/el-gr.json index dc358df..e84f19b 100644 --- a/lang/admin/el-gr.json +++ b/lang/admin/el-gr.json @@ -15,7 +15,6 @@ "inviteSendToEmail": "Αποστολή σε", "create": "Δημιουργία", "apply": "Εφαρμογή", - "delete": "Διαγραφή", "name": "Όνομα", "date": "Ημερομηνία", "lastActiveTime": "Τελευταία Ενεργός", diff --git a/lang/admin/en-gb.json b/lang/admin/en-gb.json index 44a3cf8..d716caa 100644 --- a/lang/admin/en-gb.json +++ b/lang/admin/en-gb.json @@ -69,7 +69,6 @@ "inviteInfiniteUsesWarning": "invites with infinite uses can be used abusively", "inviteSendToEmail": "Send to", "apply": "Apply", - "delete": "Delete", "updates": "Updates", "variables": "Variables", "preview": "Preview", diff --git a/lang/admin/en-us.json b/lang/admin/en-us.json index c1eb7e4..05b083d 100644 --- a/lang/admin/en-us.json +++ b/lang/admin/en-us.json @@ -17,7 +17,6 @@ "inviteSendToEmail": "Send to", "create": "Create", "apply": "Apply", - "delete": "Delete", "select": "Select", "name": "Name", "date": "Date", diff --git a/lang/admin/es-es.json b/lang/admin/es-es.json index 6e41364..1506e76 100644 --- a/lang/admin/es-es.json +++ b/lang/admin/es-es.json @@ -17,7 +17,6 @@ "inviteSendToEmail": "Enviar a", "create": "Crear", "apply": "Aplicar", - "delete": "Eliminar", "name": "Nombre", "date": "Fecha", "updates": "Actualizaciones", diff --git a/lang/admin/fr-fr.json b/lang/admin/fr-fr.json index 2a5809e..cb8eb5a 100644 --- a/lang/admin/fr-fr.json +++ b/lang/admin/fr-fr.json @@ -17,7 +17,6 @@ "inviteSendToEmail": "Envoyer à", "create": "Créer", "apply": "Appliquer", - "delete": "Effacer", "name": "Nom", "date": "Date", "lastActiveTime": "Dernière activité", diff --git a/lang/admin/hu-hu.json b/lang/admin/hu-hu.json index 9ad59ed..4161ef0 100644 --- a/lang/admin/hu-hu.json +++ b/lang/admin/hu-hu.json @@ -17,7 +17,6 @@ "inviteSendToEmail": "Címzett", "create": "Létrehozás", "apply": "Alkalmaz", - "delete": "Törlés", "select": "Kiválasztás", "name": "Név", "date": "Dátum", diff --git a/lang/admin/id-id.json b/lang/admin/id-id.json index 71a1869..5957396 100644 --- a/lang/admin/id-id.json +++ b/lang/admin/id-id.json @@ -15,7 +15,6 @@ "inviteSendToEmail": "Dikirim kepada", "create": "Buat", "apply": "Terapkan", - "delete": "Hapus", "name": "Nama", "date": "Tanggal", "lastActiveTime": "Terakhir Aktif", diff --git a/lang/admin/nl-nl.json b/lang/admin/nl-nl.json index 0464d96..46b9452 100644 --- a/lang/admin/nl-nl.json +++ b/lang/admin/nl-nl.json @@ -15,7 +15,6 @@ "inviteSendToEmail": "Stuur naar", "create": "Aanmaken", "apply": "Toepassen", - "delete": "Verwijderen", "name": "Naam", "date": "Datum", "lastActiveTime": "Laatst actief", diff --git a/lang/admin/pl-pl.json b/lang/admin/pl-pl.json index 522fb02..6b1bdc2 100644 --- a/lang/admin/pl-pl.json +++ b/lang/admin/pl-pl.json @@ -17,7 +17,6 @@ "inviteSendToEmail": "", "create": "", "apply": "", - "delete": "", "select": "", "name": "Imię", "date": "Data", diff --git a/lang/admin/pt-br.json b/lang/admin/pt-br.json index 2073940..0310937 100644 --- a/lang/admin/pt-br.json +++ b/lang/admin/pt-br.json @@ -15,7 +15,6 @@ "inviteSendToEmail": "Enviar para", "create": "Criar", "apply": "Aplicar", - "delete": "Deletar", "name": "Nome", "date": "Data", "lastActiveTime": "Ativo pela última vez", diff --git a/lang/admin/sv-se.json b/lang/admin/sv-se.json index 60dd719..1f7e1f1 100644 --- a/lang/admin/sv-se.json +++ b/lang/admin/sv-se.json @@ -15,7 +15,6 @@ "inviteSendToEmail": "Skicka till", "create": "Skapa", "apply": "Tillämpa", - "delete": "Radera", "name": "Namn", "date": "Datum", "lastActiveTime": "Senast aktiv", diff --git a/lang/admin/vi-vn.json b/lang/admin/vi-vn.json index 6366e28..7dd7e56 100644 --- a/lang/admin/vi-vn.json +++ b/lang/admin/vi-vn.json @@ -17,7 +17,6 @@ "inviteSendToEmail": "Gửi tới", "create": "Tạo mới", "apply": "Áp dụng", - "delete": "Xóa", "select": "Chọn", "name": "Tên", "date": "Ngày", diff --git a/lang/admin/zh-hans.json b/lang/admin/zh-hans.json index 98d050f..6190c8f 100644 --- a/lang/admin/zh-hans.json +++ b/lang/admin/zh-hans.json @@ -17,7 +17,6 @@ "inviteSendToEmail": "发送到", "create": "创建", "apply": "申请", - "delete": "删除", "select": "选择", "name": "名称", "date": "日期", diff --git a/lang/admin/zh-hant.json b/lang/admin/zh-hant.json index d876316..5546e09 100644 --- a/lang/admin/zh-hant.json +++ b/lang/admin/zh-hant.json @@ -17,7 +17,6 @@ "inviteSendToEmail": "發送到", "create": "創建", "apply": "應用", - "delete": "刪除", "select": "選擇", "name": "帳戶名稱", "date": "日期", diff --git a/lang/common/da-dk.json b/lang/common/da-dk.json index b2c3f3f..ce3fb1d 100644 --- a/lang/common/da-dk.json +++ b/lang/common/da-dk.json @@ -34,7 +34,8 @@ "disable": "Deaktiver", "expiry": "Udløb", "add": "Tilføj", - "edit": "Rediger" + "edit": "Rediger", + "delete": "Slet" }, "notifications": { "errorLoginBlank": "Brugernavnet og/eller adgangskoden blev efterladt tomme.", diff --git a/lang/common/de-de.json b/lang/common/de-de.json index 339ce88..6459eef 100644 --- a/lang/common/de-de.json +++ b/lang/common/de-de.json @@ -34,7 +34,8 @@ "disable": "Deaktivieren", "expiry": "Ablaufdatum", "add": "Hinzufügen", - "edit": "Bearbeiten" + "edit": "Bearbeiten", + "delete": "Löschen" }, "notifications": { "errorLoginBlank": "Der Benutzername und/oder das Passwort wurden nicht ausgefüllt.", diff --git a/lang/common/el-gr.json b/lang/common/el-gr.json index 7826ab7..3c0c5c9 100644 --- a/lang/common/el-gr.json +++ b/lang/common/el-gr.json @@ -24,7 +24,8 @@ "reEnable": "Επανα-ενεργοποίηση", "disable": "Απενεργοποίηση", "expiry": "Λήξη", - "edit": "Επεξεργασία" + "edit": "Επεξεργασία", + "delete": "Διαγραφή" }, "notifications": { "errorLoginBlank": "Το όνομα χρήστη και/ή ο κωδικός ήταν κενά.", diff --git a/lang/common/en-gb.json b/lang/common/en-gb.json index bb44536..ff6147b 100644 --- a/lang/common/en-gb.json +++ b/lang/common/en-gb.json @@ -34,7 +34,8 @@ "disable": "Disable", "expiry": "Expiry", "add": "Add", - "edit": "Edit" + "edit": "Edit", + "delete": "Delete" }, "notifications": { "errorLoginBlank": "The username and/or password was left blank.", diff --git a/lang/common/en-us.json b/lang/common/en-us.json index 3102ea3..688b5a2 100644 --- a/lang/common/en-us.json +++ b/lang/common/en-us.json @@ -33,13 +33,12 @@ "reEnable": "Re-enable", "disable": "Disable", "contactMethods": "Contact Methods", - "addContactMethod": "Add Contact Method", - "editContactMethod": "Edit Contact Method", "accountStatus": "Account Status", "notSet": "Not set", "expiry": "Expiry", "add": "Add", - "edit": "Edit" + "edit": "Edit", + "delete": "Delete" }, "notifications": { "errorLoginBlank": "The username and/or password were left blank.", @@ -62,4 +61,4 @@ "plural": "{n} Days" } } -} +} \ No newline at end of file diff --git a/lang/common/es-es.json b/lang/common/es-es.json index b446d47..f0bec53 100644 --- a/lang/common/es-es.json +++ b/lang/common/es-es.json @@ -34,7 +34,8 @@ "disable": "Desactivar", "expiry": "Expiración", "add": "Agregar", - "edit": "Editar" + "edit": "Editar", + "delete": "Eliminar" }, "notifications": { "errorLoginBlank": "El nombre de usuario y/o la contraseña se dejaron en blanco.", diff --git a/lang/common/fr-fr.json b/lang/common/fr-fr.json index 193ef1f..d7dfd5c 100644 --- a/lang/common/fr-fr.json +++ b/lang/common/fr-fr.json @@ -34,7 +34,8 @@ "disable": "Désactivé", "expiry": "Expiration", "add": "Ajouter", - "edit": "Éditer" + "edit": "Éditer", + "delete": "Effacer" }, "notifications": { "errorLoginBlank": "Le nom d'utilisateur et/ou le mot de passe sont vides.", diff --git a/lang/common/hu-hu.json b/lang/common/hu-hu.json index c4323a9..5c68b40 100644 --- a/lang/common/hu-hu.json +++ b/lang/common/hu-hu.json @@ -12,7 +12,8 @@ "disable": "Letiltás", "expiry": "Lejárat", "add": "Hozzáadás", - "edit": "Szerkesztés" + "edit": "Szerkesztés", + "delete": "Törlés" }, "notifications": {}, "quantityStrings": {} diff --git a/lang/common/id-id.json b/lang/common/id-id.json index a925667..e8f4e9b 100644 --- a/lang/common/id-id.json +++ b/lang/common/id-id.json @@ -18,7 +18,8 @@ "theme": "Tema", "login": "Masuk", "logout": "Keluar", - "edit": "Edit" + "edit": "Edit", + "delete": "Hapus" }, "notifications": { "errorLoginBlank": "Nama pengguna dan / atau sandi kosong.", diff --git a/lang/common/nl-nl.json b/lang/common/nl-nl.json index b43329a..0591de1 100644 --- a/lang/common/nl-nl.json +++ b/lang/common/nl-nl.json @@ -34,7 +34,8 @@ "disable": "Uitschakelen", "expiry": "Verloop", "add": "Voeg toe", - "edit": "Bewerken" + "edit": "Bewerken", + "delete": "Verwijderen" }, "notifications": { "errorLoginBlank": "De gebruikersnaam en/of wachtwoord is leeg.", diff --git a/lang/common/pt-br.json b/lang/common/pt-br.json index 5ed9ae1..b7953fa 100644 --- a/lang/common/pt-br.json +++ b/lang/common/pt-br.json @@ -34,7 +34,8 @@ "disable": "Desativar", "expiry": "Expira", "add": "Adicionar", - "edit": "Editar" + "edit": "Editar", + "delete": "Deletar" }, "notifications": { "errorLoginBlank": "O nome de usuário e/ou senha foram deixados em branco.", diff --git a/lang/common/sv-se.json b/lang/common/sv-se.json index 554ae2c..0eb8b5f 100644 --- a/lang/common/sv-se.json +++ b/lang/common/sv-se.json @@ -21,7 +21,8 @@ "enabled": "Aktiverad", "disabled": "Inaktiverad", "expiry": "Löper ut", - "edit": "Redigera" + "edit": "Redigera", + "delete": "Radera" }, "notifications": { "errorLoginBlank": "Användarnamnet och/eller lösenordet lämnades tomt.", diff --git a/lang/common/vi-vn.json b/lang/common/vi-vn.json index dce2ccb..3a8abbd 100644 --- a/lang/common/vi-vn.json +++ b/lang/common/vi-vn.json @@ -12,7 +12,8 @@ "disable": "Tắt", "expiry": "Hết hạn", "add": "Thêm", - "edit": "Chỉnh sửa" + "edit": "Chỉnh sửa", + "delete": "Xóa" }, "notifications": { "errorConnection": "Không thể kết nối với jfa-go.", diff --git a/lang/common/zh-hans.json b/lang/common/zh-hans.json index 1c6daa7..2d12e74 100644 --- a/lang/common/zh-hans.json +++ b/lang/common/zh-hans.json @@ -34,7 +34,8 @@ "disable": "禁用", "expiry": "到期", "add": "添加", - "edit": "编辑" + "edit": "编辑", + "delete": "删除" }, "notifications": { "errorLoginBlank": "用户名/密码留空。", diff --git a/lang/common/zh-hant.json b/lang/common/zh-hant.json index a4fe3a6..8b0b42f 100644 --- a/lang/common/zh-hant.json +++ b/lang/common/zh-hant.json @@ -34,7 +34,8 @@ "disable": "禁用", "expiry": "到期", "add": "添加", - "edit": "編輯" + "edit": "編輯", + "delete": "刪除" }, "notifications": { "errorLoginBlank": "帳戶名稱和/或密碼留空。", diff --git a/lang/form/en-us.json b/lang/form/en-us.json index 1e132b3..d41904c 100644 --- a/lang/form/en-us.json +++ b/lang/form/en-us.json @@ -61,4 +61,4 @@ "plural": "Must have at least {n} special characters" } } -} +} \ No newline at end of file diff --git a/router.go b/router.go index 18e3814..bf9bf99 100644 --- a/router.go +++ b/router.go @@ -237,6 +237,9 @@ func (app *appContext) loadRoutes(router *gin.Engine) { user.GET(p+"/telegram/verified/:pin", app.MyTelegramVerifiedInvite) user.POST(p+"/matrix/user", app.MatrixSendMyPIN) user.POST(p+"/matrix/verified/:userID/:pin", app.MatrixCheckMyPIN) + user.DELETE(p+"/discord", app.UnlinkMyDiscord) + user.DELETE(p+"/telegram", app.UnlinkMyTelegram) + user.DELETE(p+"/matrix", app.UnlinkMyMatrix) } } } diff --git a/scripts/langmover/common.json b/scripts/langmover/common.json index b04d430..3d078d3 100644 --- a/scripts/langmover/common.json +++ b/scripts/langmover/common.json @@ -36,8 +36,9 @@ "accountStatus": "common", "notSet": "common", "expiry": "common", - "add": "admin", - "edit": "admin" + "add": "common", + "edit": "common", + "delete": "admin" }, "notifications": { "errorLoginBlank": "common", diff --git a/ts/user.ts b/ts/user.ts index 1983d66..39d9a8c 100644 --- a/ts/user.ts +++ b/ts/user.ts @@ -1,7 +1,7 @@ import { ThemeManager } from "./modules/theme.js"; import { lang, LangFile, loadLangSelector } from "./modules/lang.js"; import { Modal } from "./modules/modal.js"; -import { _get, _post, notificationBox, whichAnimationEvent, toDateString, toggleLoader } from "./modules/common.js"; +import { _get, _post, _delete, notificationBox, whichAnimationEvent, toDateString, toggleLoader } from "./modules/common.js"; import { Login } from "./modules/login.js"; import { Discord, Telegram, Matrix, ServiceConfiguration, MatrixConfiguration } from "./modules/account-linking.js"; @@ -92,7 +92,7 @@ class ContactMethods { this._buttons = {}; } - append = (name: string, details: MyDetailsContactMethod, icon: string, addEditFunc?: (add: boolean) => void) => { + append = (name: string, details: MyDetailsContactMethod, icon: string, addEditFunc?: (add: boolean) => void, required?: boolean) => { const row = document.createElement("div"); row.classList.add("row", "flex-expand", "my-2"); let innerHTML = ` @@ -118,6 +118,15 @@ class ContactMethods { `; } + + if (!required && details.value != "") { + innerHTML += ` + + `; + } + innerHTML += ` `; @@ -159,6 +168,14 @@ class ContactMethods { const addEditButton = row.querySelector(".user-contact-edit") as HTMLButtonElement; addEditButton.onclick = () => addEditFunc(details.value == ""); } + + if (!required && details.value != "") { + const deleteButton = row.querySelector(".user-contact-delete") as HTMLButtonElement; + deleteButton.onclick = () => _delete("/my/" + name, null, (req: XMLHttpRequest) => { + if (req.readyState != 4) return; + window.location.reload(); + }); + } this._content.appendChild(row); }; @@ -248,8 +265,6 @@ class ExpiryCard { this._interval = window.setInterval(this._drawCountdown, 60*1000); this._drawCountdown(); } - - } var expiryCard = new ExpiryCard(statusCard); @@ -359,16 +374,16 @@ document.addEventListener("details-reload", () => { // Note the weird format of the functions for discord/telegram: // "this" was being redefined within the onclick() method, so // they had to be wrapped in an anonymous function. - const contactMethods: { name: string, icon: string, f: (add: boolean) => void }[] = [ - {name: "email", icon: ``, f: addEditEmail}, - {name: "discord", icon: ``, f: (add: boolean) => { discord.onclick(); }}, - {name: "telegram", icon: ``, f: (add: boolean) => { telegram.onclick() }}, - {name: "matrix", icon: `[m]`, f: (add: boolean) => { matrix.show(); }} + const contactMethods: { name: string, icon: string, f: (add: boolean) => void, required: boolean }[] = [ + {name: "email", icon: ``, f: addEditEmail, required: true}, + {name: "discord", icon: ``, f: (add: boolean) => { discord.onclick(); }, required: window.discordRequired}, + {name: "telegram", icon: ``, f: (add: boolean) => { telegram.onclick() }, required: window.telegramRequired}, + {name: "matrix", icon: `[m]`, f: (add: boolean) => { matrix.show(); }, required: window.matrixRequired} ]; for (let method of contactMethods) { if (method.name in details) { - contactMethodList.append(method.name, details[method.name], method.icon, method.f); + contactMethodList.append(method.name, details[method.name], method.icon, method.f, method.required); } }