@@ -16,12 +16,14 @@ import { Component, ViewChild, ElementRef } from '@angular/core';
1616import { IonicPage , NavController , NavParams } from 'ionic-angular' ;
1717import { TranslateService } from '@ngx-translate/core' ;
1818import { CoreAppProvider } from '@providers/app' ;
19+ import { CoreUtils } from '@providers/utils/utils' ;
1920import { CoreEventsProvider } from '@providers/events' ;
2021import { CoreSitesProvider } from '@providers/sites' ;
2122import { CoreDomUtilsProvider } from '@providers/utils/dom' ;
2223import { CoreLoginHelperProvider } from '../../providers/helper' ;
2324import { FormBuilder , FormGroup , Validators } from '@angular/forms' ;
2425import { CoreConfigConstants } from '../../../../configconstants' ;
26+ import { CoreCustomURLSchemes } from '@providers/urlschemes' ;
2527
2628/**
2729 * Page to enter the user credentials.
@@ -47,6 +49,7 @@ export class CoreLoginCredentialsPage {
4749 isBrowserSSO = false ;
4850 isFixedUrlSet = false ;
4951 showForgottenPassword = true ;
52+ showScanQR : boolean ;
5053
5154 protected siteConfig ;
5255 protected eventThrown = false ;
@@ -74,6 +77,17 @@ export class CoreLoginCredentialsPage {
7477 username : [ navParams . get ( 'username' ) || '' , Validators . required ] ,
7578 password : [ '' , Validators . required ]
7679 } ) ;
80+
81+ const canScanQR = CoreUtils . instance . canScanQR ( ) ;
82+ if ( canScanQR ) {
83+ if ( typeof CoreConfigConstants [ 'displayqroncredentialscreen' ] == 'undefined' ) {
84+ this . showScanQR = this . loginHelper . isFixedUrlSet ( ) ;
85+ } else {
86+ this . showScanQR = ! ! CoreConfigConstants [ 'displayqroncredentialscreen' ] ;
87+ }
88+ } else {
89+ this . showScanQR = false ;
90+ }
7791 }
7892
7993 /**
@@ -267,4 +281,46 @@ export class CoreLoginCredentialsPage {
267281 signup ( ) : void {
268282 this . navCtrl . push ( 'CoreLoginEmailSignupPage' , { siteUrl : this . siteUrl } ) ;
269283 }
284+
285+ /**
286+ * Show instructions and scan QR code.
287+ */
288+ showInstructionsAndScanQR ( ) : void {
289+ // Show some instructions first.
290+ this . domUtils . showAlertWithOptions ( {
291+ title : this . translate . instant ( 'core.login.faqwhereisqrcode' ) ,
292+ message : this . translate . instant ( 'core.login.faqwhereisqrcodeanswer' ,
293+ { $image : CoreLoginHelperProvider . FAQ_QRCODE_IMAGE_HTML } ) ,
294+ buttons : [
295+ {
296+ text : this . translate . instant ( 'core.cancel' ) ,
297+ role : 'cancel'
298+ } ,
299+ {
300+ text : this . translate . instant ( 'core.next' ) ,
301+ handler : ( ) : void => {
302+ this . scanQR ( ) ;
303+ }
304+ } ,
305+ ] ,
306+ } ) ;
307+ }
308+
309+ /**
310+ * Scan a QR code and put its text in the URL input.
311+ *
312+ * @return Promise resolved when done.
313+ */
314+ async scanQR ( ) : Promise < void > {
315+ // Scan for a QR code.
316+ const text = await CoreUtils . instance . scanQR ( ) ;
317+
318+ if ( text && CoreCustomURLSchemes . instance . isCustomURL ( text ) ) {
319+ try {
320+ await CoreCustomURLSchemes . instance . handleCustomURL ( text ) ;
321+ } catch ( error ) {
322+ CoreCustomURLSchemes . instance . treatHandleCustomURLError ( error ) ;
323+ }
324+ }
325+ }
270326}
0 commit comments