diff --git a/app/composables/user_password_rules.js b/app/composables/user_password_rules.js index cb9f7ac..4bda4ea 100644 --- a/app/composables/user_password_rules.js +++ b/app/composables/user_password_rules.js @@ -42,4 +42,4 @@ export function useUserPasswordRules(passwordRef, firstnameRef, lastnameRef) { return { passwordErrors, }; -} \ No newline at end of file +} diff --git a/app/pages/admin/index.vue b/app/pages/admin/index.vue index 3279c31..af2f43c 100644 --- a/app/pages/admin/index.vue +++ b/app/pages/admin/index.vue @@ -25,10 +25,21 @@
- -
- {{ passwordRequestError }} + +
+ • {{ passwordRequestError }} +
+
+
+ • {{ err }} +
@@ -36,7 +47,12 @@ - @@ -158,6 +174,8 @@ import { useUsersStore } from "~~/store/users"; import { getAvatarUrlByName } from "~~/composables/avatar"; import { useToast } from "vue-toastification"; +import { toRef } from "vue"; +import { useUserPasswordRules } from "@/composables/user_password_rules"; import { Modal } from "bootstrap"; const toast = useToast(); const userStore = useUsersStore(); @@ -168,6 +186,21 @@ const updateuserError = ref(false); const updateuserPending = ref(false); const passwordRequestError = ref(false); const cancleButton = ref(false); +const passwordSubmitted = ref(false); +const password = reactive({ + new: "", + confirm: "", +}); +const newPasswordRef = toRef(password, "new"); + +const { passwordErrors } = useUserPasswordRules( + newPasswordRef, +); + +const isChangePasswordDisabled = computed(() => { + return !password.new || !password.confirm; +}); + const route = useRoute(); const passwordModalEl = ref(null); let passwordModal = null; @@ -225,11 +258,6 @@ const userData = reactive({ email_verify: false, }); -const password = reactive({ - new: "", - confirm: "", -}); - watch( [user, userError], () => { @@ -321,9 +349,15 @@ const fetchFlowIdAndCsrfToken = async () => { }; const changePassword = async () => { + passwordSubmitted.value = true; try { + if (passwordErrors.value.length > 0) { + return; + } + if (password.new !== password.confirm) { - throw new Error("Passwords do not match."); + passwordRequestError.value = "Passwords do not match."; + return; } await fetchFlowIdAndCsrfToken(); @@ -345,10 +379,6 @@ const changePassword = async () => { } ); - if (response.status == 400) { - throw new Error("the password is too similar to the user identifier"); - } - if (!response.ok) { const errorData = await response.json(); if (errorData.error.id === "session_refresh_required") { @@ -359,11 +389,12 @@ const changePassword = async () => { } passwordRequestError.value = ""; + password.new = ""; + password.confirm = ""; - var closeModalButton = document.getElementById("closeModalButton"); - closeModalButton.click(); + toast.success("Password updated successfully."); + document.getElementById("closeModalButton").click(); } catch (error) { - console.error("Error during password change:", error.message); passwordRequestError.value = error.message; } };