Update Account

This commit is contained in:
ThienPhamVan
2026-03-30 14:09:41 +07:00
parent e7e8f0b38a
commit e1b9d9c15d
11 changed files with 1029 additions and 280 deletions

View File

@@ -26,15 +26,6 @@
{{ errors.find((v) => v.name === 'fullname').text }}
</p>
</div>
<div class="field mt-4">
<label class="label">Điện thoại</label>
<div class="control">
<input class="input" type="text" placeholder="" v-model="phone" @blur="validatePhone(phone)" />
</div>
<p class="help is-danger" v-if="errors.find((v) => v.name === 'phone')">
{{ errors.find((v) => v.name === 'phone').text }}
</p>
</div>
<div class="field mt-4">
<label class="label">Email<b class="ml-1 has-text-danger">*</b></label>
<div class="control">
@@ -107,7 +98,9 @@
</p>
</div>
<div class="field mt-5 pt-1 group-action">
<button class="button is-primary" @click="createAccount()">Tạo tài khoản</button>
<button :class="['button', 'is-primary', isLoadingCreate && 'is-loading']" @click="createAccount()">
Tạo tài khoản
</button>
<!-- <a class="ml-2" @click="$router.push('/signin')">Đăng nhập</a> -->
</div>
</div>
@@ -191,6 +184,7 @@
<script>
import GoogleLogin from 'vue-google-login';
import sendVerificationEmail from '~/components/template/email';
export default {
components: { GoogleLogin },
head() {
@@ -221,6 +215,7 @@ export default {
validTo: this.$dayjs().add(30, 'day').format('DD/MM/YYYY'),
company: this.$companyInfo(),
isVietnamese: true,
isLoadingCreate: false,
};
},
async mounted() {
@@ -310,18 +305,7 @@ export default {
if (!this.$empty(this.email)) {
this.email = this.email.trim().toLowerCase();
}
// if (this.$empty(this.fullname)) {
// this.errors.push({ name: 'fullname', text: 'Họ và tên không được bỏ trống.' });
// } else if (this.fullname.length < 5) {
// this.errors.push({ name: 'fullname', text: 'Họ và tên quá ngắn. Yêu cầu từ 5 kí tự trở nên.' });
// }
// if (!this.$empty(this.phone)) {
// if (!this.$regexPhone(this.phone)) {
// this.errors.push({ name: 'phone', text: 'Số điện thoại không hợp lệ.' });
// }
// }
this.validateFullName(this.fullname);
this.validatePhone(this.phone);
this.validateEmail(this.email);
this.validatePassword(this.password);
@@ -377,26 +361,17 @@ export default {
}
},
validatePhone(phone) {
// Xóa lỗi cũ
this.errors = this.errors.filter((err) => err.name !== 'phone');
const res = this.$validatePhone(phone, true);
if (!res.status) {
this.errors.push({
name: 'phone',
text: res.message,
});
}
},
async createAccount() {
if (this.checkError()) return;
this.isLoadingCreate = true;
if (this.checkError()) {
this.isLoadingCreate = false;
return;
}
const userRes = await this.$getdata('user', { email: this.email });
const customerRes = await this.$getdata('customer', { email: this.email });
if (userRes.length > 0 || customerRes.length > 0) {
this.isLoadingCreate = false;
return this.errors.push({ name: 'email', text: 'Tài khoản đã tồn tại trong hệ thống.' });
}
@@ -407,6 +382,7 @@ export default {
let result = await this.$getapi([ele]);
let data = result.find((v) => v.name === 'user').data.rows;
if (data.length > 0) {
this.isLoadingCreate = false;
return this.errors.push({ name: 'email', text: 'Tài khoản đã tồn tại trong hệ thống.' });
}
@@ -436,6 +412,7 @@ export default {
this.user = await this.$insertapi('user', data);
const customer = await this.$insertapi('customer', { ...data, type: null });
this.isLoadingCreate = false;
if (this.user !== 'error' && customer != 'error') {
let text = 'Bạn đã đăng ký tài khoản thành công. Hệ thống tự động chuyển tới trang đăng nhập.';
if (this.status.code === 'wait')
@@ -446,24 +423,29 @@ export default {
this.code = this.$id();
let data = { user: this.user.id, code: this.code };
result = await this.$insertapi('userauth', data);
this.processAuth();
setTimeout(() => {
this.processAuth();
}, 6000);
} else this.$router.push({ path: '/signin' });
},
async processAuth() {
let query = this.$store.state.link ? { code: this.code, link: this.$store.state.link } : { code: this.code };
let query = this.$store.state.link
? { code: this.code, link: this.$store.state.link, id: this.user.id, email: this.email }
: { code: this.code, id: this.user.id, email: this.email };
let routeData = this.$router.resolve({ path: '/account/auth', query: query });
let path = window.location.origin + routeData.href;
let conn = this.$findapi('userauth');
conn.params.filter = { user: this.user.id };
let result = await this.$getapi([conn]);
let msg = result[0].data.rows[0].code;
msg = msg.replace('[1]', this.fullname);
msg = msg.replace('[2]', this.code);
msg = msg.replace('[3]', path);
const contentEmail = sendVerificationEmail(
this.fullname,
this.user.email,
this.code,
path
);
let data = { subject: 'Xác thực tài khoản BigDataTechCloud', content: contentEmail, to: this.user.email };
const resSendMail = await this.$insertapi('sendemail', data);
console.log('resSendMail', resSendMail);
let data = { subject: 'Xác thực tài khoản BigDataTechCloud', content: msg, to: this.user.email };
result = await this.$insertapi('sendemail', data);
this.$router.push({ path: '/account/auth', query: { id: this.user.id, email: this.email } });
},
onSuccess(googleUser) {
@@ -532,7 +514,7 @@ export default {
<style lang="scss">
.login-page {
background-color: #f0fdf4;
background-color: var(--bg-accent);
min-height: 100vh;
align-content: center;