1 const TAG = '[DeviceHome][pincode]';
2 const serverPort = 9000;
3 const serverURL = window.location.protocol + '//' + window.location.hostname;
7 var dots = document.querySelectorAll('.dot'), numbers = document.querySelectorAll('.number');
10 function displayPincode() {
11 var xhr = new XMLHttpRequest();
12 xhr.onload = function () {
13 if (xhr.status === 200 || xhr.status === 201) {
14 publicKey = xhr.responseText;
16 console.error(xhr.responseText);
19 xhr.open('GET', serverURL + ':' + serverPort + '/pincode/publicKey');
24 dots = Array.prototype.slice.call(dots);
25 numbers = Array.prototype.slice.call(numbers);
26 numbers.forEach(function (number, index) {
27 number.addEventListener('click', function () {
28 number.className += ' grow';
29 if (number.innerHTML === '0') {
34 dots[input.length - 1].className += ' active';
35 if (input.length >= 4) {
36 console.log(`${TAG} input: ${input}`);
39 setTimeout(function () {
40 dots.forEach(function (dot, index) {
41 dot.className = 'dot';
45 setTimeout(function () {
46 document.body.className = '';
49 setTimeout(function () {
50 number.className = 'number';
56 async function sendPinCode(data) {
57 var encrypt = new JSEncrypt();
58 encrypt.setPublicKey(publicKey);
59 var xhr = new XMLHttpRequest();
60 xhr.onload = function () {
61 if (xhr.status === 200 || xhr.status === 201) {
62 console.log(`result : ${xhr.responseText}`);
63 chkPinCode(xhr.responseText === 'true' ? true : false);
65 console.error(xhr.responseText);
68 xhr.open('POST', serverURL + ':' + serverPort + '/pincode/pinCodeToServer');
69 xhr.setRequestHeader("Content-Type", "application/json");
70 var data = encrypt.encrypt(data);
71 console.log(`${TAG} data: ${data}`);
72 xhr.send(JSON.stringify({ pincode: data.toString("utf8") }));
75 function chkPinCode(returnVal) {
77 dots.forEach(function (dot, index) {
78 dot.className += ' correct';
80 document.body.className += ' correct';
82 setTimeout(function () {
87 dots.forEach(function (dot, index) {
88 dot.className += ' wrong';
90 document.body.className += ' wrong';
95 setTimeout(function () {
96 alert('Failed to input 5 times. A new Pincode has been generated, so check the TV notification.');
103 window.location.href = serverURL + ':' + serverPort + '/client/client.html';
106 window.onload = function () {