diff --git a/src/webpage/index.ts b/src/webpage/index.ts index f400d97..9244a7c 100644 --- a/src/webpage/index.ts +++ b/src/webpage/index.ts @@ -110,6 +110,9 @@ import {I18n} from "./i18n.js"; try { const current = sessionStorage.getItem("currentuser") || users.currentuser; console.log(users.users, current); + if (!users.users[current]) { + window.location.href = "/login"; + } thisUser = new Localuser(users.users[current]); thisUser.initwebsocket().then(() => { thisUser.loaduser(); diff --git a/src/webpage/localuser.ts b/src/webpage/localuser.ts index 3ed3528..5b9e3b1 100644 --- a/src/webpage/localuser.ts +++ b/src/webpage/localuser.ts @@ -1702,9 +1702,16 @@ class Localuser { { const deleteAccount = settings.addButton(I18n.localuser.deleteAccount()).addForm( "", - () => { - this.userinfo.remove(); - window.location.href = "/"; + (e) => { + console.log(e); + if ("message" in e) { + if (typeof e.message === "string") { + throw new FormError(password, e.message); + } + } else { + this.userinfo.remove(); + window.location.href = "/"; + } }, { headers: this.headers, @@ -1718,7 +1725,7 @@ class Localuser { I18n.localuser.areYouSureDelete(I18n.localuser.sillyDeleteConfirmPhrase()), "shrek", ); - deleteAccount.addTextInput(I18n.localuser["password:"](), "password"); + const password = deleteAccount.addTextInput(I18n.localuser["password:"](), "password"); deleteAccount.addPreprocessor((obj) => { if ("shrek" in obj) { if (obj.shrek !== I18n.localuser.sillyDeleteConfirmPhrase()) { diff --git a/src/webpage/login.ts b/src/webpage/login.ts index 2570071..c24a51c 100644 --- a/src/webpage/login.ts +++ b/src/webpage/login.ts @@ -223,7 +223,7 @@ if (document.getElementById("form")) { } //this currently does not work, and need to be implemented better at some time. if (!localStorage.getItem("SWMode")) { - localStorage.setItem("SWMode", "true"); + localStorage.setItem("SWMode", "SWOn"); } trimswitcher(); diff --git a/src/webpage/utils/utils.ts b/src/webpage/utils/utils.ts index 144f0fa..f98fee2 100644 --- a/src/webpage/utils/utils.ts +++ b/src/webpage/utils/utils.ts @@ -92,6 +92,17 @@ export class Specialuser { remove() { const info = getBulkInfo(); delete info.users[this.uid]; + if (info.currentuser === this.uid) { + const user = info.users[0]; + if (user) { + info.currentuser = new Specialuser(user).uid; + } else { + info.currentuser = null; + } + } + if (sessionStorage.getItem("currentuser") === this.uid) { + sessionStorage.delete("currentuser"); + } localStorage.setItem("userinfos", JSON.stringify(info)); } set pfpsrc(e) {