removed username/password from setup

This commit is contained in:
zadam 2021-12-28 22:59:38 +01:00
parent a910034c96
commit 7e48d214ca
5 changed files with 52 additions and 129 deletions

View File

@ -19,11 +19,6 @@ function SetupModel() {
this.setupSyncFromDesktop = ko.observable(false); this.setupSyncFromDesktop = ko.observable(false);
this.setupSyncFromServer = ko.observable(false); this.setupSyncFromServer = ko.observable(false);
this.username = ko.observable();
this.password1 = ko.observable();
this.password2 = ko.observable();
this.theme = ko.observable("light");
this.syncServerHost = ko.observable(); this.syncServerHost = ko.observable();
this.syncProxy = ko.observable(); this.syncProxy = ko.observable();
@ -32,7 +27,16 @@ function SetupModel() {
this.setupTypeSelected = () => !!this.setupType(); this.setupTypeSelected = () => !!this.setupType();
this.selectSetupType = () => { this.selectSetupType = () => {
if (this.setupType() === 'new-document') {
this.step('new-document-in-progress');
$.post('api/setup/new-document').then(() => {
window.location.replace("./setup");
});
}
else {
this.step(this.setupType()); this.step(this.setupType());
}
}; };
this.back = () => { this.back = () => {
@ -42,39 +46,6 @@ function SetupModel() {
}; };
this.finish = async () => { this.finish = async () => {
if (this.setupType() === 'new-document') {
const username = this.username();
const password1 = this.password1();
const password2 = this.password2();
const theme = this.theme();
if (!username) {
showAlert("Username can't be empty");
return;
}
if (!password1) {
showAlert("Password can't be empty");
return;
}
if (password1 !== password2) {
showAlert("Both password fields need be identical.");
return;
}
this.step('new-document-in-progress');
// not using server.js because it loads too many dependencies
$.post('api/setup/new-document', {
username: username,
password: password1,
theme: theme
}).then(() => {
window.location.replace("./setup");
});
}
else if (this.setupType() === 'sync-from-server') {
const syncServerHost = this.syncServerHost(); const syncServerHost = this.syncServerHost();
const syncProxy = this.syncProxy(); const syncProxy = this.syncProxy();
const username = this.username(); const username = this.username();
@ -113,7 +84,6 @@ function SetupModel() {
else { else {
showAlert('Sync setup failed: ' + resp.error); showAlert('Sync setup failed: ' + resp.error);
} }
}
}; };
} }

View File

@ -13,10 +13,8 @@ function getStatus() {
}; };
} }
async function setupNewDocument(req) { async function setupNewDocument() {
const { username, password, theme } = req.body; await sqlInit.createInitialDatabase();
await sqlInit.createInitialDatabase(username, password, theme);
} }
function setupSyncFromServer(req) { function setupSyncFromServer(req) {

View File

@ -12,9 +12,7 @@ function initDocumentOptions() {
optionService.createOption('documentSecret', utils.randomSecureToken(16), false); optionService.createOption('documentSecret', utils.randomSecureToken(16), false);
} }
function initSyncedOptions(username, password) { function initPassword(username, password) {
optionService.createOption('username', username, true);
optionService.createOption('passwordVerificationSalt', utils.randomSecureToken(32), true); optionService.createOption('passwordVerificationSalt', utils.randomSecureToken(32), true);
optionService.createOption('passwordDerivedKeySalt', utils.randomSecureToken(32), true); optionService.createOption('passwordDerivedKeySalt', utils.randomSecureToken(32), true);
@ -129,7 +127,7 @@ function getKeyboardDefaultOptions() {
module.exports = { module.exports = {
initDocumentOptions, initDocumentOptions,
initSyncedOptions, initPassword,
initNotSyncedOptions, initNotSyncedOptions,
initStartupOptions initStartupOptions
}; };

View File

@ -45,9 +45,7 @@ async function initDbConnection() {
dbReady.resolve(); dbReady.resolve();
} }
async function createInitialDatabase(username, password, theme) { async function createInitialDatabase() {
log.info("Creating database schema ...");
if (isDbInitialized()) { if (isDbInitialized()) {
throw new Error("DB is already initialized"); throw new Error("DB is already initialized");
} }
@ -57,9 +55,9 @@ async function createInitialDatabase(username, password, theme) {
let rootNote; let rootNote;
log.info("Creating root note ...");
sql.transactional(() => { sql.transactional(() => {
log.info("Creating database schema ...");
sql.executeScript(schema); sql.executeScript(schema);
require("../becca/becca_loader").load(); require("../becca/becca_loader").load();
@ -67,6 +65,8 @@ async function createInitialDatabase(username, password, theme) {
const Note = require("../becca/entities/note"); const Note = require("../becca/entities/note");
const Branch = require("../becca/entities/branch"); const Branch = require("../becca/entities/branch");
log.info("Creating root note ...");
rootNote = new Note({ rootNote = new Note({
noteId: 'root', noteId: 'root',
title: 'root', title: 'root',
@ -87,8 +87,7 @@ async function createInitialDatabase(username, password, theme) {
const optionsInitService = require('./options_init'); const optionsInitService = require('./options_init');
optionsInitService.initDocumentOptions(); optionsInitService.initDocumentOptions();
optionsInitService.initSyncedOptions(username, password); optionsInitService.initNotSyncedOptions(true, {});
optionsInitService.initNotSyncedOptions(true, { theme });
optionsInitService.initStartupOptions(); optionsInitService.initStartupOptions();
}); });

View File

@ -55,62 +55,20 @@
<div id="setup-type" data-bind="visible: step() == 'setup-type'" style="margin-top: 20px;"> <div id="setup-type" data-bind="visible: step() == 'setup-type'" style="margin-top: 20px;">
<div class="radio" style="margin-bottom: 15px;"> <div class="radio" style="margin-bottom: 15px;">
<label><input type="radio" name="setup-type" value="new-document" data-bind="checked: setupType"> <label><input type="radio" name="setup-type" value="new-document" data-bind="checked: setupType">
I'm a new user and I want to create new Trilium document for my notes</label> I'm a new user, and I want to create new Trilium document for my notes</label>
</div> </div>
<div class="radio" style="margin-bottom: 15px;"> <div class="radio" style="margin-bottom: 15px;">
<label><input type="radio" name="setup-type" value="sync-from-desktop" data-bind="checked: setupType"> <label><input type="radio" name="setup-type" value="sync-from-desktop" data-bind="checked: setupType">
I have desktop instance already and I want to setup sync with it</label> I have desktop instance already, and I want to set up sync with it</label>
</div> </div>
<div class="radio" style="margin-bottom: 15px;"> <div class="radio" style="margin-bottom: 15px;">
<label><input type="radio" name="setup-type" value="sync-from-server" data-bind="checked: setupType"> <label><input type="radio" name="setup-type" value="sync-from-server" data-bind="checked: setupType">
I have server instance already and I want to setup sync with it</label> I have server instance already, and I want to set up sync with it</label>
</div> </div>
<button type="button" data-bind="disable: !setupTypeSelected(), click: selectSetupType" class="btn btn-primary">Next</button> <button type="button" data-bind="disable: !setupTypeSelected(), click: selectSetupType" class="btn btn-primary">Next</button>
</div> </div>
<div data-bind="visible: step() == 'new-document'">
<h2>New document</h2>
<p>You're almost done with the setup. The last thing is to choose username and password using which you'll login to the application.
This password is also used for generating encryption key which encrypts protected notes.</p>
<div class="form-group">
<label for="username">Username</label>
<input type="text" class="form-control" data-bind="value: username" placeholder="Choose alphanumeric username">
</div>
<div class="form-group">
<label for="password1">Password</label>
<input type="password" class="form-control" data-bind="value: password1" placeholder="Password">
</div>
<div class="form-group">
<label for="password2">Repeat password</label>
<input type="password" class="form-control" data-bind="value: password2" placeholder="Password">
</div>
<div class="form-group">
<label for="password2">Theme</label>
<div style="display: flex; justify-content: space-around;">
<div class="form-check form-check-inline">
<input class="form-check-input" type="radio" name="theme" id="theme-light" value="light" data-bind="checked: theme" checked>
<label class="form-check-label" for="theme-light">light</label>
</div>
<div class="form-check form-check-inline">
<input class="form-check-input" type="radio" name="theme" id="theme-dark" value="dark" data-bind="checked: theme">
<label class="form-check-label" for="theme-dark">dark</label>
</div>
</div>
<p style="font-size: smaller;margin-top: 10px;"><em>Theme can be later changed in Options -> Appearance.</em></p>
</div>
<button type="button" data-bind="click: back" class="btn btn-secondary">Back</button>
&nbsp;
<button type="button" data-bind="click: finish" class="btn btn-primary">Finish setup</button>
</div>
<div data-bind="visible: step() == 'new-document-in-progress'"> <div data-bind="visible: step() == 'new-document-in-progress'">
<h2>Document initialization in progress</h2> <h2>Document initialization in progress</h2>