11module openflow {
2- "use strict" ;
2+ // "use strict";
33
44 function treatAsUTC ( date ) : number {
55 var result = new Date ( date ) ;
@@ -396,8 +396,11 @@ module openflow {
396396 } ) ;
397397 }
398398 }
399+ declare var QRScanner : any ;
399400 export class LoginCtrl {
400401 public localenabled : boolean = false ;
402+ public scanning : boolean = false ;
403+ public qrcodescan : boolean = false ;
401404 public providers : any = false ;
402405 public username : string = "" ;
403406 public password : string = "" ;
@@ -423,10 +426,81 @@ module openflow {
423426 this . localenabled = true ;
424427 }
425428 }
426-
427429 if ( ! this . $scope . $$phase ) { this . $scope . $apply ( ) ; }
430+ setTimeout ( this . scanForQRScanner . bind ( this ) , 200 ) ;
431+
432+ console . log ( "get mobiledomain" ) ;
433+ var storage = window . localStorage ;
434+ var value = storage . getItem ( "mobiledomain" ) ; // Pass a key name to get its value.
435+ console . log ( value ) ;
436+ if ( value !== null && value !== undefined && value !== "" ) {
437+ if ( value !== window . location . hostname ) {
438+ window . location . replace ( "https://" + value ) ;
439+ return ;
440+ }
441+ }
442+
428443 } ) ;
429444 }
445+ scanForQRScanner ( ) {
446+ try {
447+ if ( QRScanner !== undefined ) {
448+ console . log ( "Found QRScanner!!!!" ) ;
449+ this . qrcodescan = true ;
450+ if ( ! this . $scope . $$phase ) { this . $scope . $apply ( ) ; }
451+ } else {
452+ console . debug ( "QRScanner not definded" ) ;
453+ setTimeout ( this . scanForQRScanner , 200 ) ;
454+ }
455+ } catch ( error ) {
456+ console . debug ( "Failed locating QRScanner" ) ;
457+ setTimeout ( this . scanForQRScanner , 200 ) ;
458+ }
459+ }
460+ Scan ( ) {
461+ try {
462+ console . log ( "Scan" ) ;
463+ if ( this . scanning ) {
464+ this . scanning = false ;
465+ QRScanner . destroy ( ) ;
466+ if ( ! this . $scope . $$phase ) { this . $scope . $apply ( ) ; }
467+ return ;
468+ }
469+ this . scanning = true ;
470+ QRScanner . scan ( this . QRScannerHit . bind ( this ) ) ;
471+ QRScanner . show ( ) ;
472+ if ( ! this . $scope . $$phase ) { this . $scope . $apply ( ) ; }
473+ } catch ( error ) {
474+ console . error ( "Error Scan" ) ;
475+ console . error ( error ) ;
476+ }
477+ }
478+ QRScannerHit ( err , contents ) {
479+ try {
480+ console . log ( "QRScannerHit" ) ;
481+ if ( err ) {
482+ // console.error(err._message);
483+ console . error ( err ) ;
484+ return ;
485+ }
486+ console . log ( contents ) ;
487+ QRScanner . hide ( ) ;
488+ QRScanner . destroy ( ) ;
489+
490+ var storage = window . localStorage ;
491+ var value = storage . getItem ( "mobiledomain" ) ; // Pass a key name to get its value.
492+ storage . setItem ( "mobiledomain" , contents ) // Pass a key name and its value to add or update that key.
493+ // storage.removeItem(key) // Pass a key name to remove that key from storage.
494+ console . log ( "set mobiledomain to " + contents ) ;
495+
496+ this . scanning = false ;
497+ if ( ! this . $scope . $$phase ) { this . $scope . $apply ( ) ; }
498+ } catch ( error ) {
499+ console . error ( "Error QRScannerHit" ) ;
500+ console . error ( error ) ;
501+
502+ }
503+ }
430504 async submit ( ) : Promise < void > {
431505 this . message = "" ;
432506 var q : SigninMessage = new SigninMessage ( ) ;
0 commit comments