var publicKey;
var input = '';
var dots = document.querySelectorAll('.dot'), numbers = document.querySelectorAll('.number');
-var tryCount = 0;
-function preloadKey() {
+function displayPincode() {
var xhr = new XMLHttpRequest();
- xhr.onload = function () {
+ xhr.onload = function() {
if (xhr.status === 200 || xhr.status === 201) {
publicKey = xhr.responseText;
- if (publicKey) {
- init();
- } else {
- console.error('[WT] Failed to get public key.');
- }
} else {
console.error(xhr.responseText);
}
function init() {
dots = Array.prototype.slice.call(dots);
numbers = Array.prototype.slice.call(numbers);
- numbers.forEach(function (number, index) {
- number.addEventListener('click', function () {
+ numbers.forEach(function(number, index) {
+ number.addEventListener('click', function() {
number.className += ' grow';
if (number.innerHTML === '0') {
input += 0;
console.log(`${TAG} input: ${input}`);
sendPinCode(input);
- setTimeout(function () {
- dots.forEach(function (dot, index) {
+ setTimeout(function() {
+ dots.forEach(function(dot, index) {
dot.className = 'dot';
});
input = '';
}, 900);
- setTimeout(function () {
+ setTimeout(function() {
document.body.className = '';
}, 1000);
}
- setTimeout(function () {
+ setTimeout(function() {
number.className = 'number';
}, 1000);
});
var encrypt = new JSEncrypt();
encrypt.setPublicKey(publicKey);
var xhr = new XMLHttpRequest();
- xhr.onload = function () {
+ xhr.onload = function() {
if (xhr.status === 200 || xhr.status === 201) {
console.log(`result : ${xhr.responseText}`);
- chkPinCode(xhr.responseText === 'true' ? true : false);
+ if (xhr.responseText === 'retry') {
+ retryPinCode();
+ } else {
+ chkPinCode(xhr.responseText === 'true' ? true : false);
+ }
} else {
console.error(xhr.responseText);
}
xhr.send(JSON.stringify({ pincode: data.toString("utf8") }));
}
-function generatePinCodeNumber() {
- var xhr = new XMLHttpRequest();
- xhr.onload = function () {
- if (xhr.status === 200 || xhr.status === 201) {
- console.log(xhr.responseText);
- } else {
- console.error(xhr.responseText);
- }
- };
- xhr.open('GET', serverURL + ':' + serverPort + '/retryPinCode');
- xhr.send();
+function retryPinCode() {
+ dots.forEach(function(dot, index) {
+ dot.className += ' wrong';
+ });
+ document.body.className += ' wrong';
+ displayPincode();
+ setTimeout(function() {
+ alert('Failed to input 5 times. A new Pincode has been generated, so check the TV notification.');
+ }, 1000);
}
function chkPinCode(returnVal) {
if (returnVal) {
- dots.forEach(function (dot, index) {
+ dots.forEach(function(dot, index) {
dot.className += ' correct';
});
document.body.className += ' correct';
- tryCount = 0;
- setTimeout(function () {
+ setTimeout(function() {
loginForm.submit();
- //pinCode();
}, 1000);
} else {
- dots.forEach(function (dot, index) {
+ dots.forEach(function(dot, index) {
dot.className += ' wrong';
});
document.body.className += ' wrong';
- tryCount++;
- if (tryCount === 5) {
- tryCount = 0;
- generatePinCodeNumber();
- setTimeout(function () {
- alert('Failed to input 5 times. A new Pincode has been generated, so check the TV notification.');
- }, 1000);
- }
}
}
window.location.href = serverURL + ':' + serverPort + '/client/client.html';
}
-window.onload = function () {
- preloadKey();
+window.onload = function() {
+ displayPincode();
+ init();
};