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