From daf1f8d2538385b08aa3a3da4806a134094bbb8a Mon Sep 17 00:00:00 2001 From: Rohan Sircar Date: Fri, 29 May 2020 13:04:22 +0530 Subject: [PATCH] Fixed login js Now correctly handles failed login attempts --- chatto/src/main/resources/static/js/login.js | 12 ++++++++---- chatto/src/main/resources/templates/home.html | 4 ---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/chatto/src/main/resources/static/js/login.js b/chatto/src/main/resources/static/js/login.js index 7f67a51..6e737c0 100644 --- a/chatto/src/main/resources/static/js/login.js +++ b/chatto/src/main/resources/static/js/login.js @@ -1,7 +1,9 @@ +var secondClick = false; + function storeCredentials() { let usernameInput = document.getElementById('username'); let passwordInput = document.getElementById('password'); - var jqxhr = $.ajax({ + let jqxhr = $.ajax({ type: 'GET', url: `/api/chat/get/token`, headers: { @@ -14,7 +16,7 @@ function storeCredentials() { localStorage.setItem('authToken', authToken); authToken = localStorage.getItem('authToken') console.log("getting header " + authToken); - secondClick = true; + // secondClick = true; $('#loginForm').submit(); }); @@ -22,16 +24,18 @@ function storeCredentials() { jqxhr.fail(function() { log.error('Error retrieving auth token'); alertify.error('Error retrieving auth token. Please log in again') + secondClick = false; + // setTimeout(() => location.reload(), 2000) }) localStorage.setItem('username', usernameInput.value); } -let secondClick = false; + $('#loginForm').on('submit', function(e) { if (!secondClick) { secondClick = true; e.preventDefault(); - storeCredentials(); + storeCredentials(secondClick); } // else { // secondClick = false; diff --git a/chatto/src/main/resources/templates/home.html b/chatto/src/main/resources/templates/home.html index 038b4a6..effbb0b 100644 --- a/chatto/src/main/resources/templates/home.html +++ b/chatto/src/main/resources/templates/home.html @@ -106,10 +106,6 @@ - \ No newline at end of file