Changes Update User

This commit is contained in:
Thien Pham Van
2026-02-24 11:06:46 +07:00
parent 24dfaf52c4
commit 06f78f95d7
9 changed files with 675 additions and 536 deletions

View File

@@ -3,13 +3,13 @@
<div class="field is-horizontal">
<div class="field-body columns">
<div class="field column">
<label class="label">Username</label>
<label class="label">{{ isVietnamese ? 'Tên tài khoản' : 'Username' }}</label>
<div class="control">
<p>{{ props.row.username }}</p>
</div>
</div>
<div class="field column">
<label class="label">{{ isVietnamese ? "Loại tài khoản" : "Account type" }}</label>
<label class="label">{{ isVietnamese ? 'Loại tài khoản' : 'Account type' }}</label>
<div class="control">
<p>{{ isVietnamese ? props.row.type__name : props.row.type__en }}</p>
</div>
@@ -19,7 +19,7 @@
<div class="field is-horizontal mt-4">
<div class="field-body columns">
<div class="field column">
<label class="label">{{ isVietnamese ? "Họ tên" : "Full name" }}</label>
<label class="label">{{ isVietnamese ? 'Họ tên' : 'Full name' }}</label>
<div class="control">
<p>{{ props.row.fullname }}</p>
</div>
@@ -34,15 +34,15 @@
</div>
<div class="mt-5 pt-2">
<button :class="`button is-primary has-text-white ${showModal.loading ? 'is-loading' : ''}`" @click="showConfirm">
{{ isVietnamese ? "Đặt lại mật khẩu" : "Reset password" }}
{{ isVietnamese ? 'Đặt lại mật khẩu' : 'Reset password' }}
</button>
</div>
<Modal v-bind="showModal" v-if="showModal.show" @close="showModal.show = false"> </Modal>
</div>
</template>
<script setup>
const { $store, $id, $insertapi, $getdata, $getpath, $updateapi, $dialog, $snackbar } = useNuxtApp();
const emit = defineEmits(["close"]);
const { $store, $id, $insertapi, $getdata, $getpath, $updateapi, $dialog, $snackbar, $isVietnamese } = useNuxtApp();
const emit = defineEmits(['close']);
var props = defineProps({
row: Object,
});
@@ -52,47 +52,51 @@ const showModal = ref({
loading: false,
});
const isVietnamese = computed(() => $store.lang.toLowerCase() === "vi");
const isVietnamese = computed(() => $isVietnamese());
let pass = $id().toLocaleLowerCase();
async function handlerResetPassword() {
showModal.value.loading = true;
let user = await $getdata("user", undefined, { filter: { id: props.row.id } }, true);
let user = await $getdata('user', undefined, { filter: { id: props.row.id } }, true);
const response = await fetch(`${$getpath()}password/${pass}/`);
let hash = await response.json();
user.password = hash;
let rs1 = await $updateapi("user", user, null, false);
if (rs1 === "error") {
$dialog("Có lỗi xảy ra. Hãy thử lại một lần nữa", "Lỗi", "Error");
let rs1 = await $updateapi('user', user, null, false);
if (rs1 === 'error') {
$dialog('Có lỗi xảy ra. Hãy thử lại một lần nữa', 'Lỗi', 'Error');
} else {
showModal.value.show = false;
let content = `<p>Xin chào ${props.row.fullname}, </p>`;
content += "<p>Mật khẩu tài khoản của bạn trên hệ thống đã được đặt lại thành công.</p>";
content += "<p>Tài khoản đăng nhập của bạn:</p>";
content += '<p>Mật khẩu tài khoản của bạn trên hệ thống đã được đặt lại thành công.</p>';
content += '<p>Tài khoản đăng nhập của bạn:</p>';
content += `<p>Username: ${props.row.username}</p>`;
content += `<p>Password: ${pass}</p>`;
content += `<p>Đội ngũ Utopia.</p>`;
let info = {
subject: "Thông báo đặt lại mật khẩu tài khoản đăng nhập Utopia",
subject: 'Thông báo đặt lại mật khẩu tài khoản đăng nhập Utopia',
to: props.row.email,
sender: 1,
content: content,
};
let rs = await $insertapi("sendemail", info, null, false);
let rs = await $insertapi('sendemail', info, null, false);
showModal.value.loading = false;
$snackbar("Mật khẩu đã được đặt lại thành công. Thông tin đã được gửi tới địa chỉ email đã đăng ký.", "Thành công", "Success");
emit("close");
$snackbar(
'Mật khẩu đã được đặt lại thành công. Thông tin đã được gửi tới địa chỉ email đã đăng ký.',
'Thành công',
'Success',
);
emit('close');
}
}
function showConfirm() {
showModal.value = {
show: true,
title: !isVietnamese ? "Confirm password reset" : "Xác nhận đặt lại mật khẩu",
height: "300px",
width: "800px",
component: "dialog/Confirm",
title: !isVietnamese ? 'Confirm password reset' : 'Xác nhận đặt lại mật khẩu',
height: '300px',
width: '800px',
component: 'dialog/Confirm',
vbind: {
content: `Bạn có muốn đặt lại mật khẩu cho tài khoản ${props.row.username?.toUpperCase()} này không?`,
duration: 10,