我使用ember.js
和asp.net mvc
創建站點。在我之前的asp.net
網站中,我使用captchaMVC
(http://captchamvc.codeplex.com/)。但是,我無法弄清楚如何在Ember中使用它。谷歌搜索對我來說並不是很有幫助。在ember js和mvc中使用captcha
任何人都可以在正確的方向指出我如何使用Ember的captchaMVC
?
我使用ember.js
和asp.net mvc
創建站點。在我之前的asp.net
網站中,我使用captchaMVC
(http://captchamvc.codeplex.com/)。但是,我無法弄清楚如何在Ember中使用它。谷歌搜索對我來說並不是很有幫助。在ember js和mvc中使用captcha
任何人都可以在正確的方向指出我如何使用Ember的captchaMVC
?
重新驗證挑戰請求流(在用戶代理和reCaptcha挑戰資源服務器之間)和用戶響應驗證流程(通常在您的後端應用程序服務器和reCaptcha驗證API服務器之間)由a variety of plugins處理,摘要這個過程對你來說只有在前端和後端才能處理它的結果。
另一方面,Ember是一個客戶端應用程序,它不應該處理驗證步驟而不會泄露您的Private reCaptcha Key以及其他參數。
由於這些事實,我發現更容易手動構建reCaptcha支持,而不是依賴於特定的插件。 Google's Displaying reCAPTCHA Without Plugins頁面描述了DIY的過程。
我使用ember-cli,所以bower install recaptcha-ajax --save
或配置它在bower.json中直接指向Google的recaptcha-ajax.js,然後將其導入Brocfile中。
在您看來,您可以針對特定的元素,像這樣:
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
});
}
});
在你的模板,只需嵌入的element_id
你這個元素從上方插入表單元素:
<form action="" method="post">
<div id="element_id"></div>
</form>
和不要忘了排除的Recaptcha在.jshintrc文件:
{
"predef": {
"Recaptcha": true
}
}
現在您的後端表單處理程序將收到recaptcha_challenge_field
和recaptcha_response_field
,它必須使用它來構建POST
請求http://www.google.com/recaptcha/api/verify,並且您必須根據Google's reCaptcha Verification Flow Document設置一些其他參數。
你還在Broccoli.js中導入了lib嗎?或者那不是必需的? –
@EdyBourne是的,我提到如果你仔細閱讀,你將不得不在我的文章中的brocfile中導入'recaptcha-ajax';) – ashraf
很酷!這首先是我做的,但我使用了錯誤的loader.js。現在使用正確的版本,一切都爲我工作。謝謝! –