From 46e9e91f463a2ff56632e8467121a565e9d250c9 Mon Sep 17 00:00:00 2001 From: Mo Bitar Date: Sat, 28 Jan 2017 22:44:40 -0600 Subject: [PATCH] sync status, show credentials --- .../javascripts/app/services/authManager.js | 7 +++--- .../services/directives/views/accountMenu.js | 12 +++++++-- .../javascripts/app/services/syncManager.js | 25 ++++++++++++++++--- app/assets/stylesheets/app/_header.scss | 14 ++++++++++- .../directives/account-menu.html.haml | 10 +++++++- 5 files changed, 58 insertions(+), 10 deletions(-) diff --git a/app/assets/javascripts/app/services/authManager.js b/app/assets/javascripts/app/services/authManager.js index f874b1a7d..f0976e1ee 100644 --- a/app/assets/javascripts/app/services/authManager.js +++ b/app/assets/javascripts/app/services/authManager.js @@ -79,7 +79,7 @@ angular.module('app.frontend') var params = {password: keys.pw, email: email}; _.merge(request, params); request.post().then(function(response){ - this.handleAuthResponse(response, email, url, authParams, mk); + this.handleAuthResponse(response, email, url, authParams, mk, keys.pw); callback(response); }.bind(this)) .catch(function(response){ @@ -90,11 +90,12 @@ angular.module('app.frontend') }.bind(this)) } - this.handleAuthResponse = function(response, email, url, authParams, mk) { + this.handleAuthResponse = function(response, email, url, authParams, mk, pw) { localStorage.setItem("server", url); localStorage.setItem("user", JSON.stringify(response.plain().user)); localStorage.setItem("auth_params", JSON.stringify(_.omit(authParams, ["pw_nonce"]))); localStorage.setItem("mk", mk); + localStorage.setItem("pw", pw); localStorage.setItem("jwt", response.token); } @@ -106,7 +107,7 @@ angular.module('app.frontend') var params = _.merge({password: keys.pw, email: email}, authParams); _.merge(request, params); request.post().then(function(response){ - this.handleAuthResponse(response, email, url, authParams, mk); + this.handleAuthResponse(response, email, url, authParams, mk, keys.pw); callback(response); }.bind(this)) .catch(function(response){ diff --git a/app/assets/javascripts/app/services/directives/views/accountMenu.js b/app/assets/javascripts/app/services/directives/views/accountMenu.js index dfc1a6457..34b18dc4f 100644 --- a/app/assets/javascripts/app/services/directives/views/accountMenu.js +++ b/app/assets/javascripts/app/services/directives/views/accountMenu.js @@ -19,6 +19,14 @@ class AccountMenu { $scope.showNewPasswordForm = !$scope.showNewPasswordForm; } + $scope.encryptionKey = function() { + return syncManager.masterKey; + } + + $scope.serverPassword = function() { + return syncManager.serverPassword; + } + $scope.submitPasswordChange = function() { $scope.passwordChangeData.status = "Generating New Keys..."; @@ -108,10 +116,10 @@ class AccountMenu { $scope.importData.loading = true; // allow loading indicator to come up with timeout $timeout(function(){ - $scope.importJSONData(data, password, function(success, response){ + $scope.importJSONData(data, password, function(response){ // console.log("Import response:", success, response); $scope.importData.loading = false; - if(success) { + if(response) { $scope.importData = null; } else { alert("There was an error importing your data. Please try again."); diff --git a/app/assets/javascripts/app/services/syncManager.js b/app/assets/javascripts/app/services/syncManager.js index 07cff13ec..035d69247 100644 --- a/app/assets/javascripts/app/services/syncManager.js +++ b/app/assets/javascripts/app/services/syncManager.js @@ -17,6 +17,10 @@ class SyncManager { return localStorage.getItem("mk"); } + get serverPassword() { + return localStorage.getItem("pw"); + } + writeItemsToLocalStorage(items, offlineOnly, callback) { var params = items.map(function(item) { var itemParams = new ItemParams(item, null); @@ -49,7 +53,7 @@ class SyncManager { }.bind(this)) if(callback) { - callback(); + callback({success: true}); } } @@ -66,7 +70,6 @@ class SyncManager { } set syncToken(token) { - console.log("setting token", token); this._syncToken = token; localStorage.setItem("syncToken", token); } @@ -78,6 +81,22 @@ class SyncManager { return this._syncToken; } + set cursorToken(token) { + this._cursorToken = token; + if(token) { + localStorage.setItem("cursorToken", token); + } else { + localStorage.removeItem("cursorToken"); + } + } + + get cursorToken() { + if(!this._cursorToken) { + this._cursorToken = localStorage.getItem("cursorToken"); + } + return this._cursorToken; + } + sync(callback, options = {}) { if(this.syncStatus.syncOpInProgress) { @@ -135,7 +154,6 @@ class SyncManager { this.modelManager.clearDirtyItems(subItems); this.syncStatus.error = null; - this.cursorToken = response.cursor_token; this.$rootScope.$broadcast("sync:updated_token", this.syncToken); @@ -154,6 +172,7 @@ class SyncManager { // set the sync token at the end, so that if any errors happen above, you can resync this.syncToken = response.sync_token; + this.cursorToken = response.cursor_token; if(this.cursorToken || this.repeatOnCompletion || this.needsMoreSync) { setTimeout(function () { diff --git a/app/assets/stylesheets/app/_header.scss b/app/assets/stylesheets/app/_header.scss index cee146988..cdd9582b3 100644 --- a/app/assets/stylesheets/app/_header.scss +++ b/app/assets/stylesheets/app/_header.scss @@ -76,6 +76,10 @@ display: block; } +.small-padding { + padding: 5px !important; +} + .medium-padding { padding: 10px !important; } @@ -84,6 +88,14 @@ padding-bottom: 4px !important; } +.pb-6 { + padding-bottom: 6px !important; +} + +.pb-10 { + padding-bottom: 10px !important; +} + .large-padding { padding: 22px !important; } @@ -178,7 +190,7 @@ } h4 { - margin-bottom: 0px !important; + margin-bottom: 4px !important; font-size: 13px !important; } diff --git a/app/assets/templates/frontend/directives/account-menu.html.haml b/app/assets/templates/frontend/directives/account-menu.html.haml index 726ab702d..029a84f12 100644 --- a/app/assets/templates/frontend/directives/account-menu.html.haml +++ b/app/assets/templates/frontend/directives/account-menu.html.haml @@ -28,10 +28,18 @@ %div{"ng-if" => "user"} %h2 {{user.email}} %p {{server}} + %a.block.mt-5{"ng-click" => "showCredentials = !showCredentials"} Show Credentials + %section.gray-bg.mt-10.medium-padding{"ng-if" => "showCredentials"} + %label.block + Encryption key: + %span.wrap.normal {{encryptionKey()}} + %label.block.mt-5 Server password: + %span.wrap {{serverPassword() ? serverPassword() : 'Not available. Sign out then sign back in to compute.'}} %div.bold.mt-10.blue{"delay-hide" => "true", "show" => "syncStatus.syncOpInProgress", "delay" => "1000"} .spinner.inline.mr-5.blue - Syncing: {{syncStatus.current}}/{{syncStatus.total}} + Syncing + %span{"ng-if" => "syncStatus.total > 0"}: {{syncStatus.current}}/{{syncStatus.total}} %p.bold.mt-10.red.block{"ng-if" => "syncStatus.error"} Error syncing: {{syncStatus.error.message}} .medium-v-space