feat: rebuild login check

This commit is contained in:
KUN1007 2023-10-13 18:49:15 +08:00
parent ff9fdf17be
commit 453a3e6eb1
6 changed files with 99 additions and 65 deletions

View file

@ -14,6 +14,7 @@ import { resetRouter } from '@/router'
const { uid, name, moemoepoint } = storeToRefs(useKUNGalgameUserStore())
const router = useRouter()
const container = ref<HTMLElement>()
const routerRedirectTo = `/kungalgamer/${uid.value}/info`
@ -39,7 +40,7 @@ const logOut = async () => {
)
if (res) {
kungalgameStoreReset()
useRouter().push('/login')
router.push('/login')
resetRouter()
message('Logout successfully!', '登出成功', 'success')
}

View file

@ -111,11 +111,11 @@ const handleChangePassword = async () => {
<div class="password" v-else-if="!flag">
<div class="input">
<span>更改密码</span>
<input v-model="input.newPassword" type="text" />
<input v-model="input.newPassword" type="password" />
</div>
<div class="input">
<span>确认密码</span>
<input v-model="input.confirmPassword" type="text" />
<input v-model="input.confirmPassword" type="password" />
</div>
</div>
</Transition>

View file

@ -20,6 +20,7 @@ defineProps<{
user: UserInfo
}>()
const router = useRouter()
//
const email = ref('')
//
@ -114,7 +115,7 @@ const handleChangePassword = async () => {
if (res.code === 200) {
kungalgameStoreReset()
useRouter().push('/login')
router.push('/login')
resetRouter()
Message('Password change successfully!', '密码更改成功', 'success')
} else {
@ -131,6 +132,11 @@ onMounted(async () => {
Message('Get email failed!', '获取邮箱失败!', 'error')
}
})
//
const handleClickForgotPassword = () => {
router.push('/forgot')
}
</script>
<template>
@ -156,6 +162,7 @@ onMounted(async () => {
<button @click="handleResetEmail">确定更改邮箱</button>
</div>
</div>
<!-- 用户更改密码 -->
<div class="password">
<div class="title">更改密码:</div>
@ -176,6 +183,11 @@ onMounted(async () => {
<button @click="handleChangePassword">确定更改密码</button>
</div>
</div>
<!-- 忘记密码 -->
<span @click="handleClickForgotPassword" class="forget">
{{ $tm('login.login.forget') }}
</span>
</div>
</template>
@ -242,6 +254,18 @@ onMounted(async () => {
}
}
.password {
margin-bottom: 20px;
}
/* 忘记密码 */
.forget {
font-size: medium;
cursor: pointer;
text-decoration: none;
color: var(--kungalgame-blue-4);
}
@media (max-width: 700px) {
.article {
font-size: small;

View file

@ -6,92 +6,105 @@ import { useRouter } from 'vue-router'
import { useKUNGalgameMessageStore } from '@/store/modules/message'
import { storeToRefs } from 'pinia'
//
import message from '@/components/alert/Message'
import Message from '@/components/alert/Message'
//
import Settings from './Settings.vue'
// i18n
import { useI18n } from 'vue-i18n'
//
import { isValidEmail, isValidName, isValidPassword } from '@/utils/validate'
// i18n
import { useI18n } from 'vue-i18n'
const { tm } = useI18n()
const router = useRouter()
const { tm } = useI18n()
const info = useKUNGalgameMessageStore()
// 使 store
const { isShowCapture, isCaptureSuccessful } = storeToRefs(
useKUNGalgameMessageStore()
)
const router = useRouter()
const info = useKUNGalgameMessageStore()
const useStore = useKUNGalgameUserStore()
//
const loginForm = reactive({
name: '',
password: '',
})
const isEmptyInput = (): boolean => {
//
const checkUsername = (name: string) => {
//
if (!loginForm.name.trim()) {
if (!name.trim()) {
//
message('Username cannot be empty', '用户名不可为空', 'warn')
Message('Username cannot be empty', '用户名不可为空', 'warn')
return false
}
if (!loginForm.password.trim()) {
//
message('Password cannot be empty', '密码不可为空', 'warn')
if (!isValidName(name) && !isValidEmail(name)) {
//
info.info(tm('AlertInfo.login.invalidUsername'))
return false
}
return true
}
//
const isValidInput = (): boolean => {
// false
if (!isEmptyInput()) {
return false
}
if (!isValidName(loginForm.name) && !isValidEmail(loginForm.name)) {
//
info.info(tm('AlertInfo.login.invalidUsername'))
const checkPassword = (password: string) => {
if (!password.trim()) {
//
Message('Password cannot be empty', '密码不可为空', 'warn')
return false
}
//
if (!isValidPassword(loginForm.password)) {
if (!isValidPassword(password)) {
//
info.info(tm('AlertInfo.login.invalidPassword'))
return false
}
return true
}
const checkLogin = (
name: string,
password: string,
isCaptureSuccessful: boolean
) => {
//
if (!checkUsername(name) || !checkPassword(password)) {
return false
}
//
if (!isCaptureSuccessful) {
Message(
'Please click above to complete the human verification',
'请点击上方完成人机身份验证',
'warn'
)
return false
}
return true
}
//
const handleLogin = async () => {
//
if (!isValidInput()) {
return
}
//
if (!isCaptureSuccessful.value) {
message(
'Please click above to complete the human verification',
'请点击上方完成人机身份验证',
'warn'
// ,
const result = checkLogin(
loginForm.name,
loginForm.password,
isCaptureSuccessful.value
)
if (!result) {
return
}
//
const res = await useStore.login(loginForm)
const res = await useKUNGalgameUserStore().login(loginForm)
//
if (res.code === 200) {
router.push('/kun')
message(
Message(
'Login Successfully! Welcome to KUN Visual Novel ~ ',
'登陆成功!欢迎来到 鲲 Galgame ~ ',
'success',
@ -190,7 +203,7 @@ const handleClickForgotPassword = () => {
transition: 0.2s linear;
}
/* 获取验证码 */
/* 忘记密码 */
.forget {
cursor: pointer;
text-decoration: none;

View file

@ -33,7 +33,7 @@ const info = useKUNGalgameMessageStore()
const router = useRouter()
const isSendCode = ref(false)
import { registerFormItem } from './registerForm'
import { registerFormItem } from '../utils/registerForm'
const registerForm = reactive<Record<string, string>>({
name: '',
@ -97,7 +97,7 @@ const handleSendCode = () => {
isSendCode.value = true
}
const handleRegister = () => {
const handleRegister = async () => {
if (!isSendCode.value) {
message(
'Need to send an email verification code',
@ -126,25 +126,21 @@ const handleRegister = () => {
}
//
useKUNGalgameUserStore()
.register({
const res = await useKUNGalgameUserStore().register({
name: registerForm.name,
email: registerForm.email,
password: registerForm.password,
code: registerForm.code,
})
.then((res) => {
//
if (res.code === 200) {
router.push('/')
message('Register successfully!', '注册成功!', 'success')
info.info(tm('AlertInfo.login.success'))
} else {
message('Register failed!', '注册失败!', 'error')
}
})
.catch((error) => {
console.log(error)
})
}
</script>