syncification

This commit is contained in:
zadam
2020-06-20 12:31:38 +02:00
parent 30062d687f
commit 88348c560c
97 changed files with 1673 additions and 1700 deletions

View File

@@ -7,8 +7,8 @@ const utils = require('./utils');
const passwordEncryptionService = require('./password_encryption');
const optionService = require('./options');
async function checkAuth(req, res, next) {
if (!await sqlInit.isDbInitialized()) {
function checkAuth(req, res, next) {
if (!sqlInit.isDbInitialized()) {
res.redirect("setup");
}
else if (!req.session.loggedIn && !utils.isElectron()) {
@@ -21,7 +21,7 @@ async function checkAuth(req, res, next) {
// for electron things which need network stuff
// currently we're doing that for file upload because handling form data seems to be difficult
async function checkApiAuthOrElectron(req, res, next) {
function checkApiAuthOrElectron(req, res, next) {
if (!req.session.loggedIn && !utils.isElectron()) {
reject(req, res, "Not authorized");
}
@@ -30,7 +30,7 @@ async function checkApiAuthOrElectron(req, res, next) {
}
}
async function checkApiAuth(req, res, next) {
function checkApiAuth(req, res, next) {
if (!req.session.loggedIn) {
reject(req, res, "Not authorized");
}
@@ -39,8 +39,8 @@ async function checkApiAuth(req, res, next) {
}
}
async function checkAppInitialized(req, res, next) {
if (!await sqlInit.isDbInitialized()) {
function checkAppInitialized(req, res, next) {
if (!sqlInit.isDbInitialized()) {
res.redirect("setup");
}
else {
@@ -48,8 +48,8 @@ async function checkAppInitialized(req, res, next) {
}
}
async function checkAppNotInitialized(req, res, next) {
if (await sqlInit.isDbInitialized()) {
function checkAppNotInitialized(req, res, next) {
if (sqlInit.isDbInitialized()) {
reject(req, res, "App already initialized.");
}
else {
@@ -57,10 +57,10 @@ async function checkAppNotInitialized(req, res, next) {
}
}
async function checkToken(req, res, next) {
function checkToken(req, res, next) {
const token = req.headers.authorization;
if (await sql.getValue("SELECT COUNT(*) FROM api_tokens WHERE isDeleted = 0 AND token = ?", [token]) === 0) {
if (sql.getValue("SELECT COUNT(*) FROM api_tokens WHERE isDeleted = 0 AND token = ?", [token]) === 0) {
reject(req, res, "Not authorized");
}
else {
@@ -74,15 +74,15 @@ function reject(req, res, message) {
res.status(401).send(message);
}
async function checkBasicAuth(req, res, next) {
function checkBasicAuth(req, res, next) {
const header = req.headers.authorization || '';
const token = header.split(/\s+/).pop() || '';
const auth = new Buffer.from(token, 'base64').toString();
const [username, password] = auth.split(/:/);
const dbUsername = await optionService.getOption('username');
const dbUsername = optionService.getOption('username');
if (dbUsername !== username || !await passwordEncryptionService.verifyPassword(password)) {
if (dbUsername !== username || !passwordEncryptionService.verifyPassword(password)) {
res.status(401).send('Incorrect username and/or password');
}
else {
@@ -98,4 +98,4 @@ module.exports = {
checkApiAuthOrElectron,
checkToken,
checkBasicAuth
};
};