Update .gitignore and add new dependencies and routes
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:
@@ -1,7 +1,7 @@
|
||||
const fs = require('fs').promises;
|
||||
const path = require('path');
|
||||
|
||||
const filePath = path.join(__dirname, '../user.json');
|
||||
const filePath = path.join(__dirname, '../data/user.json');
|
||||
|
||||
async function getUserData() {
|
||||
try {
|
||||
@@ -15,9 +15,14 @@ async function getUserData() {
|
||||
|
||||
async function checkUserExistsAD(req, res, next) {
|
||||
let userData = await getUserData();
|
||||
console.log('User data:', userData);
|
||||
|
||||
if (!req.user || (!req.user.name && !req.user.id)) {
|
||||
return res.status(500).send('Internal Server Error');
|
||||
if (Array.isArray(req.user)) {
|
||||
req.user = req.user.find(u => u._json && u._json.sAMAccountName);
|
||||
}
|
||||
|
||||
if (req.user && req.user._json && req.user._json.sAMAccountName) {
|
||||
req.user.name = req.user._json.sAMAccountName;
|
||||
}
|
||||
|
||||
try {
|
||||
@@ -40,7 +45,7 @@ async function checkUserExistsAD(req, res, next) {
|
||||
users.push(newUser);
|
||||
|
||||
try {
|
||||
await fs.promises.writeFile(filePath, JSON.stringify(users, null, 2), 'utf8');
|
||||
await fs.writeFile(filePath, JSON.stringify(users, null, 2), 'utf8');
|
||||
} catch (error) {
|
||||
console.error(`Failed to write to ${filePath}: ${error}`);
|
||||
return next(error);
|
||||
|
||||
Reference in New Issue
Block a user