From 73e7319c4e80d4ed1dd2947cef2d5e1d1826ad34 Mon Sep 17 00:00:00 2001 From: KUN1007 Date: Tue, 31 Oct 2023 16:52:39 +0800 Subject: [PATCH] BUG: nginx 403 --- src/router/modules/home.ts | 2 + src/utils/validate.ts | 4 +- src/views/login/components/Register.vue | 63 ---------------------- src/views/login/utils/checkLogin.ts | 0 src/views/login/utils/checkRegister.ts | 71 +++++++++++++++++++++++++ 5 files changed, 75 insertions(+), 65 deletions(-) create mode 100644 src/views/login/utils/checkLogin.ts create mode 100644 src/views/login/utils/checkRegister.ts diff --git a/src/router/modules/home.ts b/src/router/modules/home.ts index 6a4b299d..9223038f 100644 --- a/src/router/modules/home.ts +++ b/src/router/modules/home.ts @@ -11,6 +11,8 @@ const index: RouteRecordRaw[] = [ { name: 'KUN', path: '', + // Try fix nginx slash + alias: '/', component: () => import('@/views/Home/KUNGalgameMainPage.vue'), meta: { title: 'home', diff --git a/src/utils/validate.ts b/src/utils/validate.ts index fb2d1bd9..8bb81153 100644 --- a/src/utils/validate.ts +++ b/src/utils/validate.ts @@ -17,9 +17,9 @@ export const isValidName = (name: string) => { return regex.test(name) } -// Regular expression to match a password of 6 to 17 characters, containing at least one letter and one number, and optionally including special characters \w!@#$%^&*()-+= +// Regular expression to match a password of 6 to 107 characters, containing at least one letter and one number, and optionally including special characters \w!@#$%^&*()-+= export const isValidPassword = (pwd: string) => { - const regex = /^(?=.*[a-zA-Z])(?=.*[0-9])[\w!@#$%^&*()-+=]{6,17}$/ + const regex = /^(?=.*[a-zA-Z])(?=.*[0-9])[\w!@#$%^&*()-+=]{6,107}$/ return regex.test(pwd) } diff --git a/src/views/login/components/Register.vue b/src/views/login/components/Register.vue index 1280fa75..d5a62e30 100644 --- a/src/views/login/components/Register.vue +++ b/src/views/login/components/Register.vue @@ -41,42 +41,6 @@ const registerForm = reactive>({ code: '', }) -// Check if the form fields are empty -const isEmptyInput = () => { - if (!registerForm.name.trim()) { - Message('Username cannot be empty!', '用户名不可为空!', 'warn') - return false - } else if (!registerForm.email.trim()) { - Message('Email cannot be empty!', '邮箱不可为空!', 'warn') - return false - } else if (!registerForm.password.trim()) { - Message('Password cannot be empty!', '密码不可为空!', 'warn') - return false - } else { - return true - } -} - -// Check if the form fields are valid -const isValidInput = (): boolean => { - if (!isEmptyInput()) { - return false - } - if (!isValidName(registerForm.name)) { - Message('Invalid username format!', '非法的用户名格式!', 'warn') - return false - } - if (!isValidEmail(registerForm.email)) { - Message('Invalid email format!', '非法的邮箱格式!', 'warn') - return false - } - if (!isValidPassword(registerForm.password)) { - Message('Invalid password format!', '非法的密码格式!', 'warn') - return false - } - return true -} - // Send verification code const handleSendCode = () => { // If the form is empty @@ -96,33 +60,6 @@ const handleSendCode = () => { } const handleRegister = async () => { - if (!isSendCode.value) { - Message( - 'Need to send an email verification code', - '需要发送邮箱验证码', - 'warn' - ) - return - } - - if (!registerForm.code.trim()) { - Message( - 'Email verification code cannot be empty', - '邮箱验证码不可为空', - 'warn' - ) - return - } - - if (!isValidMailConfirmCode(registerForm.code)) { - Message( - 'Invalid email verification code format!', - '非法的邮箱验证码格式!', - 'warn' - ) - return - } - // Execute registration logic, send a request, and validate the code on the backend const res = await useKUNGalgameUserStore().register({ name: registerForm.name, diff --git a/src/views/login/utils/checkLogin.ts b/src/views/login/utils/checkLogin.ts new file mode 100644 index 00000000..e69de29b diff --git a/src/views/login/utils/checkRegister.ts b/src/views/login/utils/checkRegister.ts new file mode 100644 index 00000000..d19becfb --- /dev/null +++ b/src/views/login/utils/checkRegister.ts @@ -0,0 +1,71 @@ +import Message from '@/components/alert/Message' +import { + isValidEmail, + isValidName, + isValidPassword, + isValidMailConfirmCode, +} from '@/utils/validate' +import i18n from '@/language/i18n' + +// Check if the form fields are valid +export const checkRegisterForm = ( + name: string, + email: string, + password: string +): boolean => { + if (!name.trim() || !email.trim() || !password.trim()) { + Message( + 'Username, email, password field cannot be empty!', + '用户名,邮箱,密码字段不可为空!', + 'warn' + ) + return false + } + + if (!isValidName(name)) { + Message('Invalid username format!', '非法的用户名格式!', 'warn') + return false + } + + if (!isValidEmail(email)) { + Message('Invalid email format!', '非法的邮箱格式!', 'warn') + return false + } + + if (!isValidPassword(password)) { + Message('Invalid password format!', '非法的密码格式!', 'warn') + return false + } + + return true +} + +// Check if the form fields are valid, on submit register form +export const checkRegisterFormSubmit = (isSendCode: boolean, code: string) => { + if (!isSendCode) { + Message( + 'Need to send an email verification code', + '需要发送邮箱验证码', + 'warn' + ) + return + } + + if (!code.trim()) { + Message( + 'Email verification code cannot be empty', + '邮箱验证码不可为空', + 'warn' + ) + return + } + + if (!isValidMailConfirmCode(code)) { + Message( + 'Invalid email verification code format!', + '非法的邮箱验证码格式!', + 'warn' + ) + return + } +}