-
Notifications
You must be signed in to change notification settings - Fork 7
/
showQRCtrl.js
51 lines (50 loc) · 1.25 KB
/
showQRCtrl.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
const QRCode = require('qrcode');
module.exports = [
'$scope',
'$window',
'$location',
'alertService',
'userService',
'socketIOService',
function (
$scope,
$window,
$location,
alertService,
userService,
socketIOService
) {
const urlParams = new URLSearchParams(window.location.search);
const token = urlParams.get('token');
const cardKey = urlParams.get('cardKey');
const [, , code] = token.split(':');
const link = `${window.location.origin}/auth/login/?token=${token}`;
QRCode.toDataURL(
link,
{ type: 'image/png', width: 1000 },
function (err, url) {
$scope.qrdata = url;
}
);
socketIOService.listen('qr-opened', function (socketCode) {
if (socketCode === code) {
$scope.$apply(() => {
$location.url('/moderator/qr?status=success');
});
}
});
$scope.close = function () {
$location.url('/moderator/qr?status=success');
};
$scope.closeAndDeactivate = function () {
userService.toggleUser(cardKey).then(
function (response) {
$location.url('/moderator/qr?status=fail');
},
function () {
$location.url('/moderator/qr?status=success');
}
);
};
},
];