Skip to content

Commit

Permalink
[+] Remove unnecessary logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Muska-Ami committed Jan 13, 2025
1 parent bf98f08 commit da98d89
Show file tree
Hide file tree
Showing 6 changed files with 130 additions and 15 deletions.
11 changes: 10 additions & 1 deletion components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,18 @@ declare module 'vue' {
NButton: typeof import('naive-ui')['NButton']
NCard: typeof import('naive-ui')['NCard']
NCode: typeof import('naive-ui')['NCode']
NCollapse: typeof import('naive-ui')['NCollapse']
NCollapseItem: typeof import('naive-ui')['NCollapseItem']
NDivider: typeof import('naive-ui')['NDivider']
NDrawer: typeof import('naive-ui')['NDrawer']
NDrawerContent: typeof import('naive-ui')['NDrawerContent']
NEl: typeof import('naive-ui')['NEl']
NEllipsis: typeof import('naive-ui')['NEllipsis']
NEmpty: typeof import('naive-ui')['NEmpty']
NForm: typeof import('naive-ui')['NForm']
NFormItem: typeof import('naive-ui')['NFormItem']
NGi: typeof import('naive-ui')['NGi']
NGradientText: typeof import('naive-ui')['NGradientText']
NGrid: typeof import('naive-ui')['NGrid']
NGridItem: typeof import('naive-ui')['NGridItem']
NH1: typeof import('naive-ui')['NH1']
Expand All @@ -31,33 +35,38 @@ declare module 'vue' {
NH4: typeof import('naive-ui')['NH4']
NH5: typeof import('naive-ui')['NH5']
NIcon: typeof import('naive-ui')['NIcon']
NImage: typeof import('naive-ui')['NImage']
NInput: typeof import('naive-ui')['NInput']
NLayout: typeof import('naive-ui')['NLayout']
NLayoutContent: typeof import('naive-ui')['NLayoutContent']
NLayoutHeader: typeof import('naive-ui')['NLayoutHeader']
NLayoutSider: typeof import('naive-ui')['NLayoutSider']
NLi: typeof import('naive-ui')['NLi']
NList: typeof import('naive-ui')['NList']
NListItem: typeof import('naive-ui')['NListItem']
NMenu: typeof import('naive-ui')['NMenu']
NModal: typeof import('naive-ui')['NModal']
NNumberAnimation: typeof import('naive-ui')['NNumberAnimation']
NP: typeof import('naive-ui')['NP']
NQrCode: typeof import('naive-ui')['NQrCode']
NRadio: typeof import('naive-ui')['NRadio']
NRadioButton: typeof import('naive-ui')['NRadioButton']
NRadioGroup: typeof import('naive-ui')['NRadioGroup']
NScrollbar: typeof import('naive-ui')['NScrollbar']
NSelect: typeof import('naive-ui')['NSelect']
NSkeleton: typeof import('naive-ui')['NSkeleton']
NSpace: typeof import('naive-ui')['NSpace']
NSpin: typeof import('naive-ui')['NSpin']
NStatistic: typeof import('naive-ui')['NStatistic']
NStep: typeof import('naive-ui')['NStep']
NSteps: typeof import('naive-ui')['NSteps']
NTab: typeof import('naive-ui')['NTab']
NTabPane: typeof import('naive-ui')['NTabPane']
NTabs: typeof import('naive-ui')['NTabs']
NTag: typeof import('naive-ui')['NTag']
NText: typeof import('naive-ui')['NText']
NThing: typeof import('naive-ui')['NThing']
NTooltip: typeof import('naive-ui')['NTooltip']
NUl: typeof import('naive-ui')['NUl']
RouterLink: typeof import('vue-router')['RouterLink']
RouterView: typeof import('vue-router')['RouterView']
TheDialog: typeof import('./src/components/TheDialog.vue')['default']
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
"format": "prettier --write src/"
},
"dependencies": {
"@chongying-star/vaptcha-typescript": "^1.1.0",
"@chongying-star/vue-vaptcha": "^1.0.0-beta.1",
"@vicons/carbon": "^0.13.0",
"@vicons/fa": "^0.12.0",
"@vicons/fluent": "^0.12.0",
Expand Down Expand Up @@ -56,7 +58,7 @@
"naive-ui": "2.38.2",
"vfonts": "^0.1.0",
"typescript": "~5.6.3",
"vite": "^6.0.5",
"vite": "^6.0.7",
"vite-plugin-vue-devtools": "^7.6.8",
"vue-tsc": "^2.1.10"
}
Expand Down
12 changes: 10 additions & 2 deletions src/api/v2/auth/login.api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,19 @@
import { post } from '@/utils/request'
import base from '@/api/base'

const login = async (username: number, password: string, captcha_response_token: string) => {
const login = async (
username: number,
password: string,
captcha_id: string,
captcha_token: string,
captcha_server: string | undefined
) => {
const rs = post(`${base.api_v2_url}/auth/login`, {
username: username,
password: password,
captcha_response_token: captcha_response_token
captcha_id: captcha_id,
captcha_token: captcha_token,
captcha_server: captcha_server
})
return base.buildResponse(await rs)
}
Expand Down
12 changes: 12 additions & 0 deletions src/api/v2/captcha.api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import base from '@/api/base'
//@ts-ignore
import { get, post } from '@/utils/request'

const captcha = async (action: string) => {
const rs = get(`${base.api_v2_url}/captcha`, {
action: action
})
return base.buildResponse(await rs)
}

export default captcha
4 changes: 3 additions & 1 deletion src/api/v2/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import email from './email'
import notice from './notice'
import minecraft from './minecraft'
import app from './app'
import captcha from './captcha.api'

export default {
user: user,
Expand All @@ -23,5 +24,6 @@ export default {
icp: icp,
notice: notice,
minecraft: minecraft,
app: app
app: app,
captcha: captcha
}
102 changes: 92 additions & 10 deletions src/views/auth/LoginView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@
type="text"
v-model:value="model.username"
placeholder="用户名"
@keyup.enter="showTurnstile = true"
@keyup.enter="loadCaptcha"
/>
</n-form-item>
<n-form-item label="密码" path="password">
<n-input
type="password"
v-model:value="model.password"
placeholder="密码"
@keyup.enter="showTurnstile = true"
@keyup.enter="loadCaptcha"
/>
</n-form-item>
<div>
Expand All @@ -43,7 +43,7 @@
>
没有账户?去注册
</n-button>
<n-button type="primary" @click="showTurnstile = true"> 登录</n-button>
<n-button type="primary" @click="loadCaptcha"> 登录</n-button>
<!-- Turnstile -->
<n-modal
v-model:show="showTurnstile"
Expand All @@ -54,7 +54,7 @@
>
<vue-turnstile
site-key="0x4AAAAAAAEXAhvwOKerpBsb"
v-model="token"
v-model="turnstileToken"
@error="
(code) => {
if (`${code}`.startsWith('200')) {
Expand All @@ -76,6 +76,20 @@
"
/>
</n-modal>
<n-modal
v-model:show="showVAPTCHA"
:mask-closable="false"
preset="card"
title="请完成人机验证"
style="min-width: 300px; width: min-content"
>
<vaptcha-button
v-model="vaptchaToken"
v-model:server="vaptchaServer"
v-model:scene="vaptchaScene"
vid="67813e52dc0ff12924d9b311"
></vaptcha-button>
</n-modal>
</n-space>
</n-space>
</div>
Expand All @@ -94,7 +108,10 @@ import Notification from '@/utils/notification'
import logger from '@/utils/logger'
import api from '@/api'
import { getUrlKey } from '@/utils/request'
import VueTurnstile from 'vue-turnstile'
import '@chongying-star/vue-vaptcha/style.css'
import { VaptchaButton } from '@chongying-star/vue-vaptcha'
const message = new Message()
const notification = new Notification()
Expand All @@ -104,8 +121,13 @@ const ldb = useLoadingBar()
const qqLoginLoading = ref(false)
// const oauthLogin_loading = ref(false)
let token = ref('')
let showTurnstile = ref(false)
let captchaPreData,
showTurnstile = ref(false),
showVAPTCHA = ref(false)
let turnstileToken = ref('')
let vaptchaToken = ref(''),
vaptchaServer = ref(''),
vaptchaScene = 0
const model = ref([
{
Expand All @@ -122,13 +144,67 @@ if (redirectQuery !== null) {
logger.info('Redirect after login: ' + redirect)
}
watch(token, (newToken, _) => {
watch(turnstileToken, (newToken, _) => {
showTurnstile.value = false
login(newToken)
login({
id: captchaPreData.id,
token: newToken
})
})
watch(vaptchaToken, (newToken, _) => {
showVAPTCHA.value = false
login({
id: captchaPreData.id,
token: newToken,
server: vaptchaServer.value
})
})
let vaptchaInserted = false
async function loadCaptcha() {
ldb.start()
let rs
try {
rs = await api.v2.captcha('login')
} catch (e) {
message.error('请求验证码数据失败:' + e)
logger.error(e)
ldb.error()
}
if (rs.status === 200) {
captchaPreData = {
id: rs.data.id,
type: rs.data.type
}
console.log(captchaPreData)
switch (rs.data.type) {
case 'turnstile':
showTurnstile.value = true
break
case 'vaptcha':
if (!vaptchaInserted) {
const script = document.createElement('script')
script.src = 'https://v-cn.vaptcha.com/v3.js'
document.head.appendChild(script)
script.onload = () => {
showVAPTCHA.value = true
}
vaptchaInserted = true
} else showVAPTCHA.value = true
break
default:
message.error('后端返回数据错误')
ldb.error()
}
} else {
message.error(rs.message)
ldb.error()
}
}
// 登录
async function login(turnstileToken) {
async function login(captchaData) {
ldb.start()
if (
model.value.username === null ||
Expand All @@ -142,7 +218,13 @@ async function login(turnstileToken) {
}
let rs
try {
rs = await api.v2.auth.login(model.value.username, model.value.password, turnstileToken)
rs = await api.v2.auth.login(
model.value.username,
model.value.password,
captchaData.id,
captchaData.token,
captchaData.server
)
} catch (e) {
message.error('请求失败: ' + e)
}
Expand Down

0 comments on commit da98d89

Please sign in to comment.