Separated confirmation from actions. Broke imports.

Imports only work when logged out. They should work regardless of when they happen.
This commit is contained in:
Robbie Antenesse 2015-11-04 17:47:54 -07:00
parent dd3783be5c
commit 1a891cebd7
2 changed files with 29 additions and 14 deletions

View File

@ -10,7 +10,7 @@ if (isset($_GET['logout']) && $current_user > 0) {
session_destroy(); session_destroy();
header('Location: ./?loggedout'); header('Location: ./?loggedout');
} }
elseif (isset($_GET['login'])) { elseif (isset($_GET['login']) && $current_user <= 0) {
if (isset($_POST['email']) && isset($_POST['password'])) { if (isset($_POST['email']) && isset($_POST['password'])) {
if (filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) { if (filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
if (EmailExists($_POST['email'])) { if (EmailExists($_POST['email'])) {
@ -45,7 +45,7 @@ elseif (isset($_GET['createaccount'])) {
header('Location: ./?error=createemailorpasswordblank'); header('Location: ./?error=createemailorpasswordblank');
} }
} }
elseif (isset($_GET['error'])) { elseif (isset($_GET['error']) && $current_user <= 0) {
if ($_GET['error'] == "couldnotcreate") { if ($_GET['error'] == "couldnotcreate") {
$notificationMessage = "Could not create account.<br>Please try again later."; $notificationMessage = "Could not create account.<br>Please try again later.";
} elseif ($_GET['error'] == "emailcreateinvalid") { } 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.<br>Please try again."; $notificationMessage = "Something seems to have gone wrong, but I don't know what.<br>Please try again.";
} }
} }
elseif (isset($_GET['success'])) { elseif (isset($_GET['success']) && $current_user <= 0) {
$notificationMessage = "Your account was created successfully!<br>Please log in using the email address and password you used to create it and you can start accessing your dictionaries anywhere!"; $notificationMessage = "Your account was created successfully!<br>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.<br>You will only be able to use the dictionary saved to your browser."; $notificationMessage = "You have been successfully logged out.<br>You will only be able to use the dictionary saved to your browser.";
} }
?> ?>
@ -218,9 +218,9 @@ elseif (isset($_GET['loggedout'])) {
<label> <label>
<span>Import Dictionary</span> <span>Import Dictionary</span>
<input type="file" id="importFile" /> <input type="file" id="importFile" />
<button type="button" onclick="ImportDictionary(); return false;">Import</button> <button type="button" onclick="ConfirmImportDictionary(); return false;">Import</button>
</label> </label>
<label><button type="button" onclick="EmptyWholeDictionary()" style="cursor:pointer;">Empty Current Dictionary</button></label> <label><button type="button" onclick="ConfirmEmptyWholeDictionary()" style="cursor:pointer;">Empty Current Dictionary</button></label>
</div> </div>
<div id="settingsSaveButtons"> <div id="settingsSaveButtons">
<span id="settingsErrorMessage"></span><br> <span id="settingsErrorMessage"></span><br>
@ -252,6 +252,9 @@ elseif (isset($_GET['loggedout'])) {
<script> <script>
currentUser = <?php echo $current_user; ?>; currentUser = <?php echo $current_user; ?>;
publicName = "<?php echo Get_Public_Name($current_user); ?>"; publicName = "<?php echo Get_Public_Name($current_user); ?>";
<?php if (isset($_GET['loggedout']) && $current_user <= 0) { ?>
EmptyWholeDictionary();
<?php } ?>
</script> </script>
<?php //include_once("php/google/analytics.php"); ?> <?php //include_once("php/google/analytics.php"); ?>
</body> </body>

View File

@ -523,15 +523,19 @@ function HideSettings() {
document.getElementById("wordEntryForm").style.display = (currentDictionary.settings.isComplete) ? "none" : "block"; 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?")) { 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); EmptyWholeDictionary();
SaveAndUpdateDictionary(false, true);
SetPartsOfSpeech();
HideSettings();
} }
} }
function EmptyWholeDictionary() {
currentDictionary = JSON.parse(defaultDictionaryJSON);
SaveAndUpdateDictionary(false, true);
SetPartsOfSpeech();
HideSettings();
}
function SaveDictionary(sendToDatabase, sendWords) { function SaveDictionary(sendToDatabase, sendWords) {
localStorage.setItem('dictionary', JSON.stringify(currentDictionary)); localStorage.setItem('dictionary', JSON.stringify(currentDictionary));
@ -565,6 +569,7 @@ function SendDictionary(sendWords) {
console.log(sendDictionary.responseText); console.log(sendDictionary.responseText);
} else if (!isNaN(parseInt(sendDictionary.responseText))) { } else if (!isNaN(parseInt(sendDictionary.responseText))) {
currentDictionary.externalID = parseInt(sendDictionary.responseText); currentDictionary.externalID = parseInt(sendDictionary.responseText);
ProcessLoad();
console.log("saved successfully"); console.log("saved successfully");
} else { } else {
console.log(sendDictionary.responseText); console.log(sendDictionary.responseText);
@ -625,7 +630,6 @@ function LoadDictionary() {
loadDictionary.responseText == "no info provided") { loadDictionary.responseText == "no info provided") {
console.log(loadDictionary.responseText); console.log(loadDictionary.responseText);
} else { } else {
console.log(loadDictionary.responseText);
currentDictionary = JSON.parse(loadDictionary.responseText); currentDictionary = JSON.parse(loadDictionary.responseText);
SaveDictionary(false, false); SaveDictionary(false, false);
ProcessLoad(); ProcessLoad();
@ -654,7 +658,7 @@ function LoadLocalDictionary() {
function ProcessLoad() { function ProcessLoad() {
HideSettingsWhenComplete(); HideSettingsWhenComplete();
ShowDictionary(""); ShowDictionary();
SetPartsOfSpeech(); SetPartsOfSpeech();
@ -686,6 +690,12 @@ function ExportDictionary() {
download(downloadName + ".dict", localStorage.getItem('dictionary')); 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() { function ImportDictionary() {
if (!window.FileReader) { if (!window.FileReader) {
alert('Your browser is not supported'); alert('Your browser is not supported');
@ -703,7 +713,9 @@ function ImportDictionary() {
if (reader.result.substr(reader.result.length - 40) == '"fileIdentifier":"Lexiconga Dictionary"}') { if (reader.result.substr(reader.result.length - 40) == '"fileIdentifier":"Lexiconga Dictionary"}') {
localStorage.setItem('dictionary', reader.result); localStorage.setItem('dictionary', reader.result);
document.getElementById("importFile").value = ""; document.getElementById("importFile").value = "";
LoadDictionary(); LoadLocalDictionary();
SendDictionary(true);
ProcessLoad();
HideSettings(); HideSettings();
} else { } else {
alert("Uploaded file is not compatible."); alert("Uploaded file is not compatible.");