sync status, show credentials

This commit is contained in:
Mo Bitar
2017-01-28 22:44:40 -06:00
parent 5d9c1c3413
commit 46e9e91f46
5 changed files with 58 additions and 10 deletions

View File

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

View File

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

View File

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

View File

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

View File

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