Urgent correction of version v1.0.0-beta.14 due to crash issues when acting on the CDN.
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -33,9 +33,9 @@ async function checkUserExistsAD(req, res, next) {
|
||||
} else if (req.user.id) {
|
||||
existingUser = users.find(u => u.id === req.user.id);
|
||||
}
|
||||
|
||||
|
||||
if (!existingUser) {
|
||||
const id = Math.floor(Math.random() * 1e19);
|
||||
const id = Math.floor(Math.random() * 1e19);
|
||||
const newUser = {
|
||||
id: id.toString(),
|
||||
name: req.user.name || req.user.id,
|
||||
@@ -55,7 +55,7 @@ async function checkUserExistsAD(req, res, next) {
|
||||
} else {
|
||||
req.user = existingUser;
|
||||
req.session.userId = existingUser.id;
|
||||
res.render('AuthLogin', { isAuthenticated: true, setupData: {}, currentUrl: req.originalUrl, errorMessage: '' });
|
||||
res.status(200).render('AuthLogin', { isAuthenticated: true, setupData: {}, currentUrl: req.originalUrl, errorMessage: '' });
|
||||
}
|
||||
|
||||
return next();
|
||||
|
||||
@@ -12,7 +12,17 @@ async function getUserData() {
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
let userData = getUserData();
|
||||
|
||||
let userData;
|
||||
|
||||
(async () => {
|
||||
try {
|
||||
userData = await getUserData();
|
||||
} catch (err) {
|
||||
console.error(`Failed to initialize userData: ${err}`);
|
||||
process.exit(1);
|
||||
}
|
||||
})();
|
||||
|
||||
async function checkUserExistsDiscord(req, res, next) {
|
||||
if (!req.user || (!req.user.username && !req.user.id)) {
|
||||
@@ -20,19 +30,18 @@ async function checkUserExistsDiscord(req, res, next) {
|
||||
}
|
||||
|
||||
try {
|
||||
let users = userData;
|
||||
let userData = await getUserData();
|
||||
|
||||
let existingUser;
|
||||
if (req.user.username) {
|
||||
existingUser = users.find(u => u.name === req.user.username);
|
||||
existingUser = userData.find(u => u.name === req.user.username);
|
||||
} else if (req.user.id) {
|
||||
existingUser = users.find(u => u.id === req.user.id);
|
||||
existingUser = userData.find(u => u.id === req.user.id);
|
||||
}
|
||||
|
||||
if (existingUser) {
|
||||
req.user.id = existingUser.id;
|
||||
res.redirect('/dpanel/dashboard');
|
||||
return;
|
||||
return res.redirect('/dpanel/dashboard');
|
||||
}
|
||||
|
||||
const newUser = {
|
||||
@@ -40,9 +49,10 @@ async function checkUserExistsDiscord(req, res, next) {
|
||||
name: req.user.username,
|
||||
role: "user"
|
||||
};
|
||||
users.push(newUser);
|
||||
|
||||
await fs.writeFile(filePath, JSON.stringify(users, null, 2), 'utf8');
|
||||
userData.push(newUser);
|
||||
|
||||
await fs.writeFile(filePath, JSON.stringify(userData, null, 2), 'utf8');
|
||||
|
||||
req.user.id = newUser.id;
|
||||
|
||||
@@ -52,4 +62,5 @@ async function checkUserExistsDiscord(req, res, next) {
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { checkUserExistsDiscord };
|
||||
|
||||
module.exports = { checkUserExistsDiscord };
|
||||
|
||||
@@ -28,14 +28,14 @@ watcher.on('change', (filePath) => {
|
||||
let modifiedFile;
|
||||
if (filePath === userFilePath) {
|
||||
try {
|
||||
userData = JSON.parse(fs.readFileSync(filePath, 'utf-8'));
|
||||
userData = JSON.parse(fs.readFileSync(filePath, 'utf-8'));
|
||||
modifiedFile = 'user.json';
|
||||
} catch (error) {
|
||||
logger.error(`Error parsing user.json: ${error}`);
|
||||
}
|
||||
} else if (filePath === setupFilePath) {
|
||||
try {
|
||||
setupData = JSON.parse(fs.readFileSync(filePath, 'utf-8'));
|
||||
setupData = JSON.parse(fs.readFileSync(filePath, 'utf-8'));
|
||||
modifiedFile = 'setup.json';
|
||||
} catch (error) {
|
||||
logger.error(`Error parsing setup.json: ${error}`);
|
||||
|
||||
Reference in New Issue
Block a user