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

View file

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

View file

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

View file

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

View file

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