From 1a891cebd7c87eb8222ee1e228300f9397eba4e0 Mon Sep 17 00:00:00 2001 From: Robbie Antenesse Date: Wed, 4 Nov 2015 17:47:54 -0700 Subject: [PATCH] Separated confirmation from actions. Broke imports. Imports only work when logged out. They should work regardless of when they happen. --- index.php | 15 +++++++++------ js/dictionaryBuilder.js | 28 ++++++++++++++++++++-------- 2 files changed, 29 insertions(+), 14 deletions(-) diff --git a/index.php b/index.php index 02020dc..e018be6 100644 --- a/index.php +++ b/index.php @@ -10,7 +10,7 @@ if (isset($_GET['logout']) && $current_user > 0) { session_destroy(); header('Location: ./?loggedout'); } -elseif (isset($_GET['login'])) { +elseif (isset($_GET['login']) && $current_user <= 0) { if (isset($_POST['email']) && isset($_POST['password'])) { if (filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) { if (EmailExists($_POST['email'])) { @@ -45,7 +45,7 @@ elseif (isset($_GET['createaccount'])) { header('Location: ./?error=createemailorpasswordblank'); } } -elseif (isset($_GET['error'])) { +elseif (isset($_GET['error']) && $current_user <= 0) { if ($_GET['error'] == "couldnotcreate") { $notificationMessage = "Could not create account.
Please try again later."; } elseif ($_GET['error'] == "emailcreateinvalid") { @@ -73,10 +73,10 @@ elseif (isset($_GET['error'])) { $notificationMessage = "Something seems to have gone wrong, but I don't know what.
Please try again."; } } -elseif (isset($_GET['success'])) { +elseif (isset($_GET['success']) && $current_user <= 0) { $notificationMessage = "Your account was created successfully!
Please log in using the email address and password you used to create it and you can start accessing your dictionaries anywhere!"; } -elseif (isset($_GET['loggedout'])) { +elseif (isset($_GET['loggedout']) && $current_user <= 0) { $notificationMessage = "You have been successfully logged out.
You will only be able to use the dictionary saved to your browser."; } ?> @@ -218,9 +218,9 @@ elseif (isset($_GET['loggedout'])) { - +

@@ -252,6 +252,9 @@ elseif (isset($_GET['loggedout'])) { diff --git a/js/dictionaryBuilder.js b/js/dictionaryBuilder.js index f1d7529..58fbb16 100644 --- a/js/dictionaryBuilder.js +++ b/js/dictionaryBuilder.js @@ -523,15 +523,19 @@ function HideSettings() { document.getElementById("wordEntryForm").style.display = (currentDictionary.settings.isComplete) ? "none" : "block"; } -function EmptyWholeDictionary() { +function ConfirmEmptyWholeDictionary() { if (confirm("This will delete the entire current dictionary. If you do not have a backed up export, you will lose it forever!\n\nDo you still want to delete?")) { - currentDictionary = JSON.parse(defaultDictionaryJSON); - SaveAndUpdateDictionary(false, true); - SetPartsOfSpeech(); - HideSettings(); + EmptyWholeDictionary(); } } +function EmptyWholeDictionary() { + currentDictionary = JSON.parse(defaultDictionaryJSON); + SaveAndUpdateDictionary(false, true); + SetPartsOfSpeech(); + HideSettings(); +} + function SaveDictionary(sendToDatabase, sendWords) { localStorage.setItem('dictionary', JSON.stringify(currentDictionary)); @@ -565,6 +569,7 @@ function SendDictionary(sendWords) { console.log(sendDictionary.responseText); } else if (!isNaN(parseInt(sendDictionary.responseText))) { currentDictionary.externalID = parseInt(sendDictionary.responseText); + ProcessLoad(); console.log("saved successfully"); } else { console.log(sendDictionary.responseText); @@ -625,7 +630,6 @@ function LoadDictionary() { loadDictionary.responseText == "no info provided") { console.log(loadDictionary.responseText); } else { - console.log(loadDictionary.responseText); currentDictionary = JSON.parse(loadDictionary.responseText); SaveDictionary(false, false); ProcessLoad(); @@ -654,7 +658,7 @@ function LoadLocalDictionary() { function ProcessLoad() { HideSettingsWhenComplete(); - ShowDictionary(""); + ShowDictionary(); SetPartsOfSpeech(); @@ -686,6 +690,12 @@ function ExportDictionary() { download(downloadName + ".dict", localStorage.getItem('dictionary')); } +function ConfirmImportDictionary() { + if (confirm("Importing this dictionary will overwrite your current one, making it impossible to retrieve if you have not already exported it! Do you still want to import?")) { + ImportDictionary(); + } +} + function ImportDictionary() { if (!window.FileReader) { alert('Your browser is not supported'); @@ -703,7 +713,9 @@ function ImportDictionary() { if (reader.result.substr(reader.result.length - 40) == '"fileIdentifier":"Lexiconga Dictionary"}') { localStorage.setItem('dictionary', reader.result); document.getElementById("importFile").value = ""; - LoadDictionary(); + LoadLocalDictionary(); + SendDictionary(true); + ProcessLoad(); HideSettings(); } else { alert("Uploaded file is not compatible.");