MOBILE-2334 core: Fix webpack errors with recaptcha
parent
ae290c3c05
commit
602312e621
|
@ -41,7 +41,8 @@ import { CoreNavBarButtonsComponent } from './navbar-buttons/navbar-buttons';
|
||||||
import { CoreDynamicComponent } from './dynamic-component/dynamic-component';
|
import { CoreDynamicComponent } from './dynamic-component/dynamic-component';
|
||||||
import { CoreSendMessageFormComponent } from './send-message-form/send-message-form';
|
import { CoreSendMessageFormComponent } from './send-message-form/send-message-form';
|
||||||
import { CoreTimerComponent } from './timer/timer';
|
import { CoreTimerComponent } from './timer/timer';
|
||||||
import { CoreRecaptchaComponent, CoreRecaptchaModalComponent } from './recaptcha/recaptcha';
|
import { CoreRecaptchaComponent } from './recaptcha/recaptcha';
|
||||||
|
import { CoreRecaptchaModalComponent } from './recaptcha/recaptchamodal';
|
||||||
import { CoreNavigationBarComponent } from './navigation-bar/navigation-bar';
|
import { CoreNavigationBarComponent } from './navigation-bar/navigation-bar';
|
||||||
import { CoreAttachmentsComponent } from './attachments/attachments';
|
import { CoreAttachmentsComponent } from './attachments/attachments';
|
||||||
|
|
||||||
|
|
|
@ -13,34 +13,29 @@
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
import { Component, Input } from '@angular/core';
|
import { Component, Input } from '@angular/core';
|
||||||
import { ModalController, ViewController, NavParams } from 'ionic-angular';
|
import { ModalController } from 'ionic-angular';
|
||||||
import { CoreSitesProvider } from '@providers/sites';
|
import { CoreSitesProvider } from '@providers/sites';
|
||||||
import { CoreLangProvider } from '@providers/lang';
|
import { CoreLangProvider } from '@providers/lang';
|
||||||
import { CoreTextUtilsProvider } from '@providers/utils/text';
|
import { CoreTextUtilsProvider } from '@providers/utils/text';
|
||||||
|
import { CoreRecaptchaModalComponent } from './recaptchamodal';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Directive to display a reCaptcha.
|
* Component that allows answering a recaptcha.
|
||||||
*
|
|
||||||
* Accepts the following attributes:
|
|
||||||
* @param {any} model The model where to store the recaptcha response.
|
|
||||||
* @param {string} publicKey The site public key.
|
|
||||||
* @param {string} [modelValueName] Name of the model property where to store the response. Defaults to 'recaptcharesponse'.
|
|
||||||
* @param {string} [siteUrl] The site URL. If not defined, current site.
|
|
||||||
*/
|
*/
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'core-recaptcha',
|
selector: 'core-recaptcha',
|
||||||
templateUrl: 'recaptcha.html'
|
templateUrl: 'recaptcha.html'
|
||||||
})
|
})
|
||||||
export class CoreRecaptchaComponent {
|
export class CoreRecaptchaComponent {
|
||||||
|
@Input() model: any; // The model where to store the recaptcha response.
|
||||||
|
@Input() publicKey: string; // The site public key.
|
||||||
|
@Input() modelValueName = 'recaptcharesponse'; // Name of the model property where to store the response.
|
||||||
|
@Input() siteUrl?: string; // The site URL. If not defined, current site.
|
||||||
|
|
||||||
expired = false;
|
expired = false;
|
||||||
|
|
||||||
protected lang: string;
|
protected lang: string;
|
||||||
|
|
||||||
@Input() model: any;
|
|
||||||
@Input() publicKey: string;
|
|
||||||
@Input() modelValueName = 'recaptcharesponse';
|
|
||||||
@Input() siteUrl?: string;
|
|
||||||
|
|
||||||
constructor(private sitesProvider: CoreSitesProvider, langProvider: CoreLangProvider,
|
constructor(private sitesProvider: CoreSitesProvider, langProvider: CoreLangProvider,
|
||||||
private textUtils: CoreTextUtilsProvider, private modalCtrl: ModalController) {
|
private textUtils: CoreTextUtilsProvider, private modalCtrl: ModalController) {
|
||||||
|
|
||||||
|
@ -75,53 +70,3 @@ export class CoreRecaptchaComponent {
|
||||||
modal.present();
|
modal.present();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Component({
|
|
||||||
selector: 'core-recaptcha-modal',
|
|
||||||
templateUrl: 'recaptchamodal.html'
|
|
||||||
})
|
|
||||||
export class CoreRecaptchaModalComponent {
|
|
||||||
|
|
||||||
expired = false;
|
|
||||||
value = '';
|
|
||||||
src: string;
|
|
||||||
|
|
||||||
constructor(protected viewCtrl: ViewController, params: NavParams) {
|
|
||||||
this.src = params.get('src');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Close modal.
|
|
||||||
*/
|
|
||||||
closeModal(): void {
|
|
||||||
this.viewCtrl.dismiss({
|
|
||||||
expired: this.expired,
|
|
||||||
value: this.value
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The iframe with the recaptcha was loaded.
|
|
||||||
*
|
|
||||||
* @param {HTMLIFrameElement} iframe Iframe element.
|
|
||||||
*/
|
|
||||||
loaded(iframe: HTMLIFrameElement): void {
|
|
||||||
// Search the iframe content.
|
|
||||||
const contentWindow = iframe && iframe.contentWindow;
|
|
||||||
|
|
||||||
if (contentWindow) {
|
|
||||||
// Set the callbacks we're interested in.
|
|
||||||
contentWindow['recaptchacallback'] = (value): void => {
|
|
||||||
this.expired = false;
|
|
||||||
this.value = value;
|
|
||||||
this.closeModal();
|
|
||||||
};
|
|
||||||
|
|
||||||
contentWindow['recaptchaexpiredcallback'] = (): void => {
|
|
||||||
// Verification expired. Check the checkbox again.
|
|
||||||
this.expired = true;
|
|
||||||
this.value = '';
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -0,0 +1,68 @@
|
||||||
|
// (C) Copyright 2015 Martin Dougiamas
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
import { Component } from '@angular/core';
|
||||||
|
import { ViewController, NavParams } from 'ionic-angular';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Component to display a the recaptcha in a modal.
|
||||||
|
*/
|
||||||
|
@Component({
|
||||||
|
selector: 'core-recaptcha-modal',
|
||||||
|
templateUrl: 'recaptchamodal.html'
|
||||||
|
})
|
||||||
|
export class CoreRecaptchaModalComponent {
|
||||||
|
expired = false;
|
||||||
|
value = '';
|
||||||
|
src: string;
|
||||||
|
|
||||||
|
constructor(protected viewCtrl: ViewController, params: NavParams) {
|
||||||
|
this.src = params.get('src');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Close modal.
|
||||||
|
*/
|
||||||
|
closeModal(): void {
|
||||||
|
this.viewCtrl.dismiss({
|
||||||
|
expired: this.expired,
|
||||||
|
value: this.value
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The iframe with the recaptcha was loaded.
|
||||||
|
*
|
||||||
|
* @param {HTMLIFrameElement} iframe Iframe element.
|
||||||
|
*/
|
||||||
|
loaded(iframe: HTMLIFrameElement): void {
|
||||||
|
// Search the iframe content.
|
||||||
|
const contentWindow = iframe && iframe.contentWindow;
|
||||||
|
|
||||||
|
if (contentWindow) {
|
||||||
|
// Set the callbacks we're interested in.
|
||||||
|
contentWindow['recaptchacallback'] = (value): void => {
|
||||||
|
this.expired = false;
|
||||||
|
this.value = value;
|
||||||
|
this.closeModal();
|
||||||
|
};
|
||||||
|
|
||||||
|
contentWindow['recaptchaexpiredcallback'] = (): void => {
|
||||||
|
// Verification expired. Check the checkbox again.
|
||||||
|
this.expired = true;
|
||||||
|
this.value = '';
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue