From d3ef16b94768878846e16e14c5945563b92e8fdf Mon Sep 17 00:00:00 2001 From: Robbie Antenesse Date: Fri, 24 May 2019 11:34:11 -0600 Subject: [PATCH] Correctly sync dictionary on login and create account --- src/js/account/login.js | 6 ++++++ src/js/account/sync.js | 4 ++-- src/php/api/User.php | 2 +- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/js/account/login.js b/src/js/account/login.js index 298d241..a348df4 100644 --- a/src/js/account/login.js +++ b/src/js/account/login.js @@ -38,6 +38,7 @@ export function logIn() { loginModal.parentElement.removeChild(loginModal); triggerLoginChanges(); addMessage(`Welcome${window.account.publicName !== '' ? ', ' + window.account.publicName : ''}! You are logged in.`); + syncDictionary(); } }).catch(err => console.error(err)); } @@ -106,6 +107,11 @@ export function createAccount() { triggerLoginChanges(); addMessage('Account Created Successfully!'); addMessage(`Welcome${publicName !== '' ? ', ' + publicName : ''}! You are logged in.`); + if (window.currentDictionary.hasOwnProperty('externalID')) { + // Ensure dictionary uploads to overwrite the auto-created default dictionary + delete window.currentDictionary.externalID; + } + syncDictionary(false); } }); } diff --git a/src/js/account/sync.js b/src/js/account/sync.js index ed7066e..8f2e1ee 100644 --- a/src/js/account/sync.js +++ b/src/js/account/sync.js @@ -34,9 +34,9 @@ login -> upload anything that needs update */ -export function syncDictionary() { +export function syncDictionary(uploadAsNewIfNoExternalID = true) { if (!window.currentDictionary.hasOwnProperty('externalID')) { - uploadWholeDictionary(true); + uploadWholeDictionary(uploadAsNewIfNoExternalID); } else { addMessage('Syncing...'); request({ diff --git a/src/php/api/User.php b/src/php/api/User.php index 4163c61..2550443 100644 --- a/src/php/api/User.php +++ b/src/php/api/User.php @@ -194,7 +194,7 @@ VALUES (?, ?, ?, ?, ?)'; $user = $user_data->id; $dictionary = $user_data->dictionary; $details_updated = $this->dictionary->setDetails($user, $dictionary, $dictionary_data['details']); - $words_updated = $this->dictionary->setWords($dictionary, $dictionary_data['words']); + $words_updated = $this->dictionary->setWords($user, $dictionary, $dictionary_data['words']); if ($details_updated === true && $words_updated === true) { return $this->token->hash($dictionary); }