Skip to content

Commit

Permalink
✨ feat: add captcha before send email
Browse files Browse the repository at this point in the history
  • Loading branch information
xytoki committed Nov 16, 2023
1 parent f4b2ec1 commit 2d82427
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/App.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<template>
<router-view />
<scriptx src="https://static.geetest.com/v4/gt4.js"></scriptx>
</template>
<script>
import '@/style/theme.scss'
Expand Down
1 change: 1 addition & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ declare global {
$cocogoat: CocogoatGlobal<TypeApp>
dataLayer: unknown[]
gtag: (...args: unknown[]) => void
initGeetest4: (...args: unknown[]) => any

Check warning on line 45 in src/main.ts

View workflow job for this annotation

GitHub Actions / Build

Unexpected any. Specify a different type
}
}

Expand Down
36 changes: 34 additions & 2 deletions src/store/providers/cocogoat/Install.vue
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ import {
faBomb,
} from '@fortawesome/free-solid-svg-icons'
import { ElMessageBox } from 'element-plus'
import { computed, defineComponent, onBeforeUnmount, ref } from 'vue'
import { computed, defineComponent, onBeforeUnmount, onMounted, ref } from 'vue'
library.add(faAngleRight, faEnvelopeOpenText, faCheckCircle, faCircleNotch, faBomb)
export const name = '椰羊云同步'
export default defineComponent({
Expand All @@ -66,6 +66,30 @@ export default defineComponent({
},
emits: ['submit'],
setup(props, { emit }) {
let gtObj: any

Check warning on line 69 in src/store/providers/cocogoat/Install.vue

View workflow job for this annotation

GitHub Actions / Build

Unexpected any. Specify a different type
let gtOnSucc = () => {}

Check failure on line 70 in src/store/providers/cocogoat/Install.vue

View workflow job for this annotation

GitHub Actions / Build

Unexpected empty arrow function

Check failure on line 70 in src/store/providers/cocogoat/Install.vue

View workflow job for this annotation

GitHub Actions / Build

Unexpected empty arrow function
const step = ref(1)
onMounted(() => {
window.initGeetest4(
{
captchaId: '2c9c8579b5bc9d3771a03e7939ac0c66',
product: 'bind',
},
function (captchaObj: any) {

Check warning on line 78 in src/store/providers/cocogoat/Install.vue

View workflow job for this annotation

GitHub Actions / Build

Unexpected any. Specify a different type
captchaObj
.onReady(function () {
gtObj = captchaObj
})
.onSuccess(function () {
gtOnSucc()
gtOnSucc = () => {}

Check failure on line 85 in src/store/providers/cocogoat/Install.vue

View workflow job for this annotation

GitHub Actions / Build

Unexpected empty arrow function

Check failure on line 85 in src/store/providers/cocogoat/Install.vue

View workflow job for this annotation

GitHub Actions / Build

Unexpected empty arrow function
})
.onClose(function () {
step.value = 1
})
},
)
})
let intervalId = 0 as unknown as ReturnType<typeof setTimeout>
onBeforeUnmount(() => {
intervalId && clearTimeout(intervalId)
Expand All @@ -74,7 +98,6 @@ export default defineComponent({
onBeforeUnmount(() => {
destroyed = true
})
const step = ref(1)
const mail = ref('')
const isMail = computed(() => {
// 正则判断是否邮件地址
Expand All @@ -88,13 +111,22 @@ export default defineComponent({
const submitMail = async () => {
if (!isMail.value) return
step.value = 2
let gtres = null
if (gtObj) {
gtObj.showCaptcha()
await new Promise<void>((resolve) => {
gtOnSucc = resolve
})
gtres = gtObj.getValidate()
}
const res = await fetch(await apibase('/v2/lumine'), {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
email: mail.value,
gt: gtres,
}),
})
if (!res.ok || res.headers.get('content-type') !== 'application/json') {
Expand Down

0 comments on commit 2d82427

Please sign in to comment.