Misc updates

This commit is contained in:
Mo Bitar
2018-07-11 09:36:47 -05:00
parent b0850ed3e3
commit 7fc90ffd66
12 changed files with 62 additions and 55 deletions

View File

@@ -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) {

View File

@@ -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();
});
}

View File

@@ -36,7 +36,7 @@ class LockScreen {
return;
}
authManager.signout().then(() => {
authManager.signout(true).then(() => {
window.location.reload();
})
}

View File

@@ -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);

View File

@@ -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);

View File

@@ -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();
})
}

View File

@@ -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));
}
})
}
}

View File

@@ -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();

View File

@@ -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();
}

View File

@@ -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();

View File

@@ -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) {

View File

@@ -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) => {