【问题标题】:Using Captcha with Meteor's accounts-ui-bootstrap-3将 Captcha 与 Meteor 的 accounts-ui-bootstrap-3 一起使用
【发布时间】:2014-02-17 02:48:49
【问题描述】:

当使用 Meteor 包accounts-ui-bootstrap-3accounts-password 的组合时,我们如何包含Captcha 验证?

您如何将captchagenaccounts-ui 之类的包集成在一起?

【问题讨论】:

    标签: javascript meteor npm captcha


    【解决方案1】:

    直接使用 Google Recaptcha 实现了我自己的解决方案

    我做了什么

    1. 下载 Recaptcha .js 文件并放入lib
    2. 在我的html 页面中添加了<div id="recaptchaDiv"></div>
    3. 在客户端代码中添加

    Template.YOUR_TEMPLATE.rendered = function () { Recaptcha.create("YOUR_RECAPTCHA_KEY", "recaptchaDiv", { theme: "red", callback: Recaptcha.focus_response_field } ); };

    在服务器端我有一个方法:

    validateCaptcha: function(challenge, resp){
      var self = this;
      var ip = self.connection.clientAddress;
      var result = HTTP.post('http://www.google.com/recaptcha/api/verify', {params: {
        privatekey:"YOUR_PRIVATE_KEY",
        remoteip:ip,
        challenge:challenge,
        response:resp,
      }});
    
      if(result.statusCode === 200){
        if(result.content==="true\nsuccess")
          return "success";
    
        return "fail";
      }
    }
    

    然后当你验证表单时你调用这个方法

    Meteor.call("validateCaptcha",Recaptcha.get_challenge(),Recaptcha.get_response(),function(res){
            if(res=="ok"){
              console.log("it works")
            }else{
              Recaptcha.reload();
              console.log("wrong captacha")
            }
          });
    

    您可能需要更改包本身的一些代码以将其添加到accounts-ui

    希望对你有帮助

    【讨论】:

      猜你喜欢
      • 2015-12-24
      • 2013-08-09
      • 2013-07-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-11-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多