fixed unloading the encrypted page after encryption timeout by simply reloading the app completely plus some unrelated refactorings

This commit is contained in:
azivner 2017-11-04 21:02:56 -04:00
parent 9c88fc6060
commit b192336113
6 changed files with 19 additions and 34 deletions

View File

@ -26,7 +26,7 @@ const settings = (function() {
tabsEl.tabs();
for (module of settingModules) {
for (const module of settingModules) {
module.settingsLoaded(settings);
}
}

View File

@ -22,10 +22,6 @@ const encryption = (function() {
encryptedDataKey = settings.encrypted_data_key;
});
function setEncryptionSalt(encSalt) {
encryptionSalt = encSalt;
}
function setEncryptedDataKey(encDataKey) {
encryptedDataKey = encDataKey;
}
@ -149,15 +145,9 @@ const encryption = (function() {
dataKey = null;
if (noteEditor.getCurrentNote().detail.encryption > 0) {
noteEditor.loadNoteToEditor(noteEditor.getCurrentNoteId());
for (const noteId of glob.allNoteIds) {
const note = getNodeByKey(noteId);
if (note.data.encryption > 0) {
note.setTitle("[encrypted]");
}
}
// most secure solution - guarantees nothing remained in memory
// since this expires because user doesn't use the app, it shouldn't be disruptive
window.location.reload(true);
}
}

View File

@ -11,7 +11,6 @@ const noteEditor = (function() {
const encryptionPasswordEl = $("#encryption-password");
let currentNote = null;
let currentNoteLoadTime = null;
let noteChangeDisabled = false;
@ -26,7 +25,7 @@ const noteEditor = (function() {
}
function getCurrentNoteLoadTime() {
return currentNoteLoadTime;
return currentNote ? currentNote.loadTime : null;
}
function noteChanged() {
@ -100,9 +99,6 @@ const noteEditor = (function() {
message("Saved!");
}
currentNote = null;
currentNoteLoadTime = null;
function createNewTopLevelNote() {
let rootNode = treeEl.fancytree("getRootNode");
@ -179,9 +175,7 @@ const noteEditor = (function() {
}
async function loadNoteToEditor(noteId) {
const note = await $.get(baseApiUrl + 'notes/' + noteId);
currentNote = note;
currentNoteLoadTime = Math.floor(new Date().getTime() / 1000);
currentNote = await $.get(baseApiUrl + 'notes/' + noteId);
if (newNoteCreated) {
newNoteCreated = false;
@ -189,7 +183,7 @@ const noteEditor = (function() {
noteTitleEl.focus().select();
}
await encryption.ensureEncryptionIsAvailable(note.detail.encryption > 0, false);
await encryption.ensureEncryptionIsAvailable(currentNote.detail.encryption > 0, false);
noteDetailWrapperEl.show();
@ -201,24 +195,24 @@ const noteEditor = (function() {
encryptionPasswordEl.val('');
encryption.decryptNoteIfNecessary(note);
encryption.decryptNoteIfNecessary(currentNote);
noteTitleEl.val(note.detail.note_title);
noteTitleEl.val(currentNote.detail.note_title);
noteChangeDisabled = true;
// Clear contents and remove all stored history. This is to prevent undo from going across notes
noteDetailEl.summernote('reset');
noteDetailEl.summernote('code', note.detail.note_text);
noteDetailEl.summernote('code', currentNote.detail.note_text);
document.location.hash = noteId;
recentNotes.addRecentNote(noteId, note.detail.note_id);
recentNotes.addRecentNote(noteId, currentNote.detail.note_id);
noteChangeDisabled = false;
setNoteBackgroundIfEncrypted(note);
setNoteBackgroundIfEncrypted(currentNote);
}
async function loadNote(noteId) {

View File

@ -12,7 +12,7 @@ const status = (function() {
data: JSON.stringify({
treeLoadTime: noteTree.getTreeLoadTime(),
currentNoteId: noteEditor.getCurrentNoteId(),
currentNoteDateModified: noteEditor.getCurrentNoteLoadTime()
currentNoteLoadTime: noteEditor.getCurrentNoteLoadTime()
}),
statusCode: {
401: () => {

View File

@ -21,8 +21,9 @@ router.get('/:noteId', auth.checkApiAuth, async (req, res, next) => {
}
res.send({
'detail': detail,
'images': await sql.getResults("select * from images where note_id = ? order by note_offset", [noteId])
detail: detail,
images: await sql.getResults("select * from images where note_id = ? order by note_offset", [noteId]),
loadTime: utils.nowTimestamp()
});
});

View File

@ -11,7 +11,7 @@ const audit_category = require('../../services/audit_category');
router.post('', auth.checkApiAuth, async (req, res, next) => {
const treeLoadTime = req.body.treeLoadTime;
const currentNoteId = req.body.currentNoteId;
const currentNoteDateModified = req.body.currentNoteDateModified;
const currentNoteLoadTime = req.body.currentNoteLoadTime;
const browserId = req.get('x-browser-id');
@ -20,13 +20,13 @@ router.post('', auth.checkApiAuth, async (req, res, next) => {
audit_category.UPDATE_TITLE, audit_category.CHANGE_PARENT, audit_category.CHANGE_POSITION]);
const currentNoteChangesCount = await sql.getSingleValue("SELECT COUNT(*) FROM audit_log WHERE (browser_id IS NULL OR browser_id != ?) " +
"AND date_modified >= ? AND note_id = ? AND category IN (?)", [browserId, currentNoteDateModified, currentNoteId,
"AND date_modified >= ? AND note_id = ? AND category IN (?)", [browserId, currentNoteLoadTime, currentNoteId,
audit_category.UPDATE_CONTENT]);
if (currentNoteChangesCount > 0) {
console.log("Current note changed!");
console.log("SELECT COUNT(*) FROM audit_log WHERE (browser_id IS NULL OR browser_id != '" + browserId + "') " +
"AND date_modified >= " + currentNoteDateModified + " AND note_id = '" + currentNoteId + "' AND category IN ('" + audit_category.UPDATE_CONTENT + "')");
"AND date_modified >= " + currentNoteLoadTime + " AND note_id = '" + currentNoteId + "' AND category IN ('" + audit_category.UPDATE_CONTENT + "')");
}
let changesToPushCount = 0;