diff --git a/src/public/app/setup.js b/src/public/app/setup.js index 288b69eb3..c378d148d 100644 --- a/src/public/app/setup.js +++ b/src/public/app/setup.js @@ -19,11 +19,6 @@ function SetupModel() { this.setupSyncFromDesktop = 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.syncProxy = ko.observable(); @@ -32,7 +27,16 @@ function SetupModel() { this.setupTypeSelected = () => !!this.setupType(); this.selectSetupType = () => { - this.step(this.setupType()); + 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.back = () => { @@ -42,77 +46,43 @@ function SetupModel() { }; this.finish = async () => { - if (this.setupType() === 'new-document') { - const username = this.username(); - const password1 = this.password1(); - const password2 = this.password2(); - const theme = this.theme(); + const syncServerHost = this.syncServerHost(); + const syncProxy = this.syncProxy(); + const username = this.username(); + const password = this.password1(); - 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"); - }); + if (!syncServerHost) { + showAlert("Trilium server address can't be empty"); + return; } - else if (this.setupType() === 'sync-from-server') { - const syncServerHost = this.syncServerHost(); - const syncProxy = this.syncProxy(); - const username = this.username(); - const password = this.password1(); - if (!syncServerHost) { - showAlert("Trilium server address can't be empty"); - return; - } + if (!username) { + showAlert("Username can't be empty"); + return; + } - if (!username) { - showAlert("Username can't be empty"); - return; - } + if (!password) { + showAlert("Password can't be empty"); + return; + } - if (!password) { - showAlert("Password can't be empty"); - return; - } + // not using server.js because it loads too many dependencies + const resp = await $.post('api/setup/sync-from-server', { + syncServerHost: syncServerHost, + syncProxy: syncProxy, + username: username, + password: password + }); - // not using server.js because it loads too many dependencies - const resp = await $.post('api/setup/sync-from-server', { - syncServerHost: syncServerHost, - syncProxy: syncProxy, - username: username, - password: password - }); + if (resp.result === 'success') { + this.step('sync-in-progress'); - if (resp.result === 'success') { - this.step('sync-in-progress'); + setInterval(checkOutstandingSyncs, 1000); - setInterval(checkOutstandingSyncs, 1000); - - hideAlert(); - } - else { - showAlert('Sync setup failed: ' + resp.error); - } + hideAlert(); + } + else { + showAlert('Sync setup failed: ' + resp.error); } }; } diff --git a/src/routes/api/setup.js b/src/routes/api/setup.js index d2ec74b2e..e0ba3ef0a 100644 --- a/src/routes/api/setup.js +++ b/src/routes/api/setup.js @@ -13,10 +13,8 @@ function getStatus() { }; } -async function setupNewDocument(req) { - const { username, password, theme } = req.body; - - await sqlInit.createInitialDatabase(username, password, theme); +async function setupNewDocument() { + await sqlInit.createInitialDatabase(); } function setupSyncFromServer(req) { diff --git a/src/services/options_init.js b/src/services/options_init.js index d6034a97a..6760c4212 100644 --- a/src/services/options_init.js +++ b/src/services/options_init.js @@ -12,9 +12,7 @@ function initDocumentOptions() { optionService.createOption('documentSecret', utils.randomSecureToken(16), false); } -function initSyncedOptions(username, password) { - optionService.createOption('username', username, true); - +function initPassword(username, password) { optionService.createOption('passwordVerificationSalt', utils.randomSecureToken(32), true); optionService.createOption('passwordDerivedKeySalt', utils.randomSecureToken(32), true); @@ -129,7 +127,7 @@ function getKeyboardDefaultOptions() { module.exports = { initDocumentOptions, - initSyncedOptions, + initPassword, initNotSyncedOptions, initStartupOptions }; diff --git a/src/services/sql_init.js b/src/services/sql_init.js index b712e35a9..658fd9515 100644 --- a/src/services/sql_init.js +++ b/src/services/sql_init.js @@ -45,9 +45,7 @@ async function initDbConnection() { dbReady.resolve(); } -async function createInitialDatabase(username, password, theme) { - log.info("Creating database schema ..."); - +async function createInitialDatabase() { if (isDbInitialized()) { throw new Error("DB is already initialized"); } @@ -57,9 +55,9 @@ async function createInitialDatabase(username, password, theme) { let rootNote; - log.info("Creating root note ..."); - sql.transactional(() => { + log.info("Creating database schema ..."); + sql.executeScript(schema); require("../becca/becca_loader").load(); @@ -67,6 +65,8 @@ async function createInitialDatabase(username, password, theme) { const Note = require("../becca/entities/note"); const Branch = require("../becca/entities/branch"); + log.info("Creating root note ..."); + rootNote = new Note({ noteId: 'root', title: 'root', @@ -87,8 +87,7 @@ async function createInitialDatabase(username, password, theme) { const optionsInitService = require('./options_init'); optionsInitService.initDocumentOptions(); - optionsInitService.initSyncedOptions(username, password); - optionsInitService.initNotSyncedOptions(true, { theme }); + optionsInitService.initNotSyncedOptions(true, {}); optionsInitService.initStartupOptions(); }); diff --git a/src/views/setup.ejs b/src/views/setup.ejs index 723b281f6..1859a1b29 100644 --- a/src/views/setup.ejs +++ b/src/views/setup.ejs @@ -55,62 +55,20 @@
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.
- -Theme can be later changed in Options -> Appearance.
-