export const RECAPTCHA_URL = new InjectionToken('RECAPTCHA_URL');
@Injectable()
class ReCaptchaAsyncValidator {
constructor( private http : Http, @Inject(RECAPTCHA_URL) private url ) {
}
validateToken( token : string ) {
return ( _ : AbstractControl ) => {
return this.http.get(this.url, { params: { token } }).map(res => res.json()).map(res => {
if( !res.success ) {
return { tokenInvalid: true }
}
return null;
});
}
}
}