Changes Update User

This commit is contained in:
Thien Pham Van
2026-02-25 10:11:52 +07:00
parent 06f78f95d7
commit a19ecd2f01
3 changed files with 183 additions and 33 deletions

View File

@@ -4,7 +4,7 @@
<div class="field-body">
<div class="field">
<label class="label"
>{{ isVietnamese ? 'Tên tài khoản' : 'Username' }}<b class="ml-1 has-text-danger">*</b></label
>{{ isVietnamese ? 'Tên đăng nhập' : 'Username' }}<b class="ml-1 has-text-danger">*</b></label
>
<div class="control">
<input class="input" type="text" placeholder="" v-model="username" />
@@ -34,7 +34,7 @@
<div class="field-body">
<div class="field">
<label class="label"
>{{ isVietnamese ? 'Họ và tên' : 'Full name' }}<b class="ml-1 has-text-danger">*</b></label
>{{!dealer? isVietnamese ? 'Họ và tên' : 'Full name': isVietnamese ? 'Tên tài khoản' : 'Dealer name' }}<b class="ml-1 has-text-danger">*</b></label
>
<div class="control">
<input class="input" type="text" placeholder="" v-model="fullname" />
@@ -209,7 +209,7 @@ export default {
} else if (this.username !== this.username.replace(' ', '')) {
this.errors.push({ name: 'username', text: 'Tài khoản không được chứa khoảng trắng' });
} else if (this.username.length < 5) {
this.errors.push({ name: 'fullname', text: 'Tài khoản quá ngắn. Yêu cầu từ 5 kí tự trở nên' });
this.errors.push({ name: 'username', text: 'Tài khoản quá ngắn. Yêu cầu từ 5 kí tự trở nên' });
}
if (this.$empty(this.password)) {
this.errors.push({ name: 'password', text: 'Mật khẩu không được bỏ trống' });
@@ -276,24 +276,97 @@ export default {
} else {
//send email
if (this.email) {
let content = `<p>Xin chào ${this.fullname}, </p>`;
content += '<p>Tài khoản đăng nhập của bạn đã được khởi tạo và sẵn sàng sử dụng:</p>';
content += `<p>Username: ${this.username}</p>`;
content += `<p>Password: ${this.password}</p>`;
content += `<p>Đội ngũ Utopia.</p>`;
let info = { subject: 'Tài khoản đăng nhập Utopia', to: this.email, sender: 1, content: content };
let rs = await this.$insertapi('sendemail', info);
let loginUrl = this.$mode === 'dev' ? 'https://dev.biz.utopia.com.vn/' : 'https://biz.utopia.com.vn/';
await this.templateEmail(loginUrl);
}
}
if (this.dealer) {
let copy = this.$copy(this.row);
copy.user = this.user.id;
await this.$updaterow('dealer', copy, null, this.pagename);
let obj = { user: this.user.id, apps: 11 };
await this.$insertapi('userapps', obj, undefined, false);
let loginUrl = this.$mode === 'dev' ? 'https://dev.dealer.utopia.com.vn/' : 'https://dealer.utopia.com.vn/';
await this.templateEmail(loginUrl);
}
this.loading = false;
this.$dialog('Tạo tài khoản thành công.', 'Thành công', 'Success', 10);
this.$emit('close');
},
async templateEmail(loginUrl) {
let content = `
<table width="100%" bgcolor="#f4f6f8" cellpadding="0" cellspacing="0">
<tr>
<td align="center" style="padding:30px 15px;">
<table width="600" cellpadding="0" cellspacing="0" border="0"
style="background:#ffffff; font-family:Arial, Helvetica, sans-serif; color:#333333; border-collapse:collapse;">
<tr>
<td style="padding:30px 25px; font-size:15px; line-height:1.6;">
<p style="margin:0 0 15px 0;">
Xin chào <strong>${this.fullname}</strong>,
</p>
<p style="margin:0 0 15px 0;">
Tài khoản đăng nhập của bạn đã được khởi tạo thành công và sẵn sàng sử dụng.
</p>
<table width="100%" cellpadding="0" cellspacing="0" border="0" style="margin:15px 0;">
<tr>
<td width="120" style="padding:6px 0;"><strong>Username:</strong></td>
<td style="padding:6px 0;">${this.username}</td>
</tr>
<tr>
<td style="padding:6px 0;"><strong>Password:</strong></td>
<td style="padding:6px 0;">${this.password}</td>
</tr>
</table>
<table cellpadding="0" cellspacing="0" border="0" align="center" style="margin:25px auto;">
<tr>
<td align="center" bgcolor="#2f6fed" style="border-radius:4px;">
<a href="${loginUrl}"
target="_blank"
style="display:inline-block;
padding:12px 28px;
font-size:15px;
color:#ffffff;
text-decoration:none;
font-weight:bold;">
Đăng nhập ngay
</a>
</td>
</tr>
</table>
<p style="margin:25px 0 0 0;">
Trân trọng,<br/>
<strong>Đội ngũ Utopia</strong>
</p>
</td>
</tr>
<tr>
<td align="center"
style="padding:20px; font-size:12px; color:#777777; border-top:1px solid #eeeeee;">
© ${new Date().getFullYear()} Utopia. All rights reserved.<br/>
Đây là email tự động, vui lòng không phản hồi email này.
</td>
</tr>
</table>
</td>
</tr>
</table>
`;
let info = {
subject: this.dealer
? `${this.$mode === 'dev' ? '[DEV] ' : ''}Thông báo khởi tạo tài khoản Cổng thông tin Đại lý Utopia`
: `${this.$mode === 'dev' ? '[DEV] ' : ''}Thông báo khởi tạo tài khoản Cổng thông tin Chủ đầu tư Utopia`,
to: this.email,
sender: 1,
content: content,
};
await this.$insertapi('sendemail', info, undefined, false);
},
selected(attr, obj) {
this.option = obj;
},

View File

@@ -3,12 +3,12 @@
<div class="field is-horizontal">
<div class="field-body columns">
<div class="field column">
<label class="label">{{ isVietnamese ? 'Tên tài khoản' : 'Username' }}</label>
<label class="label">{{ isVietnamese ? 'Tên đăng nhập' : 'Username' }}</label>
<div class="control">
<p>{{ props.row.username }}</p>
<p>{{ props.row?.user__username ? props.row.user__username : props.row.username }}</p>
</div>
</div>
<div class="field column">
<div class="field column" v-if="props.row?.user__type !== 3">
<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>
@@ -19,15 +19,15 @@
<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">{{props.row?.user__fullname ? isVietnamese ? 'Tên tài khoản' : 'Full name': isVietnamese ? 'Họ tên' : 'Full name' }}</label>
<div class="control">
<p>{{ props.row.fullname }}</p>
<p>{{ props.row?.user__fullname ? props.row.user__fullname : props.row.fullname }}</p>
</div>
</div>
<div class="field column">
<label class="label">Email</label>
<div class="control">
<p>{{ props.row.email }}</p>
<p>{{ props.row?.user__email ? props.row.user__email : props.row.email }}</p>
</div>
</div>
</div>
@@ -41,7 +41,8 @@
</div>
</template>
<script setup>
const { $store, $id, $insertapi, $getdata, $getpath, $updateapi, $dialog, $snackbar, $isVietnamese } = useNuxtApp();
const { $store, $id, $insertapi, $getdata, $getpath, $updateapi, $dialog, $snackbar, $isVietnamese, $mode } =
useNuxtApp();
const emit = defineEmits(['close']);
var props = defineProps({
row: Object,
@@ -58,28 +59,29 @@ 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?.user__type === 3 ? props.row.user__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');
} 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>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',
to: props.row.email,
sender: 1,
content: content,
};
let rs = await $insertapi('sendemail', info, null, false);
if (user.type === 3) {
let loginUrl = $mode === 'dev' ? 'https://dev.dealer.utopia.com.vn/' : 'https://dealer.utopia.com.vn/';
await sendEmailAlter(loginUrl, user.fullname, user.username, pass, user.email, user.type);
} else {
let loginUrl = $mode === 'dev' ? 'https://dev.biz.utopia.com.vn/' : 'https://biz.utopia.com.vn/';
await sendEmailAlter(loginUrl, user.fullname, user.username, pass, user.email, user.type);
}
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ý.',
@@ -98,7 +100,7 @@ function showConfirm() {
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?`,
content: `Bạn có muốn đặt lại mật khẩu cho tài khoản ${(props.row?.user__username ? props.row.user__username : props.row.username)?.toUpperCase()} này không?`,
duration: 10,
},
onConfirm: async () => {
@@ -106,4 +108,79 @@ function showConfirm() {
},
};
}
async function sendEmailAlter(loginUrl, fullname, username, password, email, dealer) {
let content = `
<table width="100%" bgcolor="#f4f6f8" cellpadding="0" cellspacing="0">
<tr>
<td align="center" style="padding:30px 15px;">
<table width="600" cellpadding="0" cellspacing="0" border="0"
style="background:#ffffff; font-family:Arial, Helvetica, sans-serif; color:#333333; border-collapse:collapse;">
<tr>
<td style="padding:30px 25px; font-size:15px; line-height:1.6;">
<p style="margin:0 0 15px 0;">
Xin chào <strong>${fullname}</strong>,
</p>
<p style="margin:0 0 15px 0;">
Chúng tôi đã đặt lại mật khẩu cho tài khoản của bạn.
</p>
<table width="100%" cellpadding="0" cellspacing="0" border="0" style="margin:15px 0;">
<tr>
<td width="120" style="padding:6px 0;"><strong>Username:</strong></td>
<td style="padding:6px 0;">${username}</td>
</tr>
<tr>
<td style="padding:6px 0;"><strong>Password:</strong></td>
<td style="padding:6px 0;">${password}</td>
</tr>
</table>
<table cellpadding="0" cellspacing="0" border="0" align="center" style="margin:25px auto;">
<tr>
<td align="center" bgcolor="#2f6fed" style="border-radius:4px;">
<a href="${loginUrl}"
target="_blank"
style="display:inline-block;
padding:12px 28px;
font-size:15px;
color:#ffffff;
text-decoration:none;
font-weight:bold;">
Đăng nhập ngay
</a>
</td>
</tr>
</table>
<p style="margin:25px 0 0 0;">
Trân trọng,<br/>
<strong>Đội ngũ Utopia</strong>
</p>
</td>
</tr>
<tr>
<td align="center"
style="padding:20px; font-size:12px; color:#777777; border-top:1px solid #eeeeee;">
© ${new Date().getFullYear()} Utopia. All rights reserved.<br/>
Đây là email tự động, vui lòng không phản hồi email này.
</td>
</tr>
</table>
</td>
</tr>
</table>
`;
let info = {
subject:
dealer === 3
? `${$mode === 'dev' ? '[DEV] ' : ''}Thông báo đặt lại mật khẩu thành công Cổng thông tin Đại lý Utopia`
: `${$mode === 'dev' ? '[DEV] ' : ''}Thông báo đặt lại mật khẩu thành công Cổng thông tin Chủ đầu tư Utopia`,
to: email,
sender: 1,
content: content,
};
await $insertapi('sendemail', info, undefined, false);
}
</script>