Skip to content

Commit ea0552d

Browse files
committed
add qrcode support in login
1 parent 9851397 commit ea0552d

2 files changed

Lines changed: 107 additions & 27 deletions

File tree

OpenFlow/src/public/Controllers.ts

Lines changed: 76 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module 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();

OpenFlow/src/public/Login.html

Lines changed: 31 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,37 @@
1-
<div class="starter-template">
1+
<div class="starter-template" ng-show="ctrl.scanning==false">
22
<div class="row">
3-
<div class="col-sm-9 col-md-7 col-lg-5 mx-auto">
4-
<div class="card card-signin my-5">
5-
<div class="card-body">
6-
<h5 class="card-title text-center" translate lib="web">signin</h5>
7-
<form class="form-signin" ngNoForm method='post' action='/local' >
8-
<div class="form-label-group" ng-show="ctrl.localenabled">
9-
<input type="text" name="username" ng-model="ctrl.username" class="form-control" placeholder="Username" required autofocus autocomplete='off'>
10-
<label for="username" translate lib="web">username</label>
11-
</div>
3+
<div class="col-sm-9 col-md-7 col-lg-5 mx-auto">
4+
<div class="card card-signin my-5">
5+
<div class="card-body">
6+
<h5 class="card-title text-center" translate lib="web">signin</h5>
7+
<form class="form-signin" ngNoForm method='post' action='/local'>
8+
<div class="form-label-group" ng-show="ctrl.localenabled">
9+
<input type="text" name="username" ng-model="ctrl.username" class="form-control" placeholder="Username"
10+
required autofocus autocomplete='off'>
11+
<label for="username" translate lib="web">username</label>
12+
</div>
13+
<div class="form-label-group" ng-show="ctrl.localenabled">
14+
<input type="password" name="password" ng-model="ctrl.password" class="form-control"
15+
placeholder="Password" required>
16+
<label for="password" translate lib="web">password</label>
17+
</div>
18+
<div class="mb-3">
19+
<label class="text-danger" translate lib="web" ng-model="ctrl.message"></label>
20+
</div>
21+
<button class="btn btn-lg btn-primary btn-block text-uppercase" type="submit" ng-show="ctrl.localenabled"
22+
translate lib="web">signin</button>
23+
<hr class="my-4" ng-show="ctrl.localenabled">
24+
<div class="form-label-group" ng-show="ctrl.qrcodescan">
25+
<button value="Scan now" ng-click="ctrl.Scan()" type="button">QRCode Scan</button>
26+
</div>
1227

13-
<div class="form-label-group" ng-show="ctrl.localenabled">
14-
<input type="password" name="password" ng-model="ctrl.password" class="form-control" placeholder="Password" required >
15-
<label for="password" translate lib="web">password</label>
16-
</div>
17-
<div class="mb-3">
18-
<label class="text-danger" translate lib="web" ng-model="ctrl.message"></label>
19-
</div>
20-
<button class="btn btn-lg btn-primary btn-block text-uppercase" type="submit" ng-show="ctrl.localenabled" translate lib="web">signin</button>
21-
<hr class="my-4" ng-show="ctrl.localenabled">
22-
23-
<a ng-href="/{{model.id}}" ng-repeat="model in ctrl.providers" class="btn btn-lg btn-block text-uppercase" >
24-
<i class="fab {{model.logo}} mr-2"></i><span translate lib="web">{{model.name}}</span>
25-
</a>
26-
</form>
27-
</div>
28+
<a ng-href="/{{model.id}}" ng-repeat="model in ctrl.providers" class="btn btn-lg btn-block text-uppercase">
29+
<i class="fab {{model.logo}} mr-2"></i><span translate lib="web">{{model.name}}</span>
30+
</a>
31+
</form>
2832
</div>
2933
</div>
3034
</div>
35+
</div>
3136
</div>
37+
<button value="Scan now" ng-click="ctrl.Scan()" type="button" ng-show="ctrl.scanning==true">QRCode Scan</button>

0 commit comments

Comments
 (0)