diff --git a/src/api/manage/api.management.ts b/src/api/manage/api.management.ts index 66341b36..26d97f09 100644 --- a/src/api/manage/api.management.ts +++ b/src/api/manage/api.management.ts @@ -16,4 +16,6 @@ export default { /** กำหนดสิทธิ์*/ managementPermission, + + resetPassword: `${management}/user/reset-password`, }; diff --git a/src/modules/02_users/views/01_user.vue b/src/modules/02_users/views/01_user.vue index d5727f4a..b30e964b 100644 --- a/src/modules/02_users/views/01_user.vue +++ b/src/modules/02_users/views/01_user.vue @@ -36,8 +36,11 @@ const { hideLoader, success, dialogConfirm, + dialogMessageNotify, } = useCounterMixin(); +const NODE_ENV = ref(process.env.NODE_ENV || "development"); + /** Tree*/ const activeId = ref(""); // id ของโครงสร้างที่ใช้งานอยู่ const orgId = ref(null); // id ของ node ที่เลือก @@ -195,6 +198,12 @@ const itemMenu = ref([ color: "blue-9", type: "managementRole", }, + { + label: "รีเซ็ตรหัสผ่าน", + icon: "mdi-lock-reset", + color: "teal-4", + type: "resetPassword", + }, { label: "ลบ", icon: "delete", @@ -281,7 +290,7 @@ async function fetchListUsers() { e.name === "STAFF" || e.name === "SUPER_ADMIN" || e.name === "ADMIN" || - e.name === "USER" + e.name === "USER", ) : [], })); @@ -319,6 +328,8 @@ function onClickAction(type: string, data: Users) { // เปลี่ยนสถานะเปิด/ปิดของผู้ใช้งาน const status = type === "open" ? true : false; onLockUser(data.id, status); + } else if (type === "resetPassword") { + onReSetPassword(data.id); } } @@ -346,7 +357,7 @@ async function onDeleteUser(id: string) { currentPage.value = await updateCurrentPage( currentPage.value, maxPage.value, - rows.value.length + rows.value.length, ); await fetchListUsers(); success($q, "ลบข้อมูลสำเร็จ"); @@ -385,7 +396,7 @@ function onLockUser(id: string, type: boolean) { type ? "ยืนยันการเปิดใช้" : "ยืนยันการระงับใช้งาน", type ? "ต้องการยืนยันการเปิดใช้นี้หรือไม่ ?" - : "ต้องการยืนยันระงับการใช้งานนี้หรือไม่ ?" + : "ต้องการยืนยันระงับการใช้งานนี้หรือไม่ ?", ); } @@ -410,7 +421,7 @@ function filterFnOptions(val: string, update: Function, type: string) { case "employeeClass": update(() => { employeeClassOption.value = employeeClassMain.value.filter( - (v: DataOption) => v.name.indexOf(val) > -1 + (v: DataOption) => v.name.indexOf(val) > -1, ); }); break; @@ -430,6 +441,32 @@ async function onSearchData() { await fetchListUsers(); } +function onReSetPassword(id: string) { + dialogConfirm( + $q, + async () => { + try { + showLoader(); + const messsage = + NODE_ENV.value === "production" + ? "รหัสผ่านจะถูกเปลี่ยนเป็น วันเดือนปีพุทธศักราชเกิด ของผู้ใช้งาน (รูปแบบ ววดดปปปป เช่น 14042533)" + : "ระบบจะตั้งรหัสผ่านใหม่เป็น P@ssw0rd"; + await http.post(config.API.resetPassword, { + keycloak: id, + }); + success($q, "รีเซ็ตรหัสผ่านสำเร็จ"); + dialogMessageNotify($q, messsage); + } catch (error) { + messageError($q, error); + } finally { + hideLoader(); + } + }, + "ยืนยันการรีเซ็ตรหัสผ่าน", + "ต้องการยืนยันการรีเซ็ตรหัสผ่านนี้หรือไม่ ?", + ); +} + /** * ดูการเปลี่ยนแปลงของจำนวนข้อมูลต่อหน้า * ดึงข้อมูลรายชื่อผู้ใช้งานตามจำนวนข้อมูลต่อหน้า @@ -438,7 +475,7 @@ watch( () => pageSize.value, () => { fetchListUsers(); - } + }, ); const tokenParsedData = ref([]); @@ -473,7 +510,7 @@ onMounted(async () => {