在ember js和mvc中使用验证码 [英] Using captcha in ember js and mvc
问题描述
我正在使用 ember.js
和 asp.net mvc
创建一个网站。在我以前的 asp.net
网站中,我使用了 captchaMVC
( http://captchamvc.codeplex.com/ )。但是,我不知道如何使用Ember。 Google搜索对我来说并没有太大的帮助。
任何人都可以指出我正确的方向,以便如何使用Ember? c codeaptchaMVC $>
在reCaptcha中,挑战请求流(在用户代理和reCaptcha挑战资源服务器之间)和用户响应验证流程(通常在您的后端应用程序服务器和reCaptcha验证API服务器)由各种插件进行处理,抽象此过程为您,并让您仅在前端和后端处理其结果。
另一方面,Ember是一个客户端应用程序不应该处理验证步骤不要暴露您的私人reCaptcha密钥以及其他参数。
由于这些事实,我发现更容易构建reCaptcha支持手动而不是依赖于一个特定的插件。 Google显示reCAPTCHA无插件页面介绍DIY流程。
我使用ember-cli,所以 bower install recaptcha-ajax --save
或者在bower.json中配置它来指向Google的recaptcha-ajax .js直接然后将其导入Brocfile。
在您看来,您可以定位特定元素,如:
<从ember导入Ember pre>
导出默认值Ember.View.extend({
didInsertElement:function(){
Recaptcha.create(your_public_key,'element_id',{
theme: red
回调:Recaptcha.focus_response_field
});
}
});
在您的模板中,只需嵌入您的 element_id元素
从上面到您的表单元素:
< form action =method =post>
< div id =element_id>< / div>
< / form>
,不要忘记在.jshintrc文件中排除Recaptcha:
{
code> recaptcha_response_field 它必须用于构建一个
predef:{
Recaptcha:true
}
}
现在您的后端表单处理程序将收到recaptcha_challenge_field
和POST
请求到 http://www.google.com/recaptcha/api/verify ,您必须根据 Google的reCaptcha验证流程文档。I'm creating a site using
ember.js
andasp.net mvc
. In my previousasp.net
sites, I've usedcaptchaMVC
(http://captchamvc.codeplex.com/). But, I can't figure out how to use it with Ember. Google searches haven't been very helpful for me.Can anyone point me in the right direction for how to use
captchaMVC
with Ember?解决方案In reCaptcha the challenge request flow (between the user-agent and the reCaptcha challenge resource server) and user response verification flow (typically between your back-end application server and the reCaptcha Verification API server) are handled by a variety of plugins that abstract this process for you and leave you to deal with its outcome only, both on the front-end and back-end side.
Ember, on the other hand, is a client-side application that should not handle the verification step not to expose your Private reCaptcha Key, amongst other parameters.
Due to these facts, I find it easier to build reCaptcha support manually rather than depend on a specific plugin. Google's Displaying reCAPTCHA Without Plugins page describes the DIY process well.
I use ember-cli, so
bower install recaptcha-ajax --save
or configure it in bower.json to point to Google's recaptcha-ajax.js directly then import it in Brocfile.In your view, you can target a specific element like so:
import Ember from 'ember'; export default Ember.View.extend({ didInsertElement: function() { Recaptcha.create("your_public_key", 'element_id', { theme: "red" callback: Recaptcha.focus_response_field }); } });
In your template, simply embed your this element of
element_id
from above into your form element:<form action="" method="post"> <div id="element_id"></div> </form>
and don't forget to exclude Recaptcha in your .jshintrc file:
{ "predef": { "Recaptcha": true } }
now your back-end form handler will receive
recaptcha_challenge_field
andrecaptcha_response_field
which it has to use in constructing aPOST
request to http://www.google.com/recaptcha/api/verify and you'll have to set a few other params as per the Google's reCaptcha Verification Flow Document.这篇关于在ember js和mvc中使用验证码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!