From dfc649043a88e775c9b3db1124d6d92f6b6c5368 Mon Sep 17 00:00:00 2001 From: PhantomMantis Date: Fri, 12 Apr 2024 21:51:55 -0600 Subject: [PATCH] =?UTF-8?q?refactor:=20=F0=9F=94=A7=20moved=20password=20t?= =?UTF-8?q?o=20account=20page?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/modules/settings/pages/Account.vue | 77 +++++++++++++++++-- .../src/modules/settings/pages/Main.vue | 7 -- .../src/modules/settings/pages/Password.vue | 64 --------------- .../src/modules/settings/router/children.ts | 9 --- 4 files changed, 71 insertions(+), 86 deletions(-) delete mode 100644 apps/wizarr-frontend/src/modules/settings/pages/Password.vue diff --git a/apps/wizarr-frontend/src/modules/settings/pages/Account.vue b/apps/wizarr-frontend/src/modules/settings/pages/Account.vue index 0107a51ed..ef9db652d 100644 --- a/apps/wizarr-frontend/src/modules/settings/pages/Account.vue +++ b/apps/wizarr-frontend/src/modules/settings/pages/Account.vue @@ -1,19 +1,51 @@ @@ -23,6 +55,9 @@ import { defineComponent } from "vue"; import { useUserStore } from "@/stores/user"; import { mapState, mapActions } from "pinia"; +import Auth from "@/api/authentication"; +import PasswordMeter from "vue-simple-password-meter"; + interface SaveAccountData { firstName: string; lastName: string; @@ -41,6 +76,17 @@ export default defineComponent({ }, ...mapState(useUserStore, ["user"]), }, + components: { + PasswordMeter, + }, + data() { + return { + auth: new Auth(), + old_password: "", + new_password: "", + confirm_password: "", + }; + }, methods: { saveAccount(data: SaveAccountData) { this.updateUser({ @@ -50,6 +96,25 @@ export default defineComponent({ }); }, ...mapActions(useUserStore, ["updateUser"]), + resetForm() { + this.old_password = ""; + this.new_password = ""; + this.confirm_password = ""; + }, + async changePassword({ old_password, new_password, confirm_password }: { old_password: string; new_password: string; confirm_password: string }) { + if (new_password !== confirm_password) { + this.$toast.error("Passwords do not match"); + return; + } else if (old_password === new_password) { + this.$toast.error("New password cannot be the same as the old password"); + return; + } + await this.auth.changePassword(old_password, new_password).then((res) => { + if (res !== undefined) { + this.resetForm(); + } + }); + }, }, }); diff --git a/apps/wizarr-frontend/src/modules/settings/pages/Main.vue b/apps/wizarr-frontend/src/modules/settings/pages/Main.vue index 7dcf83715..f196eae0e 100644 --- a/apps/wizarr-frontend/src/modules/settings/pages/Main.vue +++ b/apps/wizarr-frontend/src/modules/settings/pages/Main.vue @@ -162,13 +162,6 @@ export default defineComponent({ icon: "fas fa-user-circle", url: "/admin/settings/account", }, - { - title: this.__("Password"), - description: this.__("Change your password"), - icon: "fas fa-lock", - url: "/admin/settings/password", - disabled: false, - }, { title: this.__("Sessions"), description: this.__("View and manage your active sessions"), diff --git a/apps/wizarr-frontend/src/modules/settings/pages/Password.vue b/apps/wizarr-frontend/src/modules/settings/pages/Password.vue deleted file mode 100644 index 305a03aac..000000000 --- a/apps/wizarr-frontend/src/modules/settings/pages/Password.vue +++ /dev/null @@ -1,64 +0,0 @@ - - - diff --git a/apps/wizarr-frontend/src/modules/settings/router/children.ts b/apps/wizarr-frontend/src/modules/settings/router/children.ts index bc0d2f0a7..e7187ed03 100644 --- a/apps/wizarr-frontend/src/modules/settings/router/children.ts +++ b/apps/wizarr-frontend/src/modules/settings/router/children.ts @@ -70,15 +70,6 @@ const children: RouteRecordRaw[] = [ subheader: "Configure multi-factor authentication", }, }, - { - path: "password", - name: "admin-settings-password", - component: () => import("../pages/Password.vue"), - meta: { - header: "Manage Password", - subheader: "Change your account password", - }, - }, { path: "tasks", name: "admin-settings-tasks",