From e7e8f0b38a97b5afcd655204789f733821b040f3 Mon Sep 17 00:00:00 2001
From: ThienPhamVan
Date: Wed, 25 Mar 2026 16:03:35 +0700
Subject: [PATCH] Update validate data
---
pages/signin.vue | 85 ++++++++++++++++++++-----------------------
pages/signup.vue | 71 +++++++++++-------------------------
plugins/common.js | 92 +++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 150 insertions(+), 98 deletions(-)
diff --git a/pages/signin.vue b/pages/signin.vue
index 7f6b62a..b082bbb 100644
--- a/pages/signin.vue
+++ b/pages/signin.vue
@@ -18,6 +18,7 @@
placeholder="Nhập email"
v-model="email"
@blur="validateEmail(email)"
+ @keyup.enter="signin()"
/>
@@ -59,7 +61,9 @@
@@ -168,13 +172,9 @@ export default {
account: undefined,
company: this.$companyInfo(),
isVietnamese: true,
+ isLoading: false,
};
},
- mounted() {
- window.addEventListener('keyup', (ev) =>
- ev.key === 'Enter' && this.$route.name === 'signup' ? this.signin() : false,
- );
- },
watch: {
isLoaded: function (newVal) {
if (this.isLoaded) {
@@ -262,50 +262,36 @@ export default {
// Xóa lỗi cũ
this.errors = this.errors.filter((err) => err.name !== 'email');
- if (this.$empty(email)) {
+ const res = this.$validateEmail(email);
+
+ if (!res.status) {
this.errors.push({
name: 'email',
- text: 'Email không được để trống.',
+ text: res.message,
});
- return false;
}
-
- if (!this.$regexEmail(String(email).toLowerCase())) {
- this.errors.push({
- name: 'email',
- text: 'Email không đúng định dạng.',
- });
- return false;
- }
-
- return true;
},
validatePassword(password) {
// Xóa lỗi cũ
this.errors = this.errors.filter((err) => err.name !== 'password');
- if (this.$empty(password)) {
+ const res = this.$validatePassword(password);
+
+ if (!res.status) {
this.errors.push({
name: 'password',
- text: 'Mật khẩu không được để trống.',
+ text: res.message,
});
- return false;
}
-
- if (!this.$regexPassword(String(password).toLowerCase())) {
- this.errors.push({
- name: 'password',
- text: 'Mật khẩu không đúng định dạng.',
- });
- return false;
- }
-
- return true;
},
async signin() {
- if (this.checkError()) return;
+ this.isLoading = true;
+ if (this.checkError()) {
+ this.isLoading = false;
+ return;
+ }
let conn = this.$findapi('login');
conn.params.filter = { email: this.email, password: this.password };
let result = await this.$getapi([conn]);
@@ -358,8 +344,6 @@ export default {
}
},
invalidLogin(data) {
- console.log('login', data);
-
if (!data) {
const text = 'Tài khoản hoặc mật khẩu không chính xác';
this.errors.push({ name: 'email', text: text });
@@ -375,18 +359,20 @@ export default {
return this.errors.length > 0 ? true : false;
},
async fillData(data) {
- if (this.invalidLogin(data)) return;
+ this.isLoading = true;
+ if (this.invalidLogin(data)) {
+ this.isLoaded = false;
+ this.isLoading = false;
+ return;
+ }
+ //check permision
+ if (this.module !== 'website') {
+ let userapps = await this.$getdata('userapps', { user: data.id, apps__code: this.module }, undefined, true);
+ if (!userapps) return this.$router.push('/welcome');
+ }
this.login = data; //store login
- if (data.type === 1 || data.type__code === 'customer') {
- this.redirectUrl();
- } else if (this.$store.state.link) {
+ if (this.$store.state.link) {
let ele = this.$copy(data);
- if (
- this.$store.state.link.indexOf('bigdatatech.vn') < 0 &&
- this.$store.state.link.indexOf('localhost:3000') < 0
- ) {
- return this.$redirectWeb(ele);
- }
//get token & redirect link
const browser = Bowser.getParser(window.navigator.userAgent);
let obj = {
@@ -399,8 +385,13 @@ export default {
};
ele.token = obj.token;
await this.$insertapi('authtoken', obj);
- //await this.sendNoti(obj)
- this.$redirectWeb(ele);
+ let link = this.$store.state.link;
+ if (data.type === 3 && link.indexOf('y99') >= 0) {
+ link = link.indexOf('dev') >= 0 ? '' : '';
+ }
+ let href = `${link}?username=${ele.username}&token=${ele.token}&fullname=${ele.fullname}&userid=${ele.id}`;
+ if (ele.avatar) href = `${href}&avatar=${ele.avatar}`;
+ window.location.href = href;
} else this.redirectUrl();
},
async sendNoti(obj) {
diff --git a/pages/signup.vue b/pages/signup.vue
index 6e57120..a1f7a05 100644
--- a/pages/signup.vue
+++ b/pages/signup.vue
@@ -339,85 +339,56 @@ export default {
// Xóa lỗi cũ
this.errors = this.errors.filter((err) => err.name !== 'fullname');
- if (this.$empty(fullName)) {
+ const res = this.$validateFullName(fullName);
+
+ if (!res.status) {
this.errors.push({
name: 'fullname',
- text: 'Họ và tên không được để trống.',
+ text: res.message,
});
- return false;
}
-
- if (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.',
- });
- return false;
- }
-
- return true;
},
validateEmail(email) {
// Xóa lỗi cũ
this.errors = this.errors.filter((err) => err.name !== 'email');
- if (this.$empty(email)) {
+ const res = this.$validateEmail(email);
+
+ if (!res.status) {
this.errors.push({
name: 'email',
- text: 'Email không được để trống.',
+ text: res.message,
});
- return false;
}
-
- if (!this.$regexEmail(String(email).toLowerCase())) {
- this.errors.push({
- name: 'email',
- text: 'Email không đúng định dạng.',
- });
- return false;
- }
-
- return true;
},
validatePassword(password) {
// Xóa lỗi cũ
this.errors = this.errors.filter((err) => err.name !== 'password');
- if (this.$empty(password)) {
+ const res = this.$validatePassword(password);
+
+ if (!res.status) {
this.errors.push({
name: 'password',
- text: 'Mật khẩu không được để trống.',
+ text: res.message,
});
- return false;
}
-
- if (!this.$regexPassword(String(password).toLowerCase())) {
- this.errors.push({
- name: 'password',
- text: 'Mật khẩu không đúng định dạng.',
- });
- return false;
- }
-
- return true;
},
validatePhone(phone) {
// Xóa lỗi cũ
this.errors = this.errors.filter((err) => err.name !== 'phone');
- if (!this.$empty(phone)) {
- if (!this.$regexPhone(phone)) {
- this.errors.push({
- name: 'phone',
- text: 'Số điện thoại không hợp lệ.',
- });
- return false;
- }
- }
- return true;
+ const res = this.$validatePhone(phone, true);
+
+ if (!res.status) {
+ this.errors.push({
+ name: 'phone',
+ text: res.message,
+ });
+ }
},
async createAccount() {
@@ -497,8 +468,6 @@ export default {
},
onSuccess(googleUser) {
let info = googleUser.getBasicProfile();
- console.log('Google info', info);
-
let keys = Object.keys(info);
this.email = info[keys[5]];
this.fullname = info[keys[1]];
diff --git a/plugins/common.js b/plugins/common.js
index 8ebf498..50eff09 100644
--- a/plugins/common.js
+++ b/plugins/common.js
@@ -297,5 +297,97 @@ Vue.use({
const regexFullName = /^[A-Za-zÀ-ỹ]+(\s[A-Za-zÀ-ỹ]+)+$/;
return regexFullName.test(fullName);
};
+
+ Vue.prototype.$validateEmail = function (email, isNull = false) {
+ const value = (email || '').trim().toLowerCase();
+
+ if (!isNull && !value) {
+ return {
+ status: false,
+ message: 'Email không được bỏ trống.',
+ };
+ }
+
+ if (value && !this.$regexEmail(value)) {
+ return {
+ status: false,
+ message: 'Email không hợp lệ. Vui lòng nhập đúng định dạng (ví dụ: ex@gmail.com).',
+ };
+ }
+
+ return {
+ status: true,
+ message: '',
+ };
+ };
+
+ Vue.prototype.$validatePassword = function (password, isNull = false) {
+ const value = (password || '').trim();
+
+ if (!isNull && !value) {
+ return {
+ status: false,
+ message: 'Mật khẩu không được bỏ trống.',
+ };
+ }
+
+ if (value && !this.$regexPassword(value)) {
+ return {
+ status: false,
+ message: 'Mật khẩu không hợp lệ. Phải có ít nhất 8 ký tự, bao gồm chữ hoa, chữ thường, số và ký tự đặc biệt.',
+ };
+ }
+
+ return {
+ status: true,
+ message: '',
+ };
+ };
+
+ Vue.prototype.$validatePhone = function (phone, isNull = false) {
+ const value = (phone || '').trim();
+
+ if (!isNull && !value) {
+ return {
+ status: false,
+ message: 'Số điện thoại không được bỏ trống.',
+ };
+ }
+
+ if (value && !this.$regexPhone(value)) {
+ return {
+ status: false,
+ message: 'Số điện thoại không hợp lệ. Vui lòng nhập số điện thoại Việt Nam hợp lệ (ví dụ: 0912345678).',
+ };
+ }
+
+ return {
+ status: true,
+ message: '',
+ };
+ };
+
+ Vue.prototype.$validateFullName = function (fullName, isNull = false) {
+ const value = (fullName || '').trim();
+
+ if (!isNull && !value) {
+ return {
+ status: false,
+ message: 'Họ và tên không được bỏ trống.',
+ };
+ }
+
+ if (value && !this.$regexFullName(value)) {
+ return {
+ status: false,
+ message: 'Họ và tên không hợp lệ. Vui lòng nhập họ và tên đầy đủ.',
+ };
+ }
+
+ return {
+ status: true,
+ message: '',
+ };
+ };
},
});