Resave session history on passcode change
This commit is contained in:
@@ -440,6 +440,8 @@ class AccountMenu {
|
|||||||
|
|
||||||
fn(passcode, () => {
|
fn(passcode, () => {
|
||||||
$timeout(() => {
|
$timeout(() => {
|
||||||
|
$scope.formData.passcode = null;
|
||||||
|
$scope.formData.confirmPasscode = null;
|
||||||
$scope.formData.showPasscodeForm = false;
|
$scope.formData.showPasscodeForm = false;
|
||||||
var offline = authManager.offline();
|
var offline = authManager.offline();
|
||||||
|
|
||||||
@@ -457,7 +459,6 @@ class AccountMenu {
|
|||||||
$timeout(() => {
|
$timeout(() => {
|
||||||
$scope.formData.changingPasscode = true;
|
$scope.formData.changingPasscode = true;
|
||||||
$scope.addPasscodeClicked();
|
$scope.addPasscodeClicked();
|
||||||
$scope.formData.changingPasscode = false;
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -22,7 +22,9 @@ class RevisionPreviewModal {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$scope.$on("$destroy", function() {
|
$scope.$on("$destroy", function() {
|
||||||
componentManager.deregisterHandler($scope.identifier);
|
if($scope.identifier) {
|
||||||
|
componentManager.deregisterHandler($scope.identifier);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
$scope.note = new SFItem({content: $scope.content, content_type: "Note"});
|
$scope.note = new SFItem({content: $scope.content, content_type: "Note"});
|
||||||
|
|||||||
@@ -1,83 +1,20 @@
|
|||||||
class PasscodeManager {
|
class PasscodeManager {
|
||||||
|
|
||||||
constructor($rootScope, authManager, storageManager) {
|
constructor($rootScope, authManager, storageManager) {
|
||||||
if(isDesktopApplication()) {
|
|
||||||
// desktop only
|
|
||||||
$rootScope.$on("window-lost-focus", () => {
|
|
||||||
let visible = false;
|
|
||||||
this.documentVisibilityChanged(visible);
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
// tab visibility listender, web only
|
|
||||||
document.addEventListener('visibilitychange', (e) => {
|
|
||||||
let visible = document.visibilityState == "visible";
|
|
||||||
this.documentVisibilityChanged(visible);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
this.authManager = authManager;
|
this.authManager = authManager;
|
||||||
this.storageManager = storageManager;
|
this.storageManager = storageManager;
|
||||||
|
this.$rootScope = $rootScope;
|
||||||
|
|
||||||
this._hasPasscode = this.storageManager.getItemSync("offlineParams", StorageManager.Fixed) != null;
|
this._hasPasscode = this.storageManager.getItemSync("offlineParams", StorageManager.Fixed) != null;
|
||||||
this._locked = this._hasPasscode;
|
this._locked = this._hasPasscode;
|
||||||
|
|
||||||
const MillisecondsPerSecond = 1000;
|
this.passcodeChangeObservers = [];
|
||||||
PasscodeManager.AutoLockIntervalNone = 0;
|
|
||||||
PasscodeManager.AutoLockIntervalImmediate = 1;
|
|
||||||
PasscodeManager.AutoLockIntervalOneMinute = 60 * MillisecondsPerSecond;
|
|
||||||
PasscodeManager.AutoLockIntervalFiveMinutes = 300 * MillisecondsPerSecond;
|
|
||||||
PasscodeManager.AutoLockIntervalOneHour = 3600 * MillisecondsPerSecond;
|
|
||||||
|
|
||||||
PasscodeManager.AutoLockIntervalKey = "AutoLockIntervalKey";
|
this.configureAutoLock();
|
||||||
}
|
}
|
||||||
|
|
||||||
getAutoLockIntervalOptions() {
|
addPasscodeChangeObserver(callback) {
|
||||||
return [
|
this.passcodeChangeObservers.push(callback);
|
||||||
{
|
|
||||||
value: PasscodeManager.AutoLockIntervalNone,
|
|
||||||
label: "None"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
value: PasscodeManager.AutoLockIntervalImmediate,
|
|
||||||
label: "Immediately"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
value: PasscodeManager.AutoLockIntervalOneMinute,
|
|
||||||
label: "1 Min"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
value: PasscodeManager.AutoLockIntervalFiveMinutes,
|
|
||||||
label: "5 Min"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
value: PasscodeManager.AutoLockIntervalOneHour,
|
|
||||||
label: "1 Hr"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
documentVisibilityChanged(visible) {
|
|
||||||
if(!visible) {
|
|
||||||
this.beginAutoLockTimer();
|
|
||||||
} else {
|
|
||||||
this.cancelAutoLockTimer();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async beginAutoLockTimer() {
|
|
||||||
var interval = await this.getAutoLockInterval();
|
|
||||||
if(interval == PasscodeManager.AutoLockIntervalNone) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.lockTimeout = setTimeout(() => {
|
|
||||||
this.lockApplication();
|
|
||||||
}, interval);
|
|
||||||
}
|
|
||||||
|
|
||||||
cancelAutoLockTimer() {
|
|
||||||
clearTimeout(this.lockTimeout);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
lockApplication() {
|
lockApplication() {
|
||||||
@@ -171,6 +108,8 @@ class PasscodeManager {
|
|||||||
// After it's cleared, it's safe to write to it
|
// After it's cleared, it's safe to write to it
|
||||||
this.storageManager.setItem("offlineParams", JSON.stringify(authParams), StorageManager.Fixed);
|
this.storageManager.setItem("offlineParams", JSON.stringify(authParams), StorageManager.Fixed);
|
||||||
callback(true);
|
callback(true);
|
||||||
|
|
||||||
|
this.notifyObserversOfPasscodeChange();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -183,6 +122,14 @@ class PasscodeManager {
|
|||||||
this.storageManager.removeItem("offlineParams", StorageManager.Fixed);
|
this.storageManager.removeItem("offlineParams", StorageManager.Fixed);
|
||||||
this._keys = null;
|
this._keys = null;
|
||||||
this._hasPasscode = false;
|
this._hasPasscode = false;
|
||||||
|
|
||||||
|
this.notifyObserversOfPasscodeChange();
|
||||||
|
}
|
||||||
|
|
||||||
|
notifyObserversOfPasscodeChange() {
|
||||||
|
for(var observer of this.passcodeChangeObservers) {
|
||||||
|
observer();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
encryptLocalStorage(keys, authParams) {
|
encryptLocalStorage(keys, authParams) {
|
||||||
@@ -196,6 +143,79 @@ class PasscodeManager {
|
|||||||
this.storageManager.setKeys(keys, authParams);
|
this.storageManager.setKeys(keys, authParams);
|
||||||
return this.storageManager.decryptStorage();
|
return this.storageManager.decryptStorage();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
configureAutoLock() {
|
||||||
|
if(isDesktopApplication()) {
|
||||||
|
// desktop only
|
||||||
|
this.$rootScope.$on("window-lost-focus", () => {
|
||||||
|
let visible = false;
|
||||||
|
this.documentVisibilityChanged(visible);
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
// tab visibility listender, web only
|
||||||
|
document.addEventListener('visibilitychange', (e) => {
|
||||||
|
let visible = document.visibilityState == "visible";
|
||||||
|
this.documentVisibilityChanged(visible);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const MillisecondsPerSecond = 1000;
|
||||||
|
PasscodeManager.AutoLockIntervalNone = 0;
|
||||||
|
PasscodeManager.AutoLockIntervalImmediate = 1;
|
||||||
|
PasscodeManager.AutoLockIntervalOneMinute = 60 * MillisecondsPerSecond;
|
||||||
|
PasscodeManager.AutoLockIntervalFiveMinutes = 300 * MillisecondsPerSecond;
|
||||||
|
PasscodeManager.AutoLockIntervalOneHour = 3600 * MillisecondsPerSecond;
|
||||||
|
|
||||||
|
PasscodeManager.AutoLockIntervalKey = "AutoLockIntervalKey";
|
||||||
|
}
|
||||||
|
|
||||||
|
getAutoLockIntervalOptions() {
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
value: PasscodeManager.AutoLockIntervalNone,
|
||||||
|
label: "None"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
value: PasscodeManager.AutoLockIntervalImmediate,
|
||||||
|
label: "Immediately"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
value: PasscodeManager.AutoLockIntervalOneMinute,
|
||||||
|
label: "1 Min"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
value: PasscodeManager.AutoLockIntervalFiveMinutes,
|
||||||
|
label: "5 Min"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
value: PasscodeManager.AutoLockIntervalOneHour,
|
||||||
|
label: "1 Hr"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
documentVisibilityChanged(visible) {
|
||||||
|
if(!visible) {
|
||||||
|
this.beginAutoLockTimer();
|
||||||
|
} else {
|
||||||
|
this.cancelAutoLockTimer();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async beginAutoLockTimer() {
|
||||||
|
var interval = await this.getAutoLockInterval();
|
||||||
|
if(interval == PasscodeManager.AutoLockIntervalNone) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.lockTimeout = setTimeout(() => {
|
||||||
|
this.lockApplication();
|
||||||
|
}, interval);
|
||||||
|
}
|
||||||
|
|
||||||
|
cancelAutoLockTimer() {
|
||||||
|
clearTimeout(this.lockTimeout);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
angular.module('app').service('passcodeManager', PasscodeManager);
|
angular.module('app').service('passcodeManager', PasscodeManager);
|
||||||
|
|||||||
@@ -6,10 +6,17 @@ class SessionHistory extends SFSessionHistoryManager {
|
|||||||
"Note" : NoteHistoryEntry
|
"Note" : NoteHistoryEntry
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Session History can be encrypted with passcode keys. If it changes, we need to resave session
|
||||||
|
// history with the new keys.
|
||||||
|
passcodeManager.addPasscodeChangeObserver(() => {
|
||||||
|
this.saveToDisk();
|
||||||
|
})
|
||||||
|
|
||||||
var keyRequestHandler = async () => {
|
var keyRequestHandler = async () => {
|
||||||
let offline = authManager.offline();
|
let offline = authManager.offline();
|
||||||
let auth_params = offline ? passcodeManager.passcodeAuthParams() : await authManager.getAuthParams();
|
let auth_params = offline ? passcodeManager.passcodeAuthParams() : await authManager.getAuthParams();
|
||||||
let keys = offline ? passcodeManager.keys() : await authManager.keys();
|
let keys = offline ? passcodeManager.keys() : await authManager.keys();
|
||||||
|
|
||||||
return {
|
return {
|
||||||
keys: keys,
|
keys: keys,
|
||||||
offline: offline,
|
offline: offline,
|
||||||
|
|||||||
Reference in New Issue
Block a user