angular-captcha
Advanced tools
Comparing version 2.3.0 to 2.4.0
{ | ||
"name": "angular-captcha", | ||
"version": "2.3.0", | ||
"description": "BotDetect Captcha Angular Module (TypeScript / Angular 2+)", | ||
"version": "2.4.0", | ||
"description": "BotDetect Captcha Angular Module (TypeScript: Angular 2/4/5/6/7+)", | ||
"scripts": { | ||
@@ -19,8 +19,8 @@ "clean": "rimraf *.d.ts *.js *.map *.metadata.json src/**/*.d.ts src/**/*.js src/**/*.map src/**/*.metadata.json src/**/*.js.map", | ||
}, | ||
"homepage": "https://captcha.com/angular-captcha.html", | ||
"homepage": "https://captcha.com/angular-captcha.html#angular:2+", | ||
"keywords": [ | ||
"captcha", | ||
"angular-captcha", | ||
"captcha-generator", | ||
"angular-module", | ||
"angular captcha", | ||
"captcha generator", | ||
"angular captcha module", | ||
"botdetect" | ||
@@ -31,16 +31,16 @@ ], | ||
"devDependencies": { | ||
"@angular/common": "^4.0.0", | ||
"@angular/compiler": "^4.0.0", | ||
"@angular/compiler-cli": "^4.0.0", | ||
"@angular/core": "^4.0.0", | ||
"@angular/forms": "^4.0.0", | ||
"@angular/http": "^4.0.0", | ||
"@angular/platform-browser": "^4.0.0", | ||
"codelyzer": "^3.2.0", | ||
"rimraf": "^2.6.2", | ||
"rxjs": "^5.5.2", | ||
"tslint": "^5.1.0", | ||
"typescript": "^2.4.2", | ||
"zone.js": "^0.8.14" | ||
"@angular/common": "^2.4.9", | ||
"@angular/compiler": "^2.4.9", | ||
"@angular/compiler-cli": "^2.4.9", | ||
"@angular/core": "^2.4.9", | ||
"@angular/forms": "^2.4.9", | ||
"@angular/http": "^2.4.9", | ||
"@angular/platform-browser": "^2.4.9", | ||
"codelyzer": "^3.0.0-beta.3", | ||
"rimraf": "^2.6.1", | ||
"rxjs": "^5.2.0", | ||
"tslint": "^4.5.1", | ||
"typescript": "^2.2.1", | ||
"zone.js": "^0.7.7" | ||
} | ||
} |
104
README.md
@@ -1,5 +0,5 @@ | ||
## BotDetect Captcha Angular Module (TypeScript / Angular 2+) | ||
## BotDetect Captcha Angular Module (TypeScript: Angular 2/3/4/5/6/7+) | ||
### Requirements: | ||
Captcha Angular module requires Captcha library to generate image&sound Captcha challenges. Currently, it works with [BotDetect Java Captcha library](https://captcha.com/java-captcha.html), but ASP.NET and PHP libraries are coming soon. | ||
BotDetect Captcha Angular Module requires [BotDetect ASP.NET Captcha](https://captcha.com/asp.net-captcha.html#simple-api), [BotDetect Java Captcha](https://captcha.com/java-captcha.html#simple-api) or [BotDetect PHP Captcha](https://captcha.com/php-captcha.html#simple-api) library to generate Captcha challenges. Simple API support for ASP.NET Core and .NET Core will be released this month -- very likely during the week of 2018/11/19-25. See our [roadmap](https://captcha.com/captcha-roadmap-and-release-notes.html#aspnet-release-notes) for details. | ||
@@ -26,3 +26,8 @@ ### Quickstart: | ||
``` | ||
##### Step 3: Declare Captcha Angular Module | ||
##### Step 3: Declare BotDetect Captcha Angular Module in your application, and configure backend Captcha endpoint | ||
Endpoint Configuration depends on which technology you use in the backend. | ||
- ASP.NET-based backend: | ||
```typescript | ||
@@ -35,3 +40,3 @@ import { BotDetectCaptchaModule } from 'angular-captcha'; | ||
BotDetectCaptchaModule.forRoot({ | ||
captchaEndpoint: '/botdetect-java-captcha-api-path-at-server-side/botdetectcaptcha' | ||
captchaEndpoint: 'captcha-endpoint/BotDetectCaptcha.ashx' | ||
}) | ||
@@ -43,3 +48,35 @@ ], | ||
##### Step 4: Displaying the Captcha Challenge | ||
- Java-based backend: | ||
```typescript | ||
import { BotDetectCaptchaModule } from 'angular-captcha'; | ||
@NgModule({ | ||
imports: [ | ||
... | ||
BotDetectCaptchaModule.forRoot({ | ||
captchaEndpoint: 'captcha-endpoint/botdetectcaptcha' | ||
}) | ||
], | ||
... | ||
}) | ||
``` | ||
- PHP-based backend: | ||
```typescript | ||
import { BotDetectCaptchaModule } from 'angular-captcha'; | ||
@NgModule({ | ||
imports: [ | ||
... | ||
BotDetectCaptchaModule.forRoot({ | ||
captchaEndpoint: 'captcha-endpoint/simple-botdetect.php' | ||
}) | ||
], | ||
... | ||
}) | ||
``` | ||
##### Step 4: Displaying the Captcha Challenge in your form | ||
Place the following tag in your form where you want to display Captcha: | ||
```html | ||
@@ -50,2 +87,31 @@ <botdetect-captcha styleName="exampleCaptcha"></botdetect-captcha> | ||
##### Step 5: Client-side Captcha Validation | ||
- Using validateUnsafe(callback) method to validate Captcha code on form submit: | ||
```typescript | ||
export class ExampleComponent { | ||
/** | ||
* BotDetect CAPTCHA component. | ||
*/ | ||
@ViewChild(CaptchaComponent) captchaComponent: CaptchaComponent; | ||
/** | ||
* On form submit. | ||
*/ | ||
validate(value, valid): void { | ||
this.captchaComponent.validateUnsafe((isCaptchaCodeCorrect: boolean) => { | ||
if (isCaptchaCodeCorrect) { | ||
// Captcha code is correct | ||
} else { | ||
// Captcha code is incorrect | ||
} | ||
}); | ||
} | ||
} | ||
``` | ||
OR | ||
- Using correctCaptcha directive attribute to validate Captcha code on blur event: | ||
```html | ||
@@ -62,13 +128,33 @@ <input | ||
##### Step 6: Server-side Captcha Validation | ||
The client-side Captcha validation is just UI make-up. The purpose of Captcha is to ensure some server-side action is initiated by a human. Therefore, you must validate Captcha at server-side. | ||
These client-side captcha validations are just an usability improvement that you may use or not -- they do not protect your form from spammers at all. | ||
If you have [Java Captcha](https://captcha.com/java-captcha.html) library on a server side validation would look similar to this: | ||
As you are protecting some server-side action you must validate a Captcha at the server-side before executing that protected action. | ||
- If you have [ASP.NET Captcha](https://captcha.com/asp.net-captcha.html#simple-api) library on a server side validation would look similar to this: | ||
```csharp | ||
// C# | ||
SimpleCaptcha captcha = new SimpleCaptcha(); | ||
bool isHuman = captcha.Validate(captchaCode, captchaId); | ||
``` | ||
```vbnet | ||
' VB.NET | ||
Dim captcha As SimpleCaptcha = New SimpleCaptcha() | ||
Dim isHuman As Boolean = captcha.Validate(captchaCode, captchaId) | ||
``` | ||
- If you have [Java Captcha](https://captcha.com/java-captcha.html#simple-api) library on a server side validation would look similar to this: | ||
```java | ||
// validate captcha | ||
SimpleCaptcha captcha = SimpleCaptcha.load(request); | ||
boolean isHuman = captcha.validate(captchaCode, captchaId); | ||
``` | ||
- If you have [PHP Captcha](https://captcha.com/php-captcha.html#simple-api) library on a server side validation would look similar to this: | ||
```php | ||
$captcha = new SimpleCaptcha(); | ||
$isHuman = $captcha->Validate($captchaCode, $captchaId); | ||
``` | ||
### Documentation: | ||
[Angular CAPTCHA Integration Guide](https://captcha.com/angular-captcha.html) | ||
[Angular CAPTCHA Integration Guide](https://captcha.com/angular-captcha.html#angular:2+) | ||
@@ -75,0 +161,0 @@ ### Examples: |
"use strict"; | ||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { | ||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; | ||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); | ||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; | ||
return c > 3 && r && Object.defineProperty(target, key, r), r; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -14,5 +20,6 @@ var core_1 = require("@angular/core"); | ||
} | ||
BotDetectCaptchaModule_1 = BotDetectCaptchaModule; | ||
BotDetectCaptchaModule.forRoot = function (config) { | ||
return { | ||
ngModule: BotDetectCaptchaModule, | ||
ngModule: BotDetectCaptchaModule_1, | ||
providers: [provideBotDetectCaptcha(config)] | ||
@@ -23,24 +30,23 @@ }; | ||
return { | ||
ngModule: BotDetectCaptchaModule, | ||
ngModule: BotDetectCaptchaModule_1, | ||
providers: [provideBotDetectCaptcha(config)] | ||
}; | ||
}; | ||
BotDetectCaptchaModule.decorators = [ | ||
{ type: core_1.NgModule, args: [{ | ||
imports: [ | ||
http_1.HttpModule | ||
], | ||
declarations: [ | ||
captcha_endpoint_pipe_1.CaptchaEndpointPipe, | ||
captcha_component_1.CaptchaComponent, | ||
correct_captcha_directive_1.CorrectCaptchaDirective | ||
], | ||
exports: [ | ||
captcha_component_1.CaptchaComponent, | ||
correct_captcha_directive_1.CorrectCaptchaDirective | ||
] | ||
},] }, | ||
]; | ||
/** @nocollapse */ | ||
BotDetectCaptchaModule.ctorParameters = function () { return []; }; | ||
var BotDetectCaptchaModule_1; | ||
BotDetectCaptchaModule = BotDetectCaptchaModule_1 = __decorate([ | ||
core_1.NgModule({ | ||
imports: [ | ||
http_1.HttpModule | ||
], | ||
declarations: [ | ||
captcha_endpoint_pipe_1.CaptchaEndpointPipe, | ||
captcha_component_1.CaptchaComponent, | ||
correct_captcha_directive_1.CorrectCaptchaDirective | ||
], | ||
exports: [ | ||
captcha_component_1.CaptchaComponent, | ||
correct_captcha_directive_1.CorrectCaptchaDirective | ||
] | ||
}) | ||
], BotDetectCaptchaModule); | ||
return BotDetectCaptchaModule; | ||
@@ -47,0 +53,0 @@ }()); |
"use strict"; | ||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { | ||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; | ||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); | ||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; | ||
return c > 3 && r && Object.defineProperty(target, key, r), r; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -11,7 +17,5 @@ var core_1 = require("@angular/core"); | ||
}; | ||
CaptchaEndpointPipe.decorators = [ | ||
{ type: core_1.Pipe, args: [{ name: 'captchaEndpoint' },] }, | ||
]; | ||
/** @nocollapse */ | ||
CaptchaEndpointPipe.ctorParameters = function () { return []; }; | ||
CaptchaEndpointPipe = __decorate([ | ||
core_1.Pipe({ name: 'captchaEndpoint' }) | ||
], CaptchaEndpointPipe); | ||
return CaptchaEndpointPipe; | ||
@@ -18,0 +22,0 @@ }()); |
@@ -0,6 +1,9 @@ | ||
import { NgZone } from '@angular/core'; | ||
import { Http } from '@angular/http'; | ||
export declare class CaptchaHelperService { | ||
private http; | ||
constructor(http: Http); | ||
getScript(url: string, onLoadSuccess: () => void): void; | ||
private ngZone; | ||
constructor(http: Http, ngZone: NgZone); | ||
getScript(url: string): void; | ||
useUserInputBlurValidation(userInput: any): boolean; | ||
} |
"use strict"; | ||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { | ||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; | ||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); | ||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; | ||
return c > 3 && r && Object.defineProperty(target, key, r), r; | ||
}; | ||
var __metadata = (this && this.__metadata) || function (k, v) { | ||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -6,7 +15,9 @@ var core_1 = require("@angular/core"); | ||
var CaptchaHelperService = /** @class */ (function () { | ||
function CaptchaHelperService(http) { | ||
function CaptchaHelperService(http, ngZone) { | ||
this.http = http; | ||
this.ngZone = ngZone; | ||
} | ||
// get script and execute it immediately | ||
CaptchaHelperService.prototype.getScript = function (url, onLoadSuccess) { | ||
CaptchaHelperService.prototype.getScript = function (url) { | ||
var _this = this; | ||
this.http.get(url) | ||
@@ -16,13 +27,15 @@ .map(function (response) { return response.text(); }) | ||
var f = new Function(scriptString); | ||
f(); | ||
onLoadSuccess(); | ||
_this.ngZone.runOutsideAngular(function () { | ||
f(); | ||
}); | ||
}); | ||
}; | ||
CaptchaHelperService.decorators = [ | ||
{ type: core_1.Injectable }, | ||
]; | ||
/** @nocollapse */ | ||
CaptchaHelperService.ctorParameters = function () { return [ | ||
{ type: http_1.Http, }, | ||
]; }; | ||
CaptchaHelperService.prototype.useUserInputBlurValidation = function (userInput) { | ||
return (userInput.getAttribute('correctCaptcha') !== null); | ||
}; | ||
CaptchaHelperService = __decorate([ | ||
core_1.Injectable(), | ||
__metadata("design:paramtypes", [http_1.Http, | ||
core_1.NgZone]) | ||
], CaptchaHelperService); | ||
return CaptchaHelperService; | ||
@@ -29,0 +42,0 @@ }()); |
@@ -1,1 +0,1 @@ | ||
[{"__symbolic":"module","version":3,"metadata":{"CaptchaHelperService":{"__symbolic":"class","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Injectable"}}],"members":{"__ctor__":[{"__symbolic":"constructor","parameters":[{"__symbolic":"reference","module":"@angular/http","name":"Http"}]}],"getScript":[{"__symbolic":"method"}]}}}},{"__symbolic":"module","version":1,"metadata":{"CaptchaHelperService":{"__symbolic":"class","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Injectable"}}],"members":{"__ctor__":[{"__symbolic":"constructor","parameters":[{"__symbolic":"reference","module":"@angular/http","name":"Http"}]}],"getScript":[{"__symbolic":"method"}]}}}}] | ||
[{"__symbolic":"module","version":3,"metadata":{"CaptchaHelperService":{"__symbolic":"class","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Injectable"}}],"members":{"__ctor__":[{"__symbolic":"constructor","parameters":[{"__symbolic":"reference","module":"@angular/http","name":"Http"},{"__symbolic":"reference","module":"@angular/core","name":"NgZone"}]}],"getScript":[{"__symbolic":"method"}],"useUserInputBlurValidation":[{"__symbolic":"method"}]}}}},{"__symbolic":"module","version":1,"metadata":{"CaptchaHelperService":{"__symbolic":"class","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Injectable"}}],"members":{"__ctor__":[{"__symbolic":"constructor","parameters":[{"__symbolic":"reference","module":"@angular/http","name":"Http"},{"__symbolic":"reference","module":"@angular/core","name":"NgZone"}]}],"getScript":[{"__symbolic":"method"}],"useUserInputBlurValidation":[{"__symbolic":"method"}]}}}}] |
@@ -11,6 +11,8 @@ import { OnInit, ElementRef } from '@angular/core'; | ||
readonly captchaId: string; | ||
readonly captchaCode: string; | ||
ngOnInit(): void; | ||
displayHtml(): void; | ||
reloadImage(): void; | ||
validateUnsafe(callback: (isHuman: boolean) => void): void; | ||
loadScriptIncludes(): void; | ||
} |
"use strict"; | ||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { | ||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; | ||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); | ||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; | ||
return c > 3 && r && Object.defineProperty(target, key, r), r; | ||
}; | ||
var __metadata = (this && this.__metadata) || function (k, v) { | ||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -20,2 +29,10 @@ var core_1 = require("@angular/core"); | ||
}); | ||
Object.defineProperty(CaptchaComponent.prototype, "captchaCode", { | ||
// The typed captcha code value. | ||
get: function () { | ||
return this.captchaService.botdetectInstance.userInput.value; | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
// Display captcha html markup on component initialization. | ||
@@ -49,27 +66,42 @@ CaptchaComponent.prototype.ngOnInit = function () { | ||
}; | ||
// Validate captcha on client-side and execute user callback function on ajax success | ||
CaptchaComponent.prototype.validateUnsafe = function (callback) { | ||
var _this = this; | ||
var userInput = this.captchaService.botdetectInstance.userInput; | ||
var captchaCode = userInput.value; | ||
if (captchaCode.length !== 0) { | ||
this.captchaService.validateUnsafe(captchaCode) | ||
.subscribe(function (isHuman) { | ||
callback(isHuman); | ||
if (!_this.captchaHelper.useUserInputBlurValidation(userInput) && !isHuman) { | ||
_this.reloadImage(); | ||
} | ||
}, function (error) { | ||
throw new Error(error); | ||
}); | ||
} | ||
else { | ||
var isHuman = false; | ||
callback(isHuman); | ||
} | ||
}; | ||
// Load BotDetect scripts. | ||
CaptchaComponent.prototype.loadScriptIncludes = function () { | ||
var scriptIncludeUrl = this.captchaService.captchaEndpoint + '?get=script-include'; | ||
var self = this; | ||
this.captchaHelper.getScript(scriptIncludeUrl, function () { | ||
var captchaId = self.elementRef.nativeElement.querySelector('#BDC_VCID_' + self.styleName).value; | ||
var initScriptIncludeUrl = self.captchaService.captchaEndpoint + '?get=init-script-include&c=' + self.styleName + '&t=' + captchaId + '&cs=201'; | ||
self.captchaHelper.getScript(initScriptIncludeUrl, function () { }); | ||
}); | ||
var captchaId = this.elementRef.nativeElement.querySelector('#BDC_VCID_' + this.styleName).value; | ||
var scriptIncludeUrl = this.captchaService.captchaEndpoint + '?get=script-include&c=' + this.styleName + '&t=' + captchaId + '&cs=201'; | ||
this.captchaHelper.getScript(scriptIncludeUrl); | ||
}; | ||
CaptchaComponent.decorators = [ | ||
{ type: core_1.Component, args: [{ | ||
selector: 'botdetect-captcha', | ||
template: '' | ||
},] }, | ||
]; | ||
/** @nocollapse */ | ||
CaptchaComponent.ctorParameters = function () { return [ | ||
{ type: core_1.ElementRef, }, | ||
{ type: captcha_service_1.CaptchaService, }, | ||
{ type: captcha_helper_service_1.CaptchaHelperService, }, | ||
]; }; | ||
CaptchaComponent.propDecorators = { | ||
'styleName': [{ type: core_1.Input },], | ||
}; | ||
__decorate([ | ||
core_1.Input(), | ||
__metadata("design:type", String) | ||
], CaptchaComponent.prototype, "styleName", void 0); | ||
CaptchaComponent = __decorate([ | ||
core_1.Component({ | ||
selector: 'botdetect-captcha', | ||
template: '' | ||
}), | ||
__metadata("design:paramtypes", [core_1.ElementRef, | ||
captcha_service_1.CaptchaService, | ||
captcha_helper_service_1.CaptchaHelperService]) | ||
], CaptchaComponent); | ||
return CaptchaComponent; | ||
@@ -76,0 +108,0 @@ }()); |
@@ -1,1 +0,1 @@ | ||
[{"__symbolic":"module","version":3,"metadata":{"CaptchaComponent":{"__symbolic":"class","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Component"},"arguments":[{"selector":"botdetect-captcha","template":""}]}],"members":{"styleName":[{"__symbolic":"property","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Input"}}]}],"__ctor__":[{"__symbolic":"constructor","parameters":[{"__symbolic":"reference","module":"@angular/core","name":"ElementRef"},{"__symbolic":"reference","module":"./captcha.service","name":"CaptchaService"},{"__symbolic":"reference","module":"./captcha-helper.service","name":"CaptchaHelperService"}]}],"ngOnInit":[{"__symbolic":"method"}],"displayHtml":[{"__symbolic":"method"}],"reloadImage":[{"__symbolic":"method"}],"loadScriptIncludes":[{"__symbolic":"method"}]}}}},{"__symbolic":"module","version":1,"metadata":{"CaptchaComponent":{"__symbolic":"class","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Component"},"arguments":[{"selector":"botdetect-captcha","template":""}]}],"members":{"styleName":[{"__symbolic":"property","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Input"}}]}],"__ctor__":[{"__symbolic":"constructor","parameters":[{"__symbolic":"reference","module":"@angular/core","name":"ElementRef"},{"__symbolic":"reference","module":"./captcha.service","name":"CaptchaService"},{"__symbolic":"reference","module":"./captcha-helper.service","name":"CaptchaHelperService"}]}],"ngOnInit":[{"__symbolic":"method"}],"displayHtml":[{"__symbolic":"method"}],"reloadImage":[{"__symbolic":"method"}],"loadScriptIncludes":[{"__symbolic":"method"}]}}}}] | ||
[{"__symbolic":"module","version":3,"metadata":{"CaptchaComponent":{"__symbolic":"class","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Component"},"arguments":[{"selector":"botdetect-captcha","template":""}]}],"members":{"styleName":[{"__symbolic":"property","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Input"}}]}],"__ctor__":[{"__symbolic":"constructor","parameters":[{"__symbolic":"reference","module":"@angular/core","name":"ElementRef"},{"__symbolic":"reference","module":"./captcha.service","name":"CaptchaService"},{"__symbolic":"reference","module":"./captcha-helper.service","name":"CaptchaHelperService"}]}],"ngOnInit":[{"__symbolic":"method"}],"displayHtml":[{"__symbolic":"method"}],"reloadImage":[{"__symbolic":"method"}],"validateUnsafe":[{"__symbolic":"method"}],"loadScriptIncludes":[{"__symbolic":"method"}]}}}},{"__symbolic":"module","version":1,"metadata":{"CaptchaComponent":{"__symbolic":"class","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Component"},"arguments":[{"selector":"botdetect-captcha","template":""}]}],"members":{"styleName":[{"__symbolic":"property","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Input"}}]}],"__ctor__":[{"__symbolic":"constructor","parameters":[{"__symbolic":"reference","module":"@angular/core","name":"ElementRef"},{"__symbolic":"reference","module":"./captcha.service","name":"CaptchaService"},{"__symbolic":"reference","module":"./captcha-helper.service","name":"CaptchaHelperService"}]}],"ngOnInit":[{"__symbolic":"method"}],"displayHtml":[{"__symbolic":"method"}],"reloadImage":[{"__symbolic":"method"}],"validateUnsafe":[{"__symbolic":"method"}],"loadScriptIncludes":[{"__symbolic":"method"}]}}}}] |
@@ -15,3 +15,3 @@ import { Http } from '@angular/http'; | ||
getHtml(): Observable<string>; | ||
validate(captchaCode: string): Observable<string>; | ||
validateUnsafe(captchaCode: string): any; | ||
} |
"use strict"; | ||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { | ||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; | ||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); | ||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; | ||
return c > 3 && r && Object.defineProperty(target, key, r), r; | ||
}; | ||
var __metadata = (this && this.__metadata) || function (k, v) { | ||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); | ||
}; | ||
var __param = (this && this.__param) || function (paramIndex, decorator) { | ||
return function (target, key) { decorator(target, key, paramIndex); } | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -51,3 +63,3 @@ var core_1 = require("@angular/core"); | ||
// UI validate captcha. | ||
CaptchaService.prototype.validate = function (captchaCode) { | ||
CaptchaService.prototype.validateUnsafe = function (captchaCode) { | ||
if (!this.botdetectInstance) { | ||
@@ -61,11 +73,8 @@ throw new Error('BotDetect instance does not exist.'); | ||
}; | ||
CaptchaService.decorators = [ | ||
{ type: core_1.Injectable }, | ||
]; | ||
/** @nocollapse */ | ||
CaptchaService.ctorParameters = function () { return [ | ||
{ type: http_1.Http, }, | ||
{ type: captcha_endpoint_pipe_1.CaptchaEndpointPipe, }, | ||
{ type: undefined, decorators: [{ type: core_1.Inject, args: [config_1.CAPTCHA_SETTINGS,] },] }, | ||
]; }; | ||
CaptchaService = __decorate([ | ||
core_1.Injectable(), | ||
__param(2, core_1.Inject(config_1.CAPTCHA_SETTINGS)), | ||
__metadata("design:paramtypes", [http_1.Http, | ||
captcha_endpoint_pipe_1.CaptchaEndpointPipe, Object]) | ||
], CaptchaService); | ||
return CaptchaService; | ||
@@ -72,0 +81,0 @@ }()); |
@@ -1,1 +0,1 @@ | ||
[{"__symbolic":"module","version":3,"metadata":{"CaptchaService":{"__symbolic":"class","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Injectable"}}],"members":{"__ctor__":[{"__symbolic":"constructor","parameterDecorators":[null,null,[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Inject"},"arguments":[{"__symbolic":"reference","module":"./config","name":"CAPTCHA_SETTINGS"}]}]],"parameters":[{"__symbolic":"reference","module":"@angular/http","name":"Http"},{"__symbolic":"reference","module":"./captcha-endpoint.pipe","name":"CaptchaEndpointPipe"},{"__symbolic":"reference","module":"./captcha-settings.interface","name":"CaptchaSettings"}]}],"getHtml":[{"__symbolic":"method"}],"validate":[{"__symbolic":"method"}]}}}},{"__symbolic":"module","version":1,"metadata":{"CaptchaService":{"__symbolic":"class","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Injectable"}}],"members":{"__ctor__":[{"__symbolic":"constructor","parameterDecorators":[null,null,[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Inject"},"arguments":[{"__symbolic":"reference","module":"./config","name":"CAPTCHA_SETTINGS"}]}]],"parameters":[{"__symbolic":"reference","module":"@angular/http","name":"Http"},{"__symbolic":"reference","module":"./captcha-endpoint.pipe","name":"CaptchaEndpointPipe"},{"__symbolic":"reference","module":"./captcha-settings.interface","name":"CaptchaSettings"}]}],"getHtml":[{"__symbolic":"method"}],"validate":[{"__symbolic":"method"}]}}}}] | ||
[{"__symbolic":"module","version":3,"metadata":{"CaptchaService":{"__symbolic":"class","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Injectable"}}],"members":{"__ctor__":[{"__symbolic":"constructor","parameterDecorators":[null,null,[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Inject"},"arguments":[{"__symbolic":"reference","module":"./config","name":"CAPTCHA_SETTINGS"}]}]],"parameters":[{"__symbolic":"reference","module":"@angular/http","name":"Http"},{"__symbolic":"reference","module":"./captcha-endpoint.pipe","name":"CaptchaEndpointPipe"},{"__symbolic":"reference","module":"./captcha-settings.interface","name":"CaptchaSettings"}]}],"getHtml":[{"__symbolic":"method"}],"validateUnsafe":[{"__symbolic":"method"}]}}}},{"__symbolic":"module","version":1,"metadata":{"CaptchaService":{"__symbolic":"class","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Injectable"}}],"members":{"__ctor__":[{"__symbolic":"constructor","parameterDecorators":[null,null,[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Inject"},"arguments":[{"__symbolic":"reference","module":"./config","name":"CAPTCHA_SETTINGS"}]}]],"parameters":[{"__symbolic":"reference","module":"@angular/http","name":"Http"},{"__symbolic":"reference","module":"./captcha-endpoint.pipe","name":"CaptchaEndpointPipe"},{"__symbolic":"reference","module":"./captcha-settings.interface","name":"CaptchaSettings"}]}],"getHtml":[{"__symbolic":"method"}],"validateUnsafe":[{"__symbolic":"method"}]}}}}] |
@@ -1,3 +0,2 @@ | ||
import { InjectionToken } from '@angular/core'; | ||
import { CaptchaSettings } from './captcha-settings.interface'; | ||
export declare let CAPTCHA_SETTINGS: InjectionToken<CaptchaSettings>; | ||
import { OpaqueToken } from '@angular/core'; | ||
export declare const CAPTCHA_SETTINGS: OpaqueToken; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var core_1 = require("@angular/core"); | ||
exports.CAPTCHA_SETTINGS = new core_1.InjectionToken('captcha.settings'); | ||
exports.CAPTCHA_SETTINGS = new core_1.OpaqueToken('captcha.settings'); | ||
//# sourceMappingURL=config.js.map |
@@ -1,1 +0,1 @@ | ||
[{"__symbolic":"module","version":3,"metadata":{"CAPTCHA_SETTINGS":{"__symbolic":"new","expression":{"__symbolic":"reference","module":"@angular/core","name":"InjectionToken"},"arguments":["captcha.settings"]}}},{"__symbolic":"module","version":1,"metadata":{"CAPTCHA_SETTINGS":{"__symbolic":"new","expression":{"__symbolic":"reference","module":"@angular/core","name":"InjectionToken"},"arguments":["captcha.settings"]}}}] | ||
[{"__symbolic":"module","version":3,"metadata":{"CAPTCHA_SETTINGS":{"__symbolic":"new","expression":{"__symbolic":"reference","module":"@angular/core","name":"OpaqueToken"},"arguments":["captcha.settings"]}}},{"__symbolic":"module","version":1,"metadata":{"CAPTCHA_SETTINGS":{"__symbolic":"new","expression":{"__symbolic":"reference","module":"@angular/core","name":"OpaqueToken"},"arguments":["captcha.settings"]}}}] |
"use strict"; | ||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { | ||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; | ||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); | ||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; | ||
return c > 3 && r && Object.defineProperty(target, key, r), r; | ||
}; | ||
var __metadata = (this && this.__metadata) || function (k, v) { | ||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); | ||
}; | ||
var __param = (this && this.__param) || function (paramIndex, decorator) { | ||
return function (target, key) { decorator(target, key, paramIndex); } | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -12,2 +24,3 @@ var core_1 = require("@angular/core"); | ||
} | ||
CorrectCaptchaDirective_1 = CorrectCaptchaDirective; | ||
CorrectCaptchaDirective.prototype.validate = function (c, onBlur) { | ||
@@ -27,3 +40,3 @@ var _this = this; | ||
if (captchaCode) { | ||
_this.captchaService.validate(captchaCode) | ||
_this.captchaService.validateUnsafe(captchaCode) | ||
.subscribe(function (isHuman) { | ||
@@ -49,22 +62,23 @@ if (!isHuman) { | ||
}; | ||
CorrectCaptchaDirective.decorators = [ | ||
{ type: core_1.Directive, args: [{ | ||
selector: '[correctCaptcha][formControlName],[correctCaptcha][formControl],[correctCaptcha][ngModel]', | ||
providers: [ | ||
{ | ||
provide: forms_1.NG_ASYNC_VALIDATORS, | ||
useExisting: core_1.forwardRef(function () { return CorrectCaptchaDirective; }), | ||
multi: true | ||
} | ||
] | ||
},] }, | ||
]; | ||
/** @nocollapse */ | ||
CorrectCaptchaDirective.ctorParameters = function () { return [ | ||
{ type: undefined, decorators: [{ type: core_1.Inject, args: [platform_browser_1.DOCUMENT,] },] }, | ||
{ type: captcha_service_1.CaptchaService, }, | ||
]; }; | ||
CorrectCaptchaDirective.propDecorators = { | ||
'onBlur': [{ type: core_1.HostListener, args: ['blur',] },], | ||
}; | ||
var CorrectCaptchaDirective_1; | ||
__decorate([ | ||
core_1.HostListener('blur'), | ||
__metadata("design:type", Function), | ||
__metadata("design:paramtypes", []), | ||
__metadata("design:returntype", void 0) | ||
], CorrectCaptchaDirective.prototype, "onBlur", null); | ||
CorrectCaptchaDirective = CorrectCaptchaDirective_1 = __decorate([ | ||
core_1.Directive({ | ||
selector: '[correctCaptcha][formControlName],[correctCaptcha][formControl],[correctCaptcha][ngModel]', | ||
providers: [ | ||
{ | ||
provide: forms_1.NG_ASYNC_VALIDATORS, | ||
useExisting: core_1.forwardRef(function () { return CorrectCaptchaDirective_1; }), | ||
multi: true | ||
} | ||
] | ||
}), | ||
__param(0, core_1.Inject(platform_browser_1.DOCUMENT)), | ||
__metadata("design:paramtypes", [Object, captcha_service_1.CaptchaService]) | ||
], CorrectCaptchaDirective); | ||
return CorrectCaptchaDirective; | ||
@@ -71,0 +85,0 @@ }()); |
@@ -0,0 +0,0 @@ { |
@@ -0,0 +0,0 @@ { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
57714
611
164