Angular JS中的Recaptcha [英] Recaptcha in Angular JS
问题描述
我正在Angular JS中实现recaptcha,我正在使用" https://github.com/VividCortex/网址摘要"网址作为参考.我已经参考了用法"部分,并按照代码说明进行操作,但是仍然无法在注册页面中获得重新验证码.
I am implementing recaptcha in Angular JS, I am using "https://github.com/VividCortex/angular-recaptcha" url as reference. I have referred the Usage section and followed the instructions of code but still not able to get recaptcha in registration page.
我遵循的步骤- 1.生成了一个公钥. 2.新增 3.添加了用于recaptcha的div
Steps I have followed - 1. Generated a public key. 2. Added 3. Added div for recaptcha
- 在页面中添加了anular-recaptcha.js-上面网址的低代码形式github代码.
任何人都可以让我知道我在其中缺少什么吗?谁能给我演示验证码的演示示例链接?
Can anyone please let me know what I am missing in it? Can anyone can give me demo example link for recaptcha?
先谢谢了.
推荐答案
为我着迷的示例
register.cshtml:
example that woked for me
register.cshtml:
<div vc-recaptcha key="'domain-key'" on-success="setResponse(response)"></div>
app.js:
var app = angular.module('myApp', ['ngRoute','vcRecaptcha']);
controller.js:
controller.js:
var ctrl = function ($rootScope, $scope, $location, $routeParams, registrationService) {
$scope.reCaptchaResponse = "";
$scope.setResponse = function (response) {
$scope.reCaptchaResponse = response;
};
$scope.register = function () {
var registration = {
...
reCaptchaResponse: $scope.reCaptchaResponse
}
$http.post(serviceBase + 'Register', registration).then(function (results) {
//return result
});
}
}
Controller.cs:
Controller.cs:
[HttpPost]
public JsonResult Register(UserDTO registration)
{
string responseFromServer = "";
WebRequest request = WebRequest.Create("https://www.google.com/recaptcha/api/siteverify?secret=mysecret&response=" + registration.ReCaptchaResponse);
request.Method = "GET";
using (WebResponse response = request.GetResponse())
{
using (Stream stream = response.GetResponseStream())
{
StreamReader reader = new StreamReader(stream);
responseFromServer = reader.ReadToEnd();
}
}
if(responseFromServer != "")
{
bool isSuccess = false;
Dictionary<string, string> values = JsonConvert.DeserializeObject<Dictionary<string, string>>(responseFromServer);
foreach (var item in values)
{
if (item.Key == "success" && item.Value == "True")
{
isSuccess = true;
break;
}
}
if(isSuccess)
{
//do something
}
else
{
//return reCaptcha error
}
}
return Json(result);
}
这篇关于Angular JS中的Recaptcha的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!