From 7e48d214ca166239cda0f0db18f20cf55c78d087 Mon Sep 17 00:00:00 2001 From: zadam Date: Tue, 28 Dec 2021 22:59:38 +0100 Subject: [PATCH 01/18] removed username/password from setup --- src/public/app/setup.js | 108 +++++++++++++---------------------- src/routes/api/setup.js | 6 +- src/services/options_init.js | 6 +- src/services/sql_init.js | 13 ++--- src/views/setup.ejs | 48 +--------------- 5 files changed, 52 insertions(+), 129 deletions(-) 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 @@
+ I'm a new user, and I want to create new Trilium document for my notes
+ I have desktop instance already, and I want to set up sync with it
+ I have server instance already, and I want to set up sync with it
-
-

New document

- -

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.

-
- - - -   - - -
-

Document initialization in progress

From 4e31af8c84838297aded9c5b63a22a6ce1e3b20c Mon Sep 17 00:00:00 2001 From: zadam Date: Wed, 29 Dec 2021 23:19:05 +0100 Subject: [PATCH 02/18] set password WIP --- package-lock.json | 4 +- src/public/app/dialogs/options/credentials.js | 6 --- src/routes/login.js | 5 ++ src/routes/routes.js | 3 +- src/services/auth.js | 15 +++++- src/services/sql.js | 23 +++++++-- src/services/sql_init.js | 12 ++++- src/views/set_password.ejs | 50 +++++++++++++++++++ 8 files changed, 101 insertions(+), 17 deletions(-) create mode 100644 src/views/set_password.ejs diff --git a/package-lock.json b/package-lock.json index 798a1729c..c462596b3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "trilium", - "version": "0.48.8", + "version": "0.49.1-beta", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "trilium", - "version": "0.48.8", + "version": "0.49.1-beta", "license": "AGPL-3.0-only", "dependencies": { "@electron/remote": "2.0.1", diff --git a/src/public/app/dialogs/options/credentials.js b/src/public/app/dialogs/options/credentials.js index ce8c1a85c..cc2ebe2fb 100644 --- a/src/public/app/dialogs/options/credentials.js +++ b/src/public/app/dialogs/options/credentials.js @@ -3,10 +3,6 @@ import protectedSessionHolder from "../../services/protected_session_holder.js"; import toastService from "../../services/toast.js"; const TPL = ` -

Username

- -

Your username is .

-

Change password