$('#username, #password').keypress(function(e){ var key = e.which; if (key == 13) { loginAuth(); } }); function registerAuth() { $('#loginstatus').text("You've signed up! Logging in, please wait..."); var account = new Object(); account.username = $('#username').val(); account.firstname = $('#firstname').val(); account.midname = $('#midname').val(); account.lastname = $('#lastname').val(); account.password = $('#password').val(); account.address1 = $('#address1').val(); account.address2 = $('#address2').val(); account.city = $('#city').val(); account.statecode = $('#statecode').val(); account.zipcode = $('#zipcode').val(); account.phone = $('#phone').val(); account.email = $('#email').val(); var sessionUsername = $('#username').val(); $.ajax({ url: "https://i09nc14c1m.execute-api.us-east-1.amazonaws.com/signup/register", method: "POST", crossDomain: true, contentType: "application/json", data: JSON.stringify(account), success: function(data) { if (typeof(Storage) !== "undefined") { sessionStorage.setItem("username", sessionUsername); sessionStorage.setItem("admin", false); location.replace("dashboard.html"); // Redirect to the dashboard page } else { $('#errorMsg').text('Your current browser version or browser type is not supported with HTML5 session'); } }, error: function(jqXhr, textStatus, errorMessage) { $('#errorMsg').text('Error: ' + errorMessage + ' // Please refresh and try again.'); } }); } function loginAuth() { $('#loginstatus').text("You're being logged in, please wait..."); var account = new Object(); account.username = $('#username').val(); account.password = $('#password').val(); var sessionUsername = $('#username').val(); $.ajax({ url: "https://e1njwqu035.execute-api.us-east-1.amazonaws.com/loginStage/login", method: "POST", crossDomain: true, contentType: "application/json", data: JSON.stringify(account), success: function(data) { var record = data.recordset; if (data == "true") { if (typeof(Storage) !== "undefined") { var adminStatus = "You are the admin."; var isAdmin = "block"; sessionStorage.setItem("username", sessionUsername); sessionStorage.setItem("adminStatus", adminStatus); sessionStorage.setItem("isAdmin", isAdmin); //sessionStorage.setItem("username", record.Username); location.replace("dashboard.html"); // Redirect to the dashboard page } else { $('#errorMsg').text('Your current browser version or browser type is not supported with HTML5 session'); } } else if (data == "regularUser") { if (typeof(Storage) !== "undefined") { var adminStatus = "You are the regular user."; var isAdmin = "none"; sessionStorage.setItem("username", sessionUsername); sessionStorage.setItem("adminStatus", adminStatus); sessionStorage.setItem("isAdmin", isAdmin); //sessionStorage.setItem("username", record.Username); location.replace("dashboard.html"); // Redirect to the dashboard page } else { $('#errorMsg').text('Your current browser version or browser type is not supported with HTML5 session'); } } else { // error $('#loginerror').text('Incorrect login information. Try again please.'); } }, error: function(jqXhr, textStatus, errorMessage) { $('#errorMsg').text('Error: ' + errorMessage + ' // Please refresh and try again.'); } }); } /* function session() { $.ajax({ url: "", type: "GET", success: function(data) { if (typeof(Storage) !== "undefined") { if (sessionStorage.getItem("username") == null) { location.replace("login.html"); } } else { $('#errorMsg').text('Your current browser version or browser type is not supported with HTML5 session'); } }, error: function(jqXhr, textStatus, errorMessage) { $('#errorMsg').text('Error: ' + errorMessage); } }); }*/