Correctly sync dictionary on login and create account

This commit is contained in:
Robbie Antenesse 2019-05-24 11:34:11 -06:00
parent 33e9193abb
commit d3ef16b947
3 changed files with 9 additions and 3 deletions

View File

@ -38,6 +38,7 @@ export function logIn() {
loginModal.parentElement.removeChild(loginModal); loginModal.parentElement.removeChild(loginModal);
triggerLoginChanges(); triggerLoginChanges();
addMessage(`Welcome${window.account.publicName !== '' ? ', ' + window.account.publicName : ''}! You are logged in.`); addMessage(`Welcome${window.account.publicName !== '' ? ', ' + window.account.publicName : ''}! You are logged in.`);
syncDictionary();
} }
}).catch(err => console.error(err)); }).catch(err => console.error(err));
} }
@ -106,6 +107,11 @@ export function createAccount() {
triggerLoginChanges(); triggerLoginChanges();
addMessage('Account Created Successfully!'); addMessage('Account Created Successfully!');
addMessage(`Welcome${publicName !== '' ? ', ' + publicName : ''}! You are logged in.`); 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);
} }
}); });
} }

View File

@ -34,9 +34,9 @@ login
-> upload anything that needs update -> upload anything that needs update
*/ */
export function syncDictionary() { export function syncDictionary(uploadAsNewIfNoExternalID = true) {
if (!window.currentDictionary.hasOwnProperty('externalID')) { if (!window.currentDictionary.hasOwnProperty('externalID')) {
uploadWholeDictionary(true); uploadWholeDictionary(uploadAsNewIfNoExternalID);
} else { } else {
addMessage('Syncing...'); addMessage('Syncing...');
request({ request({

View File

@ -194,7 +194,7 @@ VALUES (?, ?, ?, ?, ?)';
$user = $user_data->id; $user = $user_data->id;
$dictionary = $user_data->dictionary; $dictionary = $user_data->dictionary;
$details_updated = $this->dictionary->setDetails($user, $dictionary, $dictionary_data['details']); $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) { if ($details_updated === true && $words_updated === true) {
return $this->token->hash($dictionary); return $this->token->hash($dictionary);
} }