简体   繁体   English

如何通知客户端reCaptcha成功

[英]how to notify client that reCaptcha is successful

Hello i have simple form where i have google reCaptcha v2 and when user submits form i am validating recaptcha but i also send email to user inputted email and i need to send status 200 two times here is first time where i need to send it 您好,我有一个简单的表格,我有google reCaptcha v2,当用户提交表格时,我正在验证recaptcha,但我也向用户输入的电子邮件发送电子邮件,我需要发送状态200两次,这是我第一次需要发送状态

request(verifyURL, (err, res, body)=>{
        body = JSON.parse(body);
        if(body.success !== undefined && !body.success){
            return res.status(409).send({
                success: false,
                message: 'დადასტურება ვერ ვოხერხდა'
            })
        }
      return res.status(200).send({success: true})   
}) 

so if i send status code 200 and use return statement, won't it cause 因此,如果我发送状态码200并使用return语句,会不会导致

Can't set headers after they are sent 发送后无法设置标题

error? 错误? if it will how can i fix it? 如果它将如何解决?

Thank you! 谢谢!

You cannot send multiple response for a single request. 您不能为一个请求发送多个响应。 You can go with either: 1. Send the mail in the same controller, and when its done successfully, then only send the response back to client. 您可以选择以下两种方式之一:1.在同一控制器中发送邮件,成功完成后,仅将响应发送回客户端。 Your response will be based on both factors ie. 您的答复将基于两个因素,即。 captcha validation and email sent response or 2. if you don't wanna wait for the email process.. Just send response once your captcha is verified.. and keep the mail process execution in background. 验证码验证和电子邮件已发送响应, 或者 2.如果您不想等待电子邮件过程。.只要验证码验证后就发送响应..并在后台保持邮件过程的执行。 In this case you need to remove the return keyword or else your request will end there and mail process won't execute. 在这种情况下,您需要删除return关键字,否则您的请求将在那里结束并且邮件处理将不会执行。

However, I'll suggest you to go with the first approach. 但是,我建议您采用第一种方法。 Hope this helps :) 希望这可以帮助 :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在没有轮询的情况下通知我的JS客户端? - How to notify my JS client without polling? 如何将长任务完成通知HTTP客户端 - How to notify HTTP client of the completion of a long task 如何在nodejs中推送/通知客户端新数据? - How to push/notify client on new data in nodejs? 用户确认自己不是机器人后,如何获取recaptcha客户端验证参数g-recaptcha-response? - how to get recaptcha client verification parameter g-recaptcha-response after user confirms he is not a robot? 如果 recaptcha 成功,则启用回调按钮(Google recaptcha v2) - Enable button on callback if recaptcha successful (Google recaptcha v2) ReCaptcha 2.0:如果 recaptcha 成功,则在回调时启用提交按钮 - ReCaptcha 2.0: enable Submit button on callback if recaptcha successful ReCaptcha 2.0:如果重新验证成功,则在回调中启用“提交”按钮 - ReCaptcha 2.0: Enable 'Submit' button on callback if recaptcha successful 如何在客户端和服务器站点验证recaptcha - How to verify recaptcha on client side as well as server site 如何通知客户端浏览器有关服务器上的某些事件? - How to notify client's browser about some event on server? Paypal客户端REST:如何通知服务器? - Paypal client-side REST: how to notify server?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM