首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >验证Nuxt中的reCaptcha v3是否正常工作

验证Nuxt中的reCaptcha v3是否正常工作
EN

Stack Overflow用户
提问于 2022-05-05 12:11:57
回答 1查看 362关注 0票数 1

我正在我的nuxt项目上安装@nuxtjs/recaptcha,这个项目是google reCaptcha V3。它看起来工作得很好,它总是从服务器返回success结果,如下所示。

代码语言:javascript
运行
复制
{success: true, challenge_ts: '2022-05-05T11:37:06Z', hostname: 'localhost', score: 0.9}

但我不确定这是否正确,因为挑战并没有出现。据我所知,中亚人道协调中心应该面临一个必须应对的挑战。但是为什么挑战不在这里出现呢?

也许它需要用某个事件处理程序来触发?但是在文档示例中,我没有看到任何与它相关的东西,或者我只是没有意识到这一点。

我可能错过了一些重要的事情,所以我需要你的帮助来解决它。

我的模板代码

代码语言:javascript
运行
复制
<template>
  <div class="container">
    <h1 align="center">SEND EMAIL TO US!</h1>

    <div class="layout">
      <form @submit.prevent="onSubmit">
        <div class="basic-info">
          <div class="name">
            <label for="">Name :</label>
            <b-form-input v-model="data.name" placeholder="Name"></b-form-input>

            <div v-if="validation.name" class="mt-2">
              <b-alert show variant="danger">{{ validation.name[0] }}</b-alert>
            </div>
          </div>
          <div class="email">
            <label for="">Email :</label>
            <b-form-input
              v-model="data.email"
              placeholder="Email"
            ></b-form-input>
            <div v-if="validation.email" class="mt-2">
              <b-alert show variant="danger">{{ validation.email[0] }}</b-alert>
            </div>
          </div>
          <div class="messege">
            <label for="">Messege :</label>
            <b-form-textarea
              id="textarea"
              v-model="data.messege"
              placeholder="Enter Messege..."
              rows="8"
              max-rows="8"
            ></b-form-textarea>
            <div v-if="validation.messege" class="mt-2">
              <b-alert show variant="danger">
                {{ validation.messege[0] }}
              </b-alert>
            </div>
          </div>

          <hr />
          <b-button type="submit" variant="outline-primary">
            SEND EMAIL
          </b-button>
          <hr />
          <b-alert v-model="alert" show :variant="variant">
            {{ result_messege }}
          </b-alert>
        </div>
      </form>
    </div>
  </div>
</template>

我的脚本代码

代码语言:javascript
运行
复制
<script>
export default {
  async mounted() {
    try {
      await this.$recaptcha.init()
    } catch (e) {
      console.log(e)
    }
  },
  methods: {
    async onSubmit() {
      try {
        this.loading = true

        // Start the verification process
        const response = await this.verifyCaptcha()

        console.log(response)

        // Display error message if verification was not successful
        if (!response.success) {
          this.$recaptcha.reset()
          this.loading = false
          this.errorStatus = true
          this.notificationMessage =
            'There was an error with your reCaptcha verification. Please try again.'
          return
        }

        // If verification was successful, send the message
        await this.sendMail()

        this.errorStatus = false
        this.notificationMessage =
          'Thank you for reaching out. We will get back to you as soon as possible'

        this.loading = false
        this.$recaptcha.reset()
      } catch (error) {
        this.loading = false
        console.log(error)
      }
    },

    async verifyCaptcha() {
      try {
        const token = await this.$recaptcha.execute()
        console.log(token)

        const response = await this.$axios.$post(
          `/captcha-api/siteverify?secret=${process.env.SECRET_KEY}&response=${token}`
        )

        return response
      } catch (error) {
        this.loading = false
        return error
      }
    },
  },
}
</script>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-05-05 12:43:38

这是完全正常的,这是v3的整个概念,你可以在这个视频中看到:https://youtu.be/tbvxFW4UJdU

更多细节也在这里:https://developers.google.com/recaptcha/docs/v3

在这里:https://www.google.com/recaptcha/about/

到目前为止,特性是这样的:不需要用户的任何交互,而是使用一些鼠标跟踪器/AI来知道它是否具有潜在的恶意。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72126970

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档