protect tree will check if password is set and send user to options if not

This commit is contained in:
zadam 2021-12-30 23:55:36 +01:00
parent 8120f1bf25
commit a38ccde8bc
9 changed files with 51 additions and 8 deletions

View File

@ -5,7 +5,7 @@ import utils from "../services/utils.js";
const $dialog = $("#options-dialog");
export async function showDialog() {
export async function showDialog(openTab) {
const options = await server.get('options');
utils.openDialog($dialog);
@ -14,7 +14,7 @@ export async function showDialog() {
import('./options/appearance.js'),
import('./options/shortcuts.js'),
import('./options/code_notes.js'),
import('./options/credentials.js'),
import('./options/password.js'),
import('./options/backup.js'),
import('./options/sync.js'),
import('./options/other.js'),
@ -26,4 +26,8 @@ export async function showDialog() {
tab.optionsLoaded(options)
}
});
if (openTab) {
$(`.nav-link[href='#options-${openTab}']`).trigger("click");
}
}

View File

@ -32,7 +32,7 @@ const TPL = `
export default class ChangePasswordOptions {
constructor() {
$("#options-credentials").html(TPL);
$("#options-password").html(TPL);
this.$passwordHeading = $("#password-heading");
this.$form = $("#change-password-form");

View File

@ -0,0 +1,13 @@
import utils from "../services/utils.js";
import appContext from "../services/app_context.js";
export function show() {
const $dialog = $("#password-not-set-dialog");
const $openPasswordOptionsButton = $("#open-password-options-button");
utils.openDialog($dialog);
$openPasswordOptionsButton.on("click", () => {
appContext.triggerCommand("showOptions", { openTab: 'password' });
});
}

View File

@ -12,7 +12,7 @@ export function show() {
}
export function close() {
// this may fal if the dialog has not been previously opened (not sure if still true with Bootstrap modal)
// this may fail if the dialog has not been previously opened (not sure if still true with Bootstrap modal)
try {
$dialog.modal('hide');
}

View File

@ -5,6 +5,7 @@ import ws from "./ws.js";
import appContext from "./app_context.js";
import froca from "./froca.js";
import utils from "./utils.js";
import options from "./options.js";
let protectedSessionDeferred = null;
@ -18,6 +19,11 @@ async function leaveProtectedSession() {
function enterProtectedSession() {
const dfd = $.Deferred();
if (!options.is("isPasswordSet")) {
import("../dialogs/password_not_set.js").then(dialog => dialog.show());
return dfd;
}
if (protectedSessionHolder.isProtectedSessionAvailable()) {
dfd.resolve(false);
}

View File

@ -53,8 +53,8 @@ export default class RootCommandExecutor extends Component {
d.showDialog(branchIds);
}
showOptionsCommand() {
import("../dialogs/options.js").then(d => d.showDialog());
showOptionsCommand({openTab}) {
import("../dialogs/options.js").then(d => d.showDialog(openTab));
}
showHelpCommand() {

View File

@ -39,6 +39,7 @@
<%- include('dialogs/include_note.ejs') %>
<%- include('dialogs/sort_child_notes.ejs') %>
<%- include('dialogs/delete_notes.ejs') %>
<%- include('dialogs/password_not_set.ejs') %>
<script type="text/javascript">
global = globalThis; /* fixes https://github.com/webpack/webpack/issues/10035 */

View File

@ -20,7 +20,7 @@
<a class="nav-link" data-toggle="tab" href="#options-code-notes">Code notes</a>
</li>
<li class="nav-item">
<a class="nav-link" data-toggle="tab" href="#options-credentials">Password</a>
<a class="nav-link" data-toggle="tab" href="#options-password">Password</a>
</li>
<li class="nav-item">
<a class="nav-link" data-toggle="tab" href="#options-backup">Backup</a>
@ -40,7 +40,7 @@
<div id="options-appearance" class="tab-pane active"></div>
<div id="options-shortcuts" class="tab-pane"></div>
<div id="options-code-notes" class="tab-pane"></div>
<div id="options-credentials" class="tab-pane"></div>
<div id="options-password" class="tab-pane"></div>
<div id="options-backup" class="tab-pane"></div>
<div id="options-sync-setup" class="tab-pane"></div>
<div id="options-other" class="tab-pane"></div>

View File

@ -0,0 +1,19 @@
<div id="password-not-set-dialog" class="modal fade mx-auto" tabindex="-1" role="dialog">
<div class="modal-dialog modal-md" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title mr-auto">Password is not set</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close" style="margin-left: 0;">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
Protected notes are encrypted using a user password, but password has not been set yet.
To be able to protect notes, <a id="open-password-options-button" href="javascript:">
click here to open the Options dialog</a> and set your password.
</div>
</div>
</div>
</div>