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');
9 function displayPincode() {
10 var xhr = new XMLHttpRequest();
11 xhr.onload = function() {
12 if (xhr.status === 200 || xhr.status === 201) {
13 publicKey = xhr.responseText;
15 console.error(xhr.responseText);
18 xhr.open('GET', serverURL + ':' + serverPort + '/pincode/publicKey');
23 dots = Array.prototype.slice.call(dots);
24 numbers = Array.prototype.slice.call(numbers);
25 numbers.forEach(function(number, index) {
26 number.addEventListener('click', function() {
27 number.className += ' grow';
28 if (number.innerHTML === '0') {
33 dots[input.length - 1].className += ' active';
34 if (input.length >= 4) {
35 console.log(`${TAG} input: ${input}`);
38 setTimeout(function() {
39 dots.forEach(function(dot, index) {
40 dot.className = 'dot';
44 setTimeout(function() {
45 document.body.className = '';
48 setTimeout(function() {
49 number.className = 'number';
55 async function sendPinCode(data) {
56 var encrypt = new JSEncrypt();
57 encrypt.setPublicKey(publicKey);
58 var xhr = new XMLHttpRequest();
59 xhr.onload = function() {
60 if (xhr.status === 200 || xhr.status === 201) {
61 console.log(`result : ${xhr.responseText}`);
62 if (xhr.responseText === 'retry') {
65 chkPinCode(xhr.responseText === 'true' ? true : false);
68 console.error(xhr.responseText);
71 xhr.open('POST', serverURL + ':' + serverPort + '/pincode/pinCodeToServer');
72 xhr.setRequestHeader("Content-Type", "application/json");
73 var data = encrypt.encrypt(data);
74 console.log(`${TAG} data: ${data}`);
75 xhr.send(JSON.stringify({ pincode: data.toString("utf8") }));
78 function retryPinCode() {
79 dots.forEach(function(dot, index) {
80 dot.className += ' wrong';
82 document.body.className += ' wrong';
84 setTimeout(function() {
85 alert('Failed to input 5 times. A new Pincode has been generated, so check the TV notification.');
89 function chkPinCode(returnVal) {
91 dots.forEach(function(dot, index) {
92 dot.className += ' correct';
94 document.body.className += ' correct';
95 setTimeout(function() {
99 dots.forEach(function(dot, index) {
100 dot.className += ' wrong';
102 document.body.className += ' wrong';
107 window.location.href = serverURL + ':' + serverPort + '/client/client.html';
110 window.onload = function() {