Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
init() {
let loc = window.location.pathname.replace(/^\//, '');
if (loc.length > 0) {
let [pin, crc] = loc.split('_');
if (crc32(pin).toString(16).toLowerCase() === crc.toLowerCase()) {
window.history.pushState({}, '', '/'); // to remove pathname
this.storage.delete(['authToken']);
this._currentScreen = 'login';
this.loginWithPin(pin)
.then(() => {
this.init(); // Should not enter endless loop because path should be empty here.
})
.catch((e) => {
console.error(e);
this.metrika.track(MetrikaService.LOAD_ERROR, {
type: 'state-init-login',
request: 'confirmRegistration',
message: e.toString()
});
});
return;
canvas.drawImage(this._video, 0, 0, canvasElement.width, canvasElement.height);
let imageData = canvas.getImageData(0, 0, canvasElement.width, canvasElement.height);
let code = jsQR(imageData.data, imageData.width, imageData.height, {
inversionAttempts: 'dontInvert',
});
if (code) {
let pincode = '';
let data = code.data.match(/^https?:\/\/(.*?)\/(\d+)_([\da-f]+)$/i);
if (data) {
if (data[1].split(':')[0] === 'localhost') { // local debug
pincode = data[2];
} else {
if (
data[1].split(':')[0] === location.host &&
crc32(data[2]).toString(16).toLowerCase() === data[3].toLowerCase()
) {
pincode = data[2];
}
}
}
if (pincode.length > 0) {
this._stopVideo();
this._video.pause();
this._onPinReceived(pincode);
return;
}
}
}
requestAnimationFrame(tick);