mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01:00
refactored detection of whether user is initialized
This commit is contained in:
parent
eabc7f80b7
commit
136375cf11
@ -3,12 +3,9 @@
|
|||||||
const migration = require('./migration');
|
const migration = require('./migration');
|
||||||
const sql = require('./sql');
|
const sql = require('./sql');
|
||||||
const utils = require('./utils');
|
const utils = require('./utils');
|
||||||
const options = require('./options');
|
|
||||||
|
|
||||||
async function checkAuth(req, res, next) {
|
async function checkAuth(req, res, next) {
|
||||||
const username = await options.getOption('username');
|
if (!await sql.isUserInitialized()) {
|
||||||
|
|
||||||
if (!username) {
|
|
||||||
res.redirect("setup");
|
res.redirect("setup");
|
||||||
}
|
}
|
||||||
else if (!req.session.loggedIn && !utils.isElectron()) {
|
else if (!req.session.loggedIn && !utils.isElectron()) {
|
||||||
@ -53,9 +50,7 @@ async function checkApiAuthForMigrationPage(req, res, next) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function checkAppNotInitialized(req, res, next) {
|
async function checkAppNotInitialized(req, res, next) {
|
||||||
const username = await options.getOption('username');
|
if (await sql.isUserInitialized()) {
|
||||||
|
|
||||||
if (username) {
|
|
||||||
res.status(400).send("App already initialized.");
|
res.status(400).send("App already initialized.");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -49,9 +49,7 @@ const dbReady = new Promise((resolve, reject) => {
|
|||||||
// the database
|
// the database
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
const username = await getFirstValue("SELECT opt_value FROM options WHERE opt_name = 'username'");
|
if (!await isUserInitialized()) {
|
||||||
|
|
||||||
if (!username) {
|
|
||||||
log.info("Login/password not initialized. DB not ready.");
|
log.info("Login/password not initialized. DB not ready.");
|
||||||
|
|
||||||
return;
|
return;
|
||||||
@ -235,8 +233,15 @@ async function isDbUpToDate() {
|
|||||||
return upToDate;
|
return upToDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function isUserInitialized() {
|
||||||
|
const username = await getFirstValue("SELECT opt_value FROM options WHERE opt_name = 'username'");
|
||||||
|
|
||||||
|
return !!username;
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
dbReady,
|
dbReady,
|
||||||
|
isUserInitialized,
|
||||||
insert,
|
insert,
|
||||||
replace,
|
replace,
|
||||||
getFirstValue,
|
getFirstValue,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user