1 const serverPort = 9000;
2 const serverURL = window.location.protocol + '//' + window.location.hostname;
6 var dots = document.querySelectorAll('.dot'), numbers = document.querySelectorAll('.number');
9 function preloadKey() {
10 var xhr = new XMLHttpRequest();
11 xhr.onload = function () {
12 if (xhr.status === 200 || xhr.status === 201) {
13 publicKey = xhr.responseText;
17 console.error('[WT] Failed to get public key.');
20 console.error(xhr.responseText);
23 xhr.open('GET', serverURL + ':' + serverPort + '/pincode/publicKey');
28 dots = Array.prototype.slice.call(dots);
29 numbers = Array.prototype.slice.call(numbers);
30 numbers.forEach(function (number, index) {
31 number.addEventListener('click', function () {
32 number.className += ' grow';
33 if (number.innerHTML === '0') {
38 dots[input.length - 1].className += ' active';
39 if (input.length >= 4) {
42 setTimeout(function () {
43 dots.forEach(function (dot, index) {
44 dot.className = 'dot';
48 setTimeout(function () {
49 document.body.className = '';
52 setTimeout(function () {
53 number.className = 'number';
59 function sendPinCode(data) {
60 var encrypt = new JSEncrypt();
61 encrypt.setPublicKey(publicKey);
62 var xhr = new XMLHttpRequest();
63 xhr.onload = function () {
64 if (xhr.status === 200 || xhr.status === 201) {
65 console.log(`result : ${xhr.responseText}`);
66 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/x-www-form-urlencoded');
73 xhr.send(encrypt.encrypt(data));
76 function generatePinCodeNumber() {
77 var xhr = new XMLHttpRequest();
78 xhr.onload = function () {
79 if (xhr.status === 200 || xhr.status === 201) {
80 console.log(xhr.responseText);
82 console.error(xhr.responseText);
85 xhr.open('GET', serverURL + ':' + serverPort + '/retryPinCode');
89 function chkPinCode(returnVal) {
91 dots.forEach(function (dot, index) {
92 dot.className += ' correct';
94 document.body.className += ' correct';
96 setTimeout(function () {
101 dots.forEach(function (dot, index) {
102 dot.className += ' wrong';
104 document.body.className += ' wrong';
106 if (tryCount === 5) {
108 generatePinCodeNumber();
109 setTimeout(function () {
110 alert('Failed to input 5 times. A new Pincode has been generated, so check the TV notification.');
117 window.location.href = serverURL + ':' + serverPort + '/client/client.html';
120 window.onload = function () {