From 7fc90ffd669380639736efcd585e043d79d9d1f3 Mon Sep 17 00:00:00 2001 From: Mo Bitar Date: Wed, 11 Jul 2018 09:36:47 -0500 Subject: [PATCH] Misc updates --- .../javascripts/app/controllers/editor.js | 43 ++++++++++--------- .../javascripts/app/controllers/home.js | 9 +++- .../javascripts/app/controllers/lockScreen.js | 2 +- .../javascripts/app/controllers/notes.js | 5 +-- .../javascripts/app/controllers/tags.js | 2 +- .../app/directives/views/accountMenu.js | 6 +-- .../app/directives/views/passwordWizard.js | 30 ++++++------- .../app/services/archiveManager.js | 2 +- .../javascripts/app/services/authManager.js | 4 +- .../app/services/desktopManager.js | 2 +- .../javascripts/app/services/modelManager.js | 8 ++++ .../app/services/passcodeManager.js | 4 -- 12 files changed, 62 insertions(+), 55 deletions(-) diff --git a/app/assets/javascripts/app/controllers/editor.js b/app/assets/javascripts/app/controllers/editor.js index f5e9cadf2..7753e524c 100644 --- a/app/assets/javascripts/app/controllers/editor.js +++ b/app/assets/javascripts/app/controllers/editor.js @@ -48,7 +48,7 @@ angular.module('app') } }) - modelManager.addItemSyncObserver("component-manager", "Note", (allItems, validItems, deletedItems, source) => { + modelManager.addItemSyncObserver("editor-note-observer", "Note", (allItems, validItems, deletedItems, source) => { if(!this.note) { return; } // Before checking if isMappingSourceRetrieved, we check if this item was deleted via a local source, @@ -75,7 +75,7 @@ angular.module('app') this.loadTagsString(); }); - modelManager.addItemSyncObserver("component-manager", "Tag", (allItems, validItems, deletedItems, source) => { + modelManager.addItemSyncObserver("editor-tag-observer", "Tag", (allItems, validItems, deletedItems, source) => { if(!this.note) { return; } for(var tag of allItems) { @@ -87,6 +87,25 @@ angular.module('app') } }); + // Observe editor changes to see if the current note should update its editor + + modelManager.addItemSyncObserver("editor-component-observer", "SN|Component", (allItems, validItems, deletedItems, source) => { + if(!this.note) { return; } + + var editors = allItems.filter(function(item) { + return item.isEditor(); + }); + + // If no editors have changed + if(editors.length == 0) { + return; + } + + // Look through editors again and find the most proper one + var editor = this.editorForNote(this.note); + this.selectedEditor = editor; + }); + this.noteDidChange = function(note, oldNote) { this.setNote(note, oldNote); this.reloadComponentContext(); @@ -95,6 +114,7 @@ angular.module('app') this.setNote = function(note, oldNote) { this.showExtensions = false; this.showMenu = false; + this.noteStatus = null; this.loadTagsString(); let onReady = () => { @@ -136,25 +156,6 @@ angular.module('app') } } - // Observe editor changes to see if the current note should update its editor - - modelManager.addItemSyncObserver("component-manager", "SN|Component", (allItems, validItems, deletedItems, source) => { - if(!this.note) { return; } - - var editors = allItems.filter(function(item) { - return item.isEditor(); - }); - - // If no editors have changed - if(editors.length == 0) { - return; - } - - // Look through editors again and find the most proper one - var editor = this.editorForNote(this.note); - this.selectedEditor = editor; - }); - this.editorForNote = function(note) { let editors = componentManager.componentsForArea("editor-editor"); for(var editor of editors) { diff --git a/app/assets/javascripts/app/controllers/home.js b/app/assets/javascripts/app/controllers/home.js index 0423f76f5..597f276c7 100644 --- a/app/assets/javascripts/app/controllers/home.js +++ b/app/assets/javascripts/app/controllers/home.js @@ -104,6 +104,13 @@ angular.module('app') syncManager.sync(); }, 30000); }); + + authManager.addEventHandler((event) => { + if(event == SFAuthManager.DidSignOutEvent) { + modelManager.handleSignout(); + syncManager.handleSignout(); + } + }) } function loadAllTag() { @@ -286,7 +293,7 @@ angular.module('app') return; } else { // sign out - authManager.signout().then(() => { + authManager.signout(true).then(() => { window.location.reload(); }); } diff --git a/app/assets/javascripts/app/controllers/lockScreen.js b/app/assets/javascripts/app/controllers/lockScreen.js index 4f3742d2b..e38eff9f6 100644 --- a/app/assets/javascripts/app/controllers/lockScreen.js +++ b/app/assets/javascripts/app/controllers/lockScreen.js @@ -36,7 +36,7 @@ class LockScreen { return; } - authManager.signout().then(() => { + authManager.signout(true).then(() => { window.location.reload(); }) } diff --git a/app/assets/javascripts/app/controllers/notes.js b/app/assets/javascripts/app/controllers/notes.js index 783871d24..c78e881c6 100644 --- a/app/assets/javascripts/app/controllers/notes.js +++ b/app/assets/javascripts/app/controllers/notes.js @@ -174,8 +174,7 @@ angular.module('app') } this.setNotes = function(notes) { - - notes.forEach(function(note){ + notes.forEach((note) => { note.visible = true; }) @@ -204,7 +203,7 @@ angular.module('app') this.createNewNote(); return; } - + this.selectedNote = note; note.conflict_of = null; // clear conflict this.selectionMade()(note); diff --git a/app/assets/javascripts/app/controllers/tags.js b/app/assets/javascripts/app/controllers/tags.js index 95aee80b3..bb9149f89 100644 --- a/app/assets/javascripts/app/controllers/tags.js +++ b/app/assets/javascripts/app/controllers/tags.js @@ -71,7 +71,7 @@ angular.module('app') this.selectTag(tag); } } else if(data.item.content_type == "SN|SmartTag") { - var tag = new SmartTag(data.item); + var tag = new SNSmartTag(data.item); Object.defineProperty(tag, "notes", { get: () => { return modelManager.notesMatchingPredicate(tag.content.predicate); diff --git a/app/assets/javascripts/app/directives/views/accountMenu.js b/app/assets/javascripts/app/directives/views/accountMenu.js index 4f2efa611..2eccf5222 100644 --- a/app/assets/javascripts/app/directives/views/accountMenu.js +++ b/app/assets/javascripts/app/directives/views/accountMenu.js @@ -14,8 +14,6 @@ class AccountMenu { 'ngInject'; $scope.formData = {mergeLocal: true, ephemeral: false}; - $scope.formData.email = "july2@bitar.io"; - $scope.formData.user_password = "password"; $scope.user = authManager.user; syncManager.getServerURL().then((url) => { @@ -153,7 +151,7 @@ class AccountMenu { $scope.clearDatabaseAndRewriteAllItems(true, block); } else { - modelManager.handleSignout(); + modelManager.removeAllItemsFromMemory(); storageManager.clearAllModels().then(() => { block(); }) @@ -183,7 +181,7 @@ class AccountMenu { return; } - authManager.signout().then(() => { + authManager.signout(true).then(() => { window.location.reload(); }) } diff --git a/app/assets/javascripts/app/directives/views/passwordWizard.js b/app/assets/javascripts/app/directives/views/passwordWizard.js index f6bfc294b..f953f6839 100644 --- a/app/assets/javascripts/app/directives/views/passwordWizard.js +++ b/app/assets/javascripts/app/directives/views/passwordWizard.js @@ -198,27 +198,25 @@ class PasswordWizard { }); } - $scope.processPasswordChange = function(callback) { + $scope.processPasswordChange = async function(callback) { let newUserPassword = $scope.securityUpdate ? $scope.formData.currentPassword : $scope.formData.newPassword; let currentServerPw = this.currentServerPw; - SFJS.crypto.generateInitialKeysAndAuthParamsForUser(authManager.user.email, newUserPassword).then((results) => { - let newKeys = results.keys; - let newAuthParams = results.authParams; + let results = await SFJS.crypto.generateInitialKeysAndAuthParamsForUser(authManager.user.email, newUserPassword); + let newKeys = results.keys; + let newAuthParams = results.authParams; - // perform a sync beforehand to pull in any last minutes changes before we change the encryption key (and thus cant decrypt new changes) - syncManager.sync().then((response) => { - authManager.changePassword(authManager.user.email, currentServerPw, newKeys, newAuthParams).then((response) => { - if(response.error) { - alert(response.error.message ? response.error.message : "There was an error changing your password. Please try again."); - $timeout(() => callback(false)); - } else { - $timeout(() => callback(true)); - } - }) - }) - }); + // perform a sync beforehand to pull in any last minutes changes before we change the encryption key (and thus cant decrypt new changes) + let syncResponse = await syncManager.sync(); + authManager.changePassword(await syncManager.getServerURL(), authManager.user.email, currentServerPw, newKeys, newAuthParams).then((response) => { + if(response.error) { + alert(response.error.message ? response.error.message : "There was an error changing your password. Please try again."); + $timeout(() => callback(false)); + } else { + $timeout(() => callback(true)); + } + }) } } diff --git a/app/assets/javascripts/app/services/archiveManager.js b/app/assets/javascripts/app/services/archiveManager.js index 741e3ee6a..8e4616a5b 100644 --- a/app/assets/javascripts/app/services/archiveManager.js +++ b/app/assets/javascripts/app/services/archiveManager.js @@ -12,7 +12,7 @@ class ArchiveManager { async downloadBackup(encrypted) { // download in Standard File format - var keys, authParams, protocolVersion; + var keys, authParams; if(encrypted) { if(this.authManager.offline() && this.passcodeManager.hasPasscode()) { keys = this.passcodeManager.keys(); diff --git a/app/assets/javascripts/app/services/authManager.js b/app/assets/javascripts/app/services/authManager.js index 89b99b163..a3a4dd880 100644 --- a/app/assets/javascripts/app/services/authManager.js +++ b/app/assets/javascripts/app/services/authManager.js @@ -88,8 +88,8 @@ class AuthManager extends SFAuthManager { }) } - async changePassword(email, current_server_pw, newKeys, newAuthParams) { - return super.changePassword(email, current_server_pw, newKeys, newAuthParams).then((response) => { + async changePassword(url, email, current_server_pw, newKeys, newAuthParams) { + return super.changePassword(url, email, current_server_pw, newKeys, newAuthParams).then((response) => { if(!response.error) { this.checkForSecurityUpdate(); } diff --git a/app/assets/javascripts/app/services/desktopManager.js b/app/assets/javascripts/app/services/desktopManager.js index e07153208..23612e64f 100644 --- a/app/assets/javascripts/app/services/desktopManager.js +++ b/app/assets/javascripts/app/services/desktopManager.js @@ -130,7 +130,7 @@ class DesktopManager { } async desktop_requestBackupFile(callback) { - var keys, authParams, protocolVersion; + var keys, authParams; if(this.authManager.offline() && this.passcodeManager.hasPasscode()) { keys = this.passcodeManager.keys(); authParams = this.passcodeManager.passcodeAuthParams(); diff --git a/app/assets/javascripts/app/services/modelManager.js b/app/assets/javascripts/app/services/modelManager.js index 6c4a6797e..ea5175b09 100644 --- a/app/assets/javascripts/app/services/modelManager.js +++ b/app/assets/javascripts/app/services/modelManager.js @@ -30,6 +30,14 @@ class ModelManager extends SFModelManager { this.components.length = 0; } + removeAllItemsFromMemory() { + for(var item of this.items) { + item.deleted = true; + } + this.notifySyncObserversOfModels(this.items); + this.handleSignout(); + } + findOrCreateTagByTitle(title) { var tag = _.find(this.tags, {title: title}) if(!tag) { diff --git a/app/assets/javascripts/app/services/passcodeManager.js b/app/assets/javascripts/app/services/passcodeManager.js index 587a61027..d70ffd2f1 100644 --- a/app/assets/javascripts/app/services/passcodeManager.js +++ b/app/assets/javascripts/app/services/passcodeManager.js @@ -26,10 +26,6 @@ angular.module('app') return JSON.parse(storageManager.getItemSync("offlineParams", StorageManager.Fixed)); } - this.protocolVersion = function() { - return this._authParams && this._authParams.version; - } - this.unlock = function(passcode, callback) { var params = this.passcodeAuthParams(); SFJS.crypto.computeEncryptionKeysForUser(passcode, params).then((keys) => {