account menu complete
This commit is contained in:
@@ -32,11 +32,10 @@ angular.module('app.frontend')
|
||||
this.updateOfflineStatus();
|
||||
|
||||
this.findErrors = function() {
|
||||
this.error = syncManager.error;
|
||||
this.error = syncManager.syncStatus.error;
|
||||
}
|
||||
this.findErrors();
|
||||
|
||||
|
||||
this.accountMenuPressed = function() {
|
||||
this.serverData = {};
|
||||
this.showAccountMenu = !this.showAccountMenu;
|
||||
|
||||
@@ -92,7 +92,7 @@ angular.module('app.frontend')
|
||||
|
||||
this.handleAuthResponse = function(response, email, url, authParams, mk) {
|
||||
localStorage.setItem("server", url);
|
||||
localStorage.setItem("user", JSON.stringify(response.plain()));
|
||||
localStorage.setItem("user", JSON.stringify(response.plain().user));
|
||||
localStorage.setItem("auth_params", JSON.stringify(_.omit(authParams, ["pw_nonce"])));
|
||||
localStorage.setItem("mk", mk);
|
||||
localStorage.setItem("jwt", response.token);
|
||||
@@ -243,10 +243,8 @@ angular.module('app.frontend')
|
||||
items: items
|
||||
}
|
||||
|
||||
if(ek.name == SNKeyName) {
|
||||
// auth params are only needed when encrypted with a standard file key
|
||||
data["auth_params"] = this.getAuthParams();
|
||||
}
|
||||
// auth params are only needed when encrypted with a standard file key
|
||||
data["auth_params"] = this.getAuthParams();
|
||||
|
||||
return makeTextFile(JSON.stringify(data, null, 2 /* pretty print */));
|
||||
}
|
||||
|
||||
@@ -11,6 +11,9 @@ class AccountMenu {
|
||||
|
||||
$scope.formData = {url: syncManager.serverURL};
|
||||
$scope.user = authManager.user;
|
||||
$scope.server = syncManager.serverURL;
|
||||
|
||||
$scope.syncStatus = syncManager.syncStatus;
|
||||
|
||||
$scope.changePasswordPressed = function() {
|
||||
$scope.showNewPasswordForm = !$scope.showNewPasswordForm;
|
||||
@@ -37,14 +40,14 @@ class AccountMenu {
|
||||
console.log("logging in with url", $scope.formData.url);
|
||||
$timeout(function(){
|
||||
authManager.login($scope.formData.url, $scope.formData.email, $scope.formData.user_password, function(response){
|
||||
$scope.formData.status = null;
|
||||
if(!response || response.error) {
|
||||
$scope.formData.status = null;
|
||||
var error = response ? response.error : {message: "An unknown error occured."}
|
||||
if(!response || (response && !response.didDisplayAlert)) {
|
||||
alert(error.message);
|
||||
}
|
||||
} else {
|
||||
window.location.reload();
|
||||
$scope.onAuthSuccess();
|
||||
}
|
||||
});
|
||||
})
|
||||
@@ -55,17 +58,23 @@ class AccountMenu {
|
||||
|
||||
$timeout(function(){
|
||||
authManager.register($scope.formData.url, $scope.formData.email, $scope.formData.user_password, function(response){
|
||||
$scope.formData.status = null;
|
||||
if(!response || response.error) {
|
||||
$scope.formData.status = null;
|
||||
var error = response ? response.error : {message: "An unknown error occured."}
|
||||
alert(error.message);
|
||||
} else {
|
||||
window.location.reload();
|
||||
$scope.onAuthSuccess();
|
||||
}
|
||||
});
|
||||
})
|
||||
}
|
||||
|
||||
$scope.onAuthSuccess = function() {
|
||||
syncManager.markAllItemsDirtyAndSaveOffline(function(){
|
||||
window.location.reload();
|
||||
})
|
||||
}
|
||||
|
||||
$scope.destroyLocalData = function() {
|
||||
if(!confirm("Are you sure you want to end your session? This will delete all local items and extensions.")) {
|
||||
return;
|
||||
@@ -79,24 +88,16 @@ class AccountMenu {
|
||||
|
||||
/* Import/Export */
|
||||
|
||||
$scope.archiveFormData = {encryption_type: $scope.user ? 'mk' : 'ek'};
|
||||
$scope.archiveFormData = {encrypted: $scope.user ? true : false};
|
||||
$scope.user = authManager.user;
|
||||
|
||||
$scope.downloadDataArchive = function() {
|
||||
if($scope.archiveFormData.encryption_type == 'ek') {
|
||||
if(!$scope.archiveFormData.ek) {
|
||||
alert("You must set an encryption key to export the data encrypted.")
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
var link = document.createElement('a');
|
||||
link.setAttribute('download', 'notes.json');
|
||||
|
||||
var ek = $scope.archiveFormData.encryption_type == 'ek' ? $scope.archiveFormData.ek : null;
|
||||
var encrypted = $scope.archiveFormData.encryption_type != 'none';
|
||||
var ek = $scope.archiveFormData.encrypted ? syncManager.masterKey : null;
|
||||
|
||||
link.href = authManager.itemsDataFile(encrypted, ek);
|
||||
link.href = authManager.itemsDataFile(ek);
|
||||
link.click();
|
||||
}
|
||||
|
||||
|
||||
@@ -13,6 +13,10 @@ class SyncManager {
|
||||
return localStorage.getItem("server") || "http://localhost:3000";
|
||||
}
|
||||
|
||||
get masterKey() {
|
||||
return localStorage.getItem("mk");
|
||||
}
|
||||
|
||||
writeItemsToLocalStorage(items, offlineOnly, callback) {
|
||||
var params = items.map(function(item) {
|
||||
var itemParams = new ItemParams(item, null);
|
||||
@@ -49,13 +53,21 @@ class SyncManager {
|
||||
}
|
||||
}
|
||||
|
||||
markAllItemsDirtyAndSaveOffline(callback) {
|
||||
var items = this.modelManager.allItems;
|
||||
for(var item of items) {
|
||||
item.setDirty(true);
|
||||
}
|
||||
this.writeItemsToLocalStorage(items, false, callback);
|
||||
}
|
||||
|
||||
get syncURL() {
|
||||
return this.serverURL + "/items/sync";
|
||||
}
|
||||
|
||||
sync(callback, options = {}) {
|
||||
|
||||
if(this.syncOpInProgress) {
|
||||
if(this.syncStatus.syncOpInProgress) {
|
||||
this.repeatOnCompletion = true;
|
||||
console.log("Sync op in progress; returning.");
|
||||
return;
|
||||
@@ -74,7 +86,7 @@ class SyncManager {
|
||||
var isContinuationSync = this.needsMoreSync;
|
||||
|
||||
this.repeatOnCompletion = false;
|
||||
this.syncOpInProgress = true;
|
||||
this.syncStatus.syncOpInProgress = true;
|
||||
|
||||
let submitLimit = 100;
|
||||
var subItems = allDirtyItems.slice(0, submitLimit);
|
||||
@@ -103,7 +115,7 @@ class SyncManager {
|
||||
|
||||
request.post().then(function(response) {
|
||||
this.modelManager.clearDirtyItems(subItems);
|
||||
this.error = null;
|
||||
this.syncStatus.error = null;
|
||||
this.syncToken = response.sync_token;
|
||||
this.cursorToken = response.cursor_token;
|
||||
|
||||
@@ -119,7 +131,7 @@ class SyncManager {
|
||||
this.writeItemsToLocalStorage(saved, false, null);
|
||||
this.writeItemsToLocalStorage(retrieved, false, null);
|
||||
|
||||
this.syncOpInProgress = false;
|
||||
this.syncStatus.syncOpInProgress = false;
|
||||
this.syncStatus.current += subItems.length;
|
||||
|
||||
if(this.cursorToken || this.repeatOnCompletion || this.needsMoreSync) {
|
||||
@@ -135,8 +147,8 @@ class SyncManager {
|
||||
console.log("Sync error: ", response);
|
||||
var error = response.data ? response.data.error : {message: "Could not connect to server."};
|
||||
|
||||
this.syncOpInProgress = false;
|
||||
this.error = error;
|
||||
this.syncStatus.syncOpInProgress = false;
|
||||
this.syncStatus.error = error;
|
||||
this.writeItemsToLocalStorage(allDirtyItems, false, null);
|
||||
|
||||
this.$rootScope.$broadcast("sync:error", error);
|
||||
|
||||
Reference in New Issue
Block a user