Added adjusted hours route and merge commits
This commit is contained in:
parent
dd118a2359
commit
0eec95294a
|
|
@ -36,6 +36,7 @@
|
|||
"puppeteer": "^24.10.1",
|
||||
"request": "^2.88.2",
|
||||
"require": "^2.4.20",
|
||||
"socket.io": "^4.8.1",
|
||||
"uglify-js": "^3.19.3",
|
||||
"uuid": "^11.0.3",
|
||||
"winston": "^3.17.0",
|
||||
|
|
@ -1976,12 +1977,27 @@
|
|||
"url": "https://github.com/sponsors/sindresorhus"
|
||||
}
|
||||
},
|
||||
"node_modules/@socket.io/component-emitter": {
|
||||
"version": "3.1.2",
|
||||
"resolved": "https://registry.npmjs.org/@socket.io/component-emitter/-/component-emitter-3.1.2.tgz",
|
||||
"integrity": "sha512-9BCxFwvbGg/RsZK9tjXd8s4UcwR0MWeFQ1XEKIQVVvAGJyINdrqKMcTRyLoK8Rse1GjzLV9cwjWV1olXRWEXVA==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/@tootallnate/quickjs-emscripten": {
|
||||
"version": "0.23.0",
|
||||
"resolved": "https://registry.npmjs.org/@tootallnate/quickjs-emscripten/-/quickjs-emscripten-0.23.0.tgz",
|
||||
"integrity": "sha512-C5Mc6rdnsaJDjO3UpGW/CQTHtCKaYlScZTly4JIu97Jxo/odCiH0ITnDXSJPTOrEKk/ycSZ0AOgTmkDtkOsvIA==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/@types/cors": {
|
||||
"version": "2.8.19",
|
||||
"resolved": "https://registry.npmjs.org/@types/cors/-/cors-2.8.19.tgz",
|
||||
"integrity": "sha512-mFNylyeyqN93lfe/9CSxOGREz8cpzAhH+E93xJ4xWQf62V8sQ/24reV2nyzUWM6H6Xji+GGHpkbLe7pVoUEskg==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@types/node": "*"
|
||||
}
|
||||
},
|
||||
"node_modules/@types/eslint": {
|
||||
"version": "9.6.1",
|
||||
"resolved": "https://registry.npmjs.org/@types/eslint/-/eslint-9.6.1.tgz",
|
||||
|
|
@ -2022,7 +2038,6 @@
|
|||
"version": "22.10.6",
|
||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-22.10.6.tgz",
|
||||
"integrity": "sha512-qNiuwC4ZDAUNcY47xgaSuS92cjf8JbSUoaKS77bmLG1rU7MlATVSiw/IlrjtIyyskXBZ8KkNfjK/P5na7rgXbQ==",
|
||||
"devOptional": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"undici-types": "~6.20.0"
|
||||
|
|
@ -2729,6 +2744,15 @@
|
|||
],
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/base64id": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/base64id/-/base64id-2.0.0.tgz",
|
||||
"integrity": "sha512-lGe34o6EHj9y3Kts9R4ZYs/Gr+6N7MCaMlIFA3F1R2O5/m7K06AxfSeO5530PEERE6/WyEg3lsuyw4GHlPZHog==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": "^4.5.0 || >= 5.9"
|
||||
}
|
||||
},
|
||||
"node_modules/base64url": {
|
||||
"version": "3.0.1",
|
||||
"resolved": "https://registry.npmjs.org/base64url/-/base64url-3.0.1.tgz",
|
||||
|
|
@ -3867,6 +3891,88 @@
|
|||
"once": "^1.4.0"
|
||||
}
|
||||
},
|
||||
"node_modules/engine.io": {
|
||||
"version": "6.6.4",
|
||||
"resolved": "https://registry.npmjs.org/engine.io/-/engine.io-6.6.4.tgz",
|
||||
"integrity": "sha512-ZCkIjSYNDyGn0R6ewHDtXgns/Zre/NT6Agvq1/WobF7JXgFff4SeDroKiCO3fNJreU9YG429Sc81o4w5ok/W5g==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@types/cors": "^2.8.12",
|
||||
"@types/node": ">=10.0.0",
|
||||
"accepts": "~1.3.4",
|
||||
"base64id": "2.0.0",
|
||||
"cookie": "~0.7.2",
|
||||
"cors": "~2.8.5",
|
||||
"debug": "~4.3.1",
|
||||
"engine.io-parser": "~5.2.1",
|
||||
"ws": "~8.17.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=10.2.0"
|
||||
}
|
||||
},
|
||||
"node_modules/engine.io-parser": {
|
||||
"version": "5.2.3",
|
||||
"resolved": "https://registry.npmjs.org/engine.io-parser/-/engine.io-parser-5.2.3.tgz",
|
||||
"integrity": "sha512-HqD3yTBfnBxIrbnM1DoD6Pcq8NECnh8d4As1Qgh0z5Gg3jRRIqijury0CL3ghu/edArpUYiYqQiDUQBIs4np3Q==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=10.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/engine.io/node_modules/cookie": {
|
||||
"version": "0.7.2",
|
||||
"resolved": "https://registry.npmjs.org/cookie/-/cookie-0.7.2.tgz",
|
||||
"integrity": "sha512-yki5XnKuf750l50uGTllt6kKILY4nQ1eNIQatoXEByZ5dWgnKqbnqmTrBE5B4N7lrMJKQ2ytWMiTO2o0v6Ew/w==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">= 0.6"
|
||||
}
|
||||
},
|
||||
"node_modules/engine.io/node_modules/debug": {
|
||||
"version": "4.3.7",
|
||||
"resolved": "https://registry.npmjs.org/debug/-/debug-4.3.7.tgz",
|
||||
"integrity": "sha512-Er2nc/H7RrMXZBFCEim6TCmMk02Z8vLC2Rbi1KEBggpo0fS6l0S1nnapwmIi3yW/+GOJap1Krg4w0Hg80oCqgQ==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"ms": "^2.1.3"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=6.0"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"supports-color": {
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/engine.io/node_modules/ms": {
|
||||
"version": "2.1.3",
|
||||
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz",
|
||||
"integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/engine.io/node_modules/ws": {
|
||||
"version": "8.17.1",
|
||||
"resolved": "https://registry.npmjs.org/ws/-/ws-8.17.1.tgz",
|
||||
"integrity": "sha512-6XQFvXTkbfUOZOKKILFG1PDK2NDQs4azKQl26T0YS5CxqWLgXajbPZ+h4gZekJyRqFU8pvnbAbbs/3TgRPy+GQ==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=10.0.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"bufferutil": "^4.0.1",
|
||||
"utf-8-validate": ">=5.0.2"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"bufferutil": {
|
||||
"optional": true
|
||||
},
|
||||
"utf-8-validate": {
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/enhanced-resolve": {
|
||||
"version": "5.18.3",
|
||||
"resolved": "https://registry.npmjs.org/enhanced-resolve/-/enhanced-resolve-5.18.3.tgz",
|
||||
|
|
@ -8127,6 +8233,137 @@
|
|||
"npm": ">= 3.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/socket.io": {
|
||||
"version": "4.8.1",
|
||||
"resolved": "https://registry.npmjs.org/socket.io/-/socket.io-4.8.1.tgz",
|
||||
"integrity": "sha512-oZ7iUCxph8WYRHHcjBEc9unw3adt5CmSNlppj/5Q4k2RIrhl8Z5yY2Xr4j9zj0+wzVZ0bxmYoGSzKJnRl6A4yg==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"accepts": "~1.3.4",
|
||||
"base64id": "~2.0.0",
|
||||
"cors": "~2.8.5",
|
||||
"debug": "~4.3.2",
|
||||
"engine.io": "~6.6.0",
|
||||
"socket.io-adapter": "~2.5.2",
|
||||
"socket.io-parser": "~4.2.4"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=10.2.0"
|
||||
}
|
||||
},
|
||||
"node_modules/socket.io-adapter": {
|
||||
"version": "2.5.5",
|
||||
"resolved": "https://registry.npmjs.org/socket.io-adapter/-/socket.io-adapter-2.5.5.tgz",
|
||||
"integrity": "sha512-eLDQas5dzPgOWCk9GuuJC2lBqItuhKI4uxGgo9aIV7MYbk2h9Q6uULEh8WBzThoI7l+qU9Ast9fVUmkqPP9wYg==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"debug": "~4.3.4",
|
||||
"ws": "~8.17.1"
|
||||
}
|
||||
},
|
||||
"node_modules/socket.io-adapter/node_modules/debug": {
|
||||
"version": "4.3.7",
|
||||
"resolved": "https://registry.npmjs.org/debug/-/debug-4.3.7.tgz",
|
||||
"integrity": "sha512-Er2nc/H7RrMXZBFCEim6TCmMk02Z8vLC2Rbi1KEBggpo0fS6l0S1nnapwmIi3yW/+GOJap1Krg4w0Hg80oCqgQ==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"ms": "^2.1.3"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=6.0"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"supports-color": {
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/socket.io-adapter/node_modules/ms": {
|
||||
"version": "2.1.3",
|
||||
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz",
|
||||
"integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/socket.io-adapter/node_modules/ws": {
|
||||
"version": "8.17.1",
|
||||
"resolved": "https://registry.npmjs.org/ws/-/ws-8.17.1.tgz",
|
||||
"integrity": "sha512-6XQFvXTkbfUOZOKKILFG1PDK2NDQs4azKQl26T0YS5CxqWLgXajbPZ+h4gZekJyRqFU8pvnbAbbs/3TgRPy+GQ==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=10.0.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"bufferutil": "^4.0.1",
|
||||
"utf-8-validate": ">=5.0.2"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"bufferutil": {
|
||||
"optional": true
|
||||
},
|
||||
"utf-8-validate": {
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/socket.io-parser": {
|
||||
"version": "4.2.4",
|
||||
"resolved": "https://registry.npmjs.org/socket.io-parser/-/socket.io-parser-4.2.4.tgz",
|
||||
"integrity": "sha512-/GbIKmo8ioc+NIWIhwdecY0ge+qVBSMdgxGygevmdHj24bsfgtCmcUUcQ5ZzcylGFHsN3k4HB4Cgkl96KVnuew==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@socket.io/component-emitter": "~3.1.0",
|
||||
"debug": "~4.3.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=10.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/socket.io-parser/node_modules/debug": {
|
||||
"version": "4.3.7",
|
||||
"resolved": "https://registry.npmjs.org/debug/-/debug-4.3.7.tgz",
|
||||
"integrity": "sha512-Er2nc/H7RrMXZBFCEim6TCmMk02Z8vLC2Rbi1KEBggpo0fS6l0S1nnapwmIi3yW/+GOJap1Krg4w0Hg80oCqgQ==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"ms": "^2.1.3"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=6.0"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"supports-color": {
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/socket.io-parser/node_modules/ms": {
|
||||
"version": "2.1.3",
|
||||
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz",
|
||||
"integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/socket.io/node_modules/debug": {
|
||||
"version": "4.3.7",
|
||||
"resolved": "https://registry.npmjs.org/debug/-/debug-4.3.7.tgz",
|
||||
"integrity": "sha512-Er2nc/H7RrMXZBFCEim6TCmMk02Z8vLC2Rbi1KEBggpo0fS6l0S1nnapwmIi3yW/+GOJap1Krg4w0Hg80oCqgQ==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"ms": "^2.1.3"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=6.0"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"supports-color": {
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/socket.io/node_modules/ms": {
|
||||
"version": "2.1.3",
|
||||
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz",
|
||||
"integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/socks": {
|
||||
"version": "2.8.5",
|
||||
"resolved": "https://registry.npmjs.org/socks/-/socks-2.8.5.tgz",
|
||||
|
|
@ -8642,7 +8879,6 @@
|
|||
"version": "6.20.0",
|
||||
"resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.20.0.tgz",
|
||||
"integrity": "sha512-Ny6QZ2Nju20vw1SRHe3d9jVu6gJ+4e3+MMpqu7pqE5HT6WsTSlce++GQmK5UXS8mzV8DSYHrQH+Xrf2jVcuKNg==",
|
||||
"devOptional": true,
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/unicode-canonical-property-names-ecmascript": {
|
||||
|
|
|
|||
|
|
@ -40,6 +40,7 @@
|
|||
"puppeteer": "^24.10.1",
|
||||
"request": "^2.88.2",
|
||||
"require": "^2.4.20",
|
||||
"socket.io": "^4.8.1",
|
||||
"uglify-js": "^3.19.3",
|
||||
"uuid": "^11.0.3",
|
||||
"winston": "^3.17.0",
|
||||
|
|
|
|||
|
|
@ -3,34 +3,138 @@ import { VAModel, LoggedModel } from "../../../models/vaModel.js";
|
|||
// Getting all active VA's and their details
|
||||
async function va_callback(req, res) {
|
||||
try {
|
||||
// Find the latest log entry for each VA and return those whose last entry is LOGIN
|
||||
// Find the latest log entry for each VA
|
||||
const agg = await LoggedModel.aggregate([
|
||||
{ $sort: { time: -1 } },
|
||||
{ $group: { _id: "$vaId", lastLog: { $first: "$$ROOT" } } },
|
||||
{ $match: { "lastLog.loggedType": "LOGIN" } }
|
||||
{
|
||||
$group: {
|
||||
_id: "$vaId",
|
||||
lastLog: { $first: "$$ROOT" },
|
||||
totalLogins: {
|
||||
$sum: {
|
||||
$cond: [{ $eq: ["$loggedType", "LOGIN"] }, 1, 0]
|
||||
}
|
||||
},
|
||||
lastActivity: { $first: "$time" }
|
||||
}
|
||||
},
|
||||
{
|
||||
$match: {
|
||||
"lastLog.loggedType": "LOGIN"
|
||||
}
|
||||
}
|
||||
]);
|
||||
|
||||
const vaIds = agg.map((a) => a._id).filter(Boolean);
|
||||
|
||||
if (vaIds.length === 0) {
|
||||
return res.status(200).json({ success: true, count: 0, data: [] });
|
||||
return res.status(200).json({
|
||||
success: true,
|
||||
count: 0,
|
||||
data: [],
|
||||
message: "No active VAs found"
|
||||
});
|
||||
}
|
||||
|
||||
// Get VA details with additional fields
|
||||
const vas = await VAModel.find({ _id: { $in: vaIds } })
|
||||
.select('userDetails.name userDetails.email userDetails.phone status createdAt')
|
||||
.lean()
|
||||
.exec();
|
||||
|
||||
|
||||
const vas = await VAModel.find({ _id: { $in: vaIds } }).lean().exec();
|
||||
|
||||
// map lastLog by VA id for easy attachment
|
||||
const lastLogByVa = agg.reduce((acc, a) => {
|
||||
acc[String(a._id)] = a.lastLog;
|
||||
// Create mapping for last log and activity data
|
||||
const activityByVa = agg.reduce((acc, a) => {
|
||||
acc[String(a._id)] = {
|
||||
lastLog: a.lastLog,
|
||||
totalLogins: a.totalLogins,
|
||||
lastActivity: a.lastActivity
|
||||
};
|
||||
return acc;
|
||||
}, {});
|
||||
|
||||
const results = vas.map((v) => ({ ...v, lastLog: lastLogByVa[String(v._id)] || null }));
|
||||
// Calculate session duration for currently active VAs
|
||||
const currentTime = new Date();
|
||||
const results = vas.map((v) => {
|
||||
const activity = activityByVa[String(v._id)] || {};
|
||||
const lastLog = activity.lastLog;
|
||||
|
||||
// Calculate current session duration if still logged in
|
||||
let currentSessionDuration = null;
|
||||
let isCurrentlyActive = false;
|
||||
|
||||
if (lastLog && lastLog.loggedType === "LOGIN") {
|
||||
const loginTime = new Date(lastLog.time);
|
||||
currentSessionDuration = Math.floor((currentTime - loginTime) / 1000); // in seconds
|
||||
isCurrentlyActive = true;
|
||||
|
||||
// Consider VA inactive if last login was more than 24 hours ago
|
||||
const hoursSinceLastActivity = (currentTime - loginTime) / (1000 * 60 * 60);
|
||||
if (hoursSinceLastActivity > 24) {
|
||||
isCurrentlyActive = false;
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
id: v._id,
|
||||
name: v.userDetails?.name || 'Unknown',
|
||||
email: v.userDetails?.email,
|
||||
phone: v.userDetails?.phone,
|
||||
status: v.status || 'active',
|
||||
isCurrentlyActive: isCurrentlyActive,
|
||||
lastLoginTime: lastLog?.time || null,
|
||||
lastActivity: activity.lastActivity,
|
||||
currentSessionDuration: currentSessionDuration,
|
||||
currentSessionFormatted: currentSessionDuration ? formatTime(currentSessionDuration) : null,
|
||||
totalLogins: activity.totalLogins || 0,
|
||||
lastProject: lastLog?.projectId || null,
|
||||
vaSince: v.createdAt
|
||||
};
|
||||
});
|
||||
|
||||
// Separate active and inactive VAs
|
||||
const activeVAs = results.filter(va => va.isCurrentlyActive);
|
||||
const inactiveButLoggedIn = results.filter(va => !va.isCurrentlyActive);
|
||||
|
||||
return res.status(200).json({
|
||||
success: true,
|
||||
count: {
|
||||
total: results.length,
|
||||
active: activeVAs.length,
|
||||
inactive: inactiveButLoggedIn.length
|
||||
},
|
||||
data: {
|
||||
active: activeVAs,
|
||||
inactive: inactiveButLoggedIn
|
||||
},
|
||||
summary: {
|
||||
currentlyWorking: activeVAs.length,
|
||||
totalLoggedIn: results.length,
|
||||
lastUpdated: currentTime.toISOString()
|
||||
}
|
||||
});
|
||||
|
||||
return res.status(200).json({ success: true, count: results.length, data: results });
|
||||
} catch (error) {
|
||||
return res.status(500).send("Internal Server Error");
|
||||
console.error("VA callback error:", error);
|
||||
return res.status(500).json({
|
||||
success: false,
|
||||
message: "Internal Server Error",
|
||||
error: error.message
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Helper function to format time
|
||||
function formatTime(seconds) {
|
||||
const hours = Math.floor(seconds / 3600);
|
||||
const minutes = Math.floor((seconds % 3600) / 60);
|
||||
const remainingSeconds = seconds % 60;
|
||||
|
||||
if (hours > 0) {
|
||||
return `${hours}h ${minutes}m ${remainingSeconds}s`;
|
||||
} else if (minutes > 0) {
|
||||
return `${minutes}m ${remainingSeconds}s`;
|
||||
} else {
|
||||
return `${remainingSeconds}s`;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,8 +4,7 @@ import { WorkTrackModel, VAModel, ProjectModel, LoggedModel } from "../../../mod
|
|||
// Getting logged hours in a specific project of VA
|
||||
async function va_log_track_work_callback(req, res) {
|
||||
try {
|
||||
const accessToken = req.headers.token;
|
||||
|
||||
const accessToken = req.headers.token;
|
||||
if (!accessToken) {
|
||||
return res.status(401).json({ success: false, message: "Missing token" });
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,23 +29,23 @@ async function va_profile_update_callback(req, res) {
|
|||
|
||||
const payload = req.body || {};
|
||||
const { userDetails } = payload;
|
||||
|
||||
|
||||
if (!userDetails) {
|
||||
return res.status(400).json({ success: false, message: "Missing userDetails" });
|
||||
}
|
||||
|
||||
// Allowed fields to update
|
||||
const allowedFields = [
|
||||
"firstName", "lastName", "dob", "age", "address",
|
||||
"bankName", "accountHolderName", "accountNumber", "routingNumber"
|
||||
];
|
||||
// const allowedFields = [
|
||||
// "firstName", "lastName", "dob", "age", "address",
|
||||
// "bankName", "accountHolderName", "accountNumber", "routingNumber"
|
||||
// ];
|
||||
|
||||
// Update allowed fields only
|
||||
allowedFields.forEach(field => {
|
||||
if (userDetails[field] !== undefined) {
|
||||
vaUser.userDetails[field] = userDetails[field];
|
||||
}
|
||||
});
|
||||
// // Update allowed fields only
|
||||
// allowedFields.forEach(field => {
|
||||
// if (userDetails[field] !== undefined) {
|
||||
// vaUser.userDetails[field] = userDetails[field];
|
||||
// }
|
||||
// });
|
||||
|
||||
/* ---------------------- PASSWORD UPDATE ---------------------- */
|
||||
if (userDetails.password || userDetails.cPassword || userDetails.oldPassword) {
|
||||
|
|
@ -78,28 +78,13 @@ async function va_profile_update_callback(req, res) {
|
|||
const saltRounds = 10;
|
||||
const hashedPassword = await bcrypt.hash(password, saltRounds);
|
||||
vaUser.userDetails.password = hashedPassword;
|
||||
} else {
|
||||
return res.status(400).json({
|
||||
success: false,
|
||||
message: "Data not found",
|
||||
});
|
||||
}
|
||||
|
||||
// if (userDetails.password) {
|
||||
// if (!userDetails.cPassword) {
|
||||
// return res.status(400).json({
|
||||
// success: false,
|
||||
// message: "Please confirm your new password",
|
||||
// });
|
||||
// }
|
||||
|
||||
// if (userDetails.password !== userDetails.cPassword) {
|
||||
// return res.status(400).json({
|
||||
// success: false,
|
||||
// message: "Passwords do not match",
|
||||
// });
|
||||
// }
|
||||
|
||||
// const saltRounds = 10;
|
||||
// const hashedPassword = await bcrypt.hash(userDetails.password, saltRounds);
|
||||
// vaUser.userDetails.password = hashedPassword;
|
||||
// }
|
||||
|
||||
await vaUser.save();
|
||||
|
||||
const updatedUser = await VAModel.findById(vaUser._id)
|
||||
|
|
|
|||
|
|
@ -52,7 +52,12 @@ async function va_projects_log_list_function(req, res) {
|
|||
|
||||
projectList = [project];
|
||||
} else {
|
||||
projectList = await ProjectModel.find({ vaAssigned: vaId });
|
||||
const all = await ProjectModel.find().lean();
|
||||
console.log(all.map(p => p.vaAssigned));
|
||||
|
||||
console.log("VA ID:", vaId.toString());
|
||||
|
||||
projectList = await ProjectModel.find({ vaAssigned: vaUser._id });
|
||||
}
|
||||
|
||||
if (!projectList.length) {
|
||||
|
|
|
|||
|
|
@ -4,28 +4,39 @@ import logger from "../config/logger.js";
|
|||
|
||||
async function authValidator(req, res, next) {
|
||||
try {
|
||||
const accessToken = req.headers.token;
|
||||
if (!accessToken) return res.status(401).json({ success: false, message: "Not Authorized" });
|
||||
const sf_token = req.header.sf_token;
|
||||
if (sf_token) {
|
||||
|
||||
const decoded = jwt.verify(accessToken, process.env.JWT_SECRET_ACCESS_TOKEN);
|
||||
} else {
|
||||
const accessToken = req.headers.token;
|
||||
if (!accessToken) return res.status(401).json({ success: false, message: "Not Authorized" });
|
||||
|
||||
if (decoded && ("id" in decoded) && decoded.id !== null && ("email" in decoded)) {
|
||||
const vaEmail = decoded.email;
|
||||
|
||||
const vaUser = await VAModel.findOne({ "userDetails.email": vaEmail })
|
||||
if (!vaUser) {
|
||||
return res.status(401).json({ success: false, message: "Not Authorized" });
|
||||
}
|
||||
if (!("accessToken" in vaUser) || !vaUser.accessToken) {
|
||||
return res.status(401).json({ success: false, message: "Not Authorized" });
|
||||
}
|
||||
|
||||
if (vaUser.accessToken === accessToken) {
|
||||
req.body.vaId = vaUser._id
|
||||
req.body.vaEmail = vaEmail
|
||||
next();
|
||||
} else {
|
||||
return res.status(401).json({ success: false, message: "Not Authorized" });
|
||||
// return res.status(200).json({
|
||||
// success: true,
|
||||
// message: "Log Out Successfull",
|
||||
// });
|
||||
|
||||
const decoded = jwt.verify(accessToken, process.env.JWT_SECRET_ACCESS_TOKEN);
|
||||
|
||||
if (decoded && ("id" in decoded) && decoded.id !== null && ("email" in decoded)) {
|
||||
const vaEmail = decoded.email;
|
||||
|
||||
const vaUser = await VAModel.findOne({ "userDetails.email": vaEmail })
|
||||
if (!vaUser) {
|
||||
return res.status(401).json({ success: false, message: "Not Authorized" });
|
||||
}
|
||||
if (!("accessToken" in vaUser) || !vaUser.accessToken) {
|
||||
return res.status(401).json({ success: false, message: "Not Authorized" });
|
||||
}
|
||||
|
||||
if (vaUser.accessToken === accessToken) {
|
||||
req.body.vaId = vaUser._id
|
||||
req.body.vaEmail = vaEmail
|
||||
next();
|
||||
} else {
|
||||
return res.status(401).json({ success: false, message: "Not Authorized" });
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -80,6 +80,10 @@ const projectSchema = new Schema({
|
|||
type: Number,
|
||||
default: 0
|
||||
},
|
||||
clientId: {
|
||||
type: Types.ObjectId,
|
||||
ref: "Client"
|
||||
},
|
||||
vaAssigned: [
|
||||
{
|
||||
type: Types.ObjectId,
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ vaRoutes.patch("/profile", authValidator, va_profile_update_callback); // Update
|
|||
|
||||
|
||||
|
||||
vaRoutes.get("/:userName", va_username_callback); // VA Username Callback (NC)
|
||||
vaRoutes.get("/:userName", va_username_callback); // VA Username Callback
|
||||
|
||||
// timesheet adjustment routes
|
||||
vaRoutes.get("/timesheet/summary/:projectId/:date", authValidator, va_timesheet_summary_function); // Get Timesheet Adjustment for VA on specific project and date
|
||||
|
|
|
|||
249
src/server.js
249
src/server.js
|
|
@ -1,19 +1,25 @@
|
|||
import dotenv from "dotenv";
|
||||
dotenv.config()
|
||||
|
||||
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
|
||||
|
||||
import express from 'express';
|
||||
import { createServer } from 'http';
|
||||
|
||||
import mongoose from "mongoose";
|
||||
import bodyParser from "body-parser";
|
||||
import { Server } from 'socket.io';
|
||||
|
||||
import cors from 'cors';
|
||||
import path from 'path';
|
||||
import { fileURLToPath } from 'url';
|
||||
import fs from "node:fs"
|
||||
import apiRoutes from './routes/index.js'
|
||||
import { render_reset_form } from "./controllers/passwordReset.controllers.js";
|
||||
|
||||
const app = express();
|
||||
const server = new createServer(app);
|
||||
const io = new Server(server);
|
||||
app.set("view engine", "ejs");
|
||||
const PORT = process.env.PORT || 8000;
|
||||
|
||||
|
|
@ -47,9 +53,250 @@ app.get('/health', (req, res) => {
|
|||
res.status(201).send({ status: "Server is healthy" });
|
||||
})
|
||||
|
||||
app.get("/client/login", (req, res) => {
|
||||
res.render("client_login")
|
||||
})
|
||||
app.get("/client/forgot-password", (req, res) => {
|
||||
res.render("forgot_password")
|
||||
})
|
||||
|
||||
app.get("/live/:projectId", (req, res) => {
|
||||
const { projectId } = req.params;
|
||||
res.render("va_live_tracker", { title: "VA Live Tracker", projectId })
|
||||
})
|
||||
|
||||
// Handling Socket
|
||||
import jwt from "jsonwebtoken";
|
||||
import { VAModel, ProjectModel, ClientModel } from './models/vaModel.js';
|
||||
import { ObjectId } from 'mongodb/lib/bson.js';
|
||||
|
||||
|
||||
const vaSocketRespectToClient = new Map();
|
||||
|
||||
io.use(async (socket, next) => {
|
||||
try {
|
||||
const token = socket.handshake.auth?.token;
|
||||
const projectId = socket.handshake.auth?.projectId;
|
||||
const userType = socket.handshake.auth?.userType;
|
||||
|
||||
console.log("🔐 Received token:", token);
|
||||
|
||||
if (!token) {
|
||||
return next(new Error("Not Authorized: Missing Token"));
|
||||
}
|
||||
|
||||
const decoded = jwt.verify(token, process.env.JWT_SECRET_ACCESS_TOKEN);
|
||||
|
||||
if (!decoded?.email) {
|
||||
return next(new Error("Invalid token payload"));
|
||||
}
|
||||
|
||||
/* ---------------------- 1⃣ Check if VA ---------------------- */
|
||||
let vaUser = null;
|
||||
let clientData = null;
|
||||
|
||||
if (userType === "va") {
|
||||
vaUser = await VAModel.findOne({ "userDetails.email": decoded.email });
|
||||
clientData = await ProjectModel.findById(projectId).populate("clientId");
|
||||
} else if (userType === "client") {
|
||||
clientData = await ProjectModel.findById(projectId).populate("clientId");
|
||||
}
|
||||
|
||||
if (clientData == null) return next(new Error("Invalid Project ID"));
|
||||
const vaProjClientId = clientData.clientId._id;
|
||||
|
||||
if (vaUser && vaUser.accessToken === token) {
|
||||
socket.data.role = "va";
|
||||
socket.data.vaId = vaUser._id.toString();
|
||||
socket.data.vaEmail = decoded.email;
|
||||
|
||||
const a = vaProjClientId.toString();
|
||||
const b = clientData.clientId._id.toString();
|
||||
const c = JSON.stringify(clientData);
|
||||
|
||||
console.log(a, b, c, "vaProjClientId vs clientData.clientId");
|
||||
|
||||
vaSocketRespectToClient.set(vaProjClientId.toString(), socket.id)
|
||||
|
||||
console.log("✅ Authenticated VA:", vaUser.userDetails.email);
|
||||
return next();
|
||||
}
|
||||
|
||||
/* ---------------------- 2⃣ Check if Client ---------------------- */
|
||||
// const clientUser = await ClientModel.findOne({ "userDetails.email": decoded.email });
|
||||
|
||||
// if (clientUser) {
|
||||
// socket.data.role = "client";
|
||||
// socket.data.clientId = clientUser._id.toString();
|
||||
|
||||
// // Get all VA IDs assigned to this client
|
||||
// socket.data.allowedVAs = clientUser.vaIds.map((va) => va.toString());
|
||||
|
||||
// console.log("✅ Authenticated Client:", clientUser.userDetails.email);
|
||||
// return next();
|
||||
// }
|
||||
const clientUser = clientData.clientId;
|
||||
|
||||
if (clientUser) {
|
||||
socket.data.role = "client";
|
||||
socket.data.clientId = clientUser._id.toString();
|
||||
|
||||
// Get all VA IDs assigned to this client
|
||||
socket.data.allowedVAs = clientData.vaAssigned.map((va) => va.toString());
|
||||
|
||||
// console.log("✅ Authenticated Client:", clientUser.userDetails.email);
|
||||
return next();
|
||||
}
|
||||
|
||||
return next(new Error("Not Authorized: Invalid User"));
|
||||
} catch (error) {
|
||||
console.error("❌ Socket Auth Error:", error.message);
|
||||
next(new Error("Authentication failed: " + error.message));
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
io.on("connection", (socket) => {
|
||||
console.log("User connected:", socket.id);
|
||||
|
||||
// Register role and ID (client or VA)
|
||||
socket.on("register", async ({ role, id }) => {
|
||||
if (role === "va") {
|
||||
socket.data.role = "va";
|
||||
socket.data.vaId = id;
|
||||
console.log(`VA registered: ${id}`);
|
||||
}
|
||||
|
||||
if (role === "client") {
|
||||
socket.data.role = "client";
|
||||
socket.data.clientId = id;
|
||||
|
||||
// 🧩 Get allowed VAs for this client
|
||||
const client = await ClientModel.findById(id)
|
||||
.populate("projectIds") // to access their projects
|
||||
.populate("vaIds"); // optional if you track directly
|
||||
|
||||
// Collect all VA IDs from their projects
|
||||
const projectVAIds = new Set();
|
||||
for (const project of client.projectIds) {
|
||||
const populated = await ProjectModel.findById(project._id).populate("vaAssigned");
|
||||
populated.vaAssigned.forEach((va) => projectVAIds.add(va._id.toString()));
|
||||
}
|
||||
|
||||
// Store allowed VA IDs in socket memory
|
||||
socket.data.allowedVAs = Array.from(projectVAIds);
|
||||
console.log(`Client ${id} can view VAs:`, socket.data.allowedVAs);
|
||||
}
|
||||
});
|
||||
|
||||
// When VA sends live image
|
||||
socket.on("sendImage", async ({ token, image, title }) => {
|
||||
try {
|
||||
// Verify token
|
||||
const decoded = jwt.verify(token, process.env.JWT_SECRET_ACCESS_TOKEN);
|
||||
const vaEmail = decoded.email;
|
||||
|
||||
// Find VA in DB
|
||||
const vaUser = await VAModel.findOne({ "userDetails.email": vaEmail });
|
||||
if (!vaUser) {
|
||||
console.log("❌ Unauthorized VA");
|
||||
return;
|
||||
}
|
||||
|
||||
const vaId = vaUser._id.toString();
|
||||
console.log("🟢 Received image from VA:", vaId);
|
||||
|
||||
// Broadcast image only to allowed clients
|
||||
for (let [_, clientSocket] of io.sockets.sockets) {
|
||||
if (
|
||||
clientSocket.data.role === "client" &&
|
||||
clientSocket.data.allowedVAs?.includes(vaId)
|
||||
) {
|
||||
clientSocket.emit("receiveImage", image, title);
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
console.error("❌ Token verification failed:", err.message);
|
||||
}
|
||||
});
|
||||
|
||||
socket.on("selectApp", ({ appTitle, clientId }) => {
|
||||
console.log(`VA selected app: ${appTitle}`);
|
||||
|
||||
const sssrrrr = vaSocketRespectToClient.get(clientId);
|
||||
console.log(vaSocketRespectToClient.get(clientId), sssrrrr, "vaSocketRespectToClient[clientId]")
|
||||
// You can forward this info to the respective Electron client
|
||||
socket.to(vaSocketRespectToClient.get(clientId)).emit("appToCapture", { appTitle });
|
||||
});
|
||||
|
||||
socket.on("getVisibleApps", async ({ token, apps }) => {
|
||||
try {
|
||||
// Verify token
|
||||
const decoded = jwt.verify(token, process.env.JWT_SECRET_ACCESS_TOKEN);
|
||||
const vaEmail = decoded.email;
|
||||
|
||||
// Find VA in DB
|
||||
const vaUser = await VAModel.findOne({ "userDetails.email": vaEmail });
|
||||
if (!vaUser) {
|
||||
console.log("❌ Unauthorized VA");
|
||||
return;
|
||||
}
|
||||
|
||||
const vaId = vaUser._id.toString();
|
||||
console.log("🟢 Received Apps from VA:", vaId);
|
||||
|
||||
// Broadcast image only to allowed clients
|
||||
for (let [_, clientSocket] of io.sockets.sockets) {
|
||||
if (
|
||||
clientSocket.data.role === "client" &&
|
||||
clientSocket.data.allowedVAs?.includes(vaId)
|
||||
) {
|
||||
clientSocket.emit("receiveVisibleApps", apps);
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
console.error("❌ Token verification failed:", err.message);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
socket.on('disconnect', () => {
|
||||
console.log('a user Disconnected');
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
// io.on('connection', (socket) => {
|
||||
|
||||
// socket.on("sendImage", (base64String) => {
|
||||
// io.emit("receiveImage", base64String);
|
||||
// });
|
||||
|
||||
|
||||
// socket.on('disconnect', () => {
|
||||
// console.log('a user Disconnected');
|
||||
// });
|
||||
// });
|
||||
|
||||
|
||||
// Express App Listening
|
||||
app.listen(PORT, () => {
|
||||
// app.listen(PORT, () => {
|
||||
// mongoose
|
||||
// .connect(
|
||||
// process.env.MONGO_URI,
|
||||
// )
|
||||
// .then(() => console.log("mongodb connected"))
|
||||
// .catch((err) => {
|
||||
// console.log(err.message);
|
||||
// process.exit(1);
|
||||
// });
|
||||
// console.log(`Express started on http://localhost:${PORT}`);
|
||||
// });
|
||||
|
||||
server.listen(PORT, () => {
|
||||
mongoose
|
||||
.connect(
|
||||
process.env.MONGO_URI,
|
||||
|
|
|
|||
|
|
@ -0,0 +1,32 @@
|
|||
// testVpnApi.js
|
||||
import axios from "axios";
|
||||
|
||||
const apiUrl = "http://165.140.240.203:3000/api";
|
||||
const apiKey = "hellovpn123";
|
||||
|
||||
const possiblePaths = [
|
||||
"/", "/v1", "/servers", "/status", "/vpn", "/health", "/ping",
|
||||
"/nodes", "/list", "/connect", "/config", "/create", "/createConfig",
|
||||
"/check", "/organizations", "/users"
|
||||
];
|
||||
|
||||
async function testPaths() {
|
||||
for (const path of possiblePaths) {
|
||||
try {
|
||||
const res = await axios.get(`${apiUrl}${path}`, {
|
||||
headers: { "x-api-key": apiKey },
|
||||
timeout: 3000
|
||||
});
|
||||
console.log(`✅ ${path} → ${res.status} ${res.statusText}`);
|
||||
console.log("Response:", res.data);
|
||||
} catch (err) {
|
||||
if (err.response) {
|
||||
console.log(`❌ ${path} → ${err.response.status}`);
|
||||
} else {
|
||||
console.log(`⚠️ ${path} → No response`);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
testPaths();
|
||||
|
|
@ -0,0 +1,297 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en" data-theme="light">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>DocVA | Login</title>
|
||||
|
||||
<style>
|
||||
:root {
|
||||
--color-bg-light: #ffffff;
|
||||
--color-bg-dark: #121212;
|
||||
--color-card-light: #ffffff;
|
||||
--color-card-dark: #1e1e1e;
|
||||
--color-text-light: #1a1a1a;
|
||||
--color-text-dark: #f5f5f5;
|
||||
--color-muted-light: #777;
|
||||
--color-muted-dark: #aaa;
|
||||
--color-primary: #0d0b57;
|
||||
--color-secondary: #2b8efc;
|
||||
--color-input-light: #f5f5f5;
|
||||
--color-input-dark: #2a2a2a;
|
||||
--radius: 14px;
|
||||
}
|
||||
|
||||
[data-theme="dark"] {
|
||||
--color-bg: var(--color-bg-dark);
|
||||
--color-card: var(--color-card-dark);
|
||||
--color-text: var(--color-text-dark);
|
||||
--color-muted: var(--color-muted-dark);
|
||||
--color-input: var(--color-input-dark);
|
||||
}
|
||||
|
||||
[data-theme="light"] {
|
||||
--color-bg: var(--color-bg-light);
|
||||
--color-card: var(--color-card-light);
|
||||
--color-text: var(--color-text-light);
|
||||
--color-muted: var(--color-muted-light);
|
||||
--color-input: var(--color-input-light);
|
||||
}
|
||||
|
||||
body {
|
||||
margin: 0;
|
||||
font-family: "Inter", sans-serif;
|
||||
background-color: var(--color-bg);
|
||||
color: var(--color-text);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
height: 100vh;
|
||||
transition: background-color 0.3s ease, color 0.3s ease;
|
||||
}
|
||||
|
||||
.logo {
|
||||
text-align: center;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.logo img {
|
||||
width: 170px;
|
||||
height: auto;
|
||||
}
|
||||
|
||||
.logo h1 {
|
||||
margin: 10px 0 2px 0;
|
||||
font-size: 2.3em;
|
||||
font-weight: 700;
|
||||
color: var(--color-primary);
|
||||
}
|
||||
|
||||
.logo p {
|
||||
color: var(--color-muted);
|
||||
font-size: 0.9em;
|
||||
letter-spacing: 0.05em;
|
||||
}
|
||||
|
||||
.login-card {
|
||||
background-color: var(--color-card);
|
||||
border-radius: var(--radius);
|
||||
padding: 18px 40px 35px 40px;
|
||||
/* width: 30%; */
|
||||
/* max-width: 410px; */
|
||||
width: 320px;
|
||||
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
|
||||
text-align: center;
|
||||
transition: background-color 0.3s ease;
|
||||
}
|
||||
|
||||
.login-card h2 {
|
||||
margin-bottom: 25px;
|
||||
color: var(--color-muted);
|
||||
font-weight: 500;
|
||||
font-size: 0.95em;
|
||||
}
|
||||
|
||||
input {
|
||||
width: calc(100% - 28px);
|
||||
padding: 12px 14px;
|
||||
margin-bottom: 18px;
|
||||
border: none;
|
||||
border-radius: 10px;
|
||||
background-color: var(--color-input);
|
||||
color: var(--color-text);
|
||||
font-size: 0.9em;
|
||||
}
|
||||
|
||||
input:focus {
|
||||
outline: 2px solid var(--color-secondary);
|
||||
}
|
||||
|
||||
.forgot {
|
||||
display: block;
|
||||
text-align: right;
|
||||
font-size: 0.8em;
|
||||
color: var(--color-muted);
|
||||
text-decoration: none;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.forgot:hover {
|
||||
color: var(--color-secondary);
|
||||
}
|
||||
|
||||
.btn {
|
||||
width: 100%;
|
||||
padding: 12px;
|
||||
border: none;
|
||||
border-radius: 10px;
|
||||
cursor: pointer;
|
||||
font-weight: 600;
|
||||
transition: background-color 0.3s ease;
|
||||
}
|
||||
|
||||
.btn-primary {
|
||||
background-color: var(--color-primary);
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.btn-primary:hover {
|
||||
background-color: #0a0848;
|
||||
}
|
||||
|
||||
.btn-secondary {
|
||||
background-color: transparent;
|
||||
border: 1.5px solid #ccc;
|
||||
color: var(--color-text);
|
||||
}
|
||||
|
||||
.btn-secondary:hover {
|
||||
border-color: var(--color-secondary);
|
||||
color: var(--color-secondary);
|
||||
}
|
||||
|
||||
.divider {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
text-align: center;
|
||||
color: var(--color-muted);
|
||||
margin: 18px 0;
|
||||
font-size: 0.85em;
|
||||
}
|
||||
|
||||
.divider::before,
|
||||
.divider::after {
|
||||
content: "";
|
||||
flex: 1;
|
||||
border-bottom: 1px solid #ccc;
|
||||
}
|
||||
|
||||
.divider:not(:empty)::before {
|
||||
margin-right: 0.75em;
|
||||
}
|
||||
|
||||
.divider:not(:empty)::after {
|
||||
margin-left: 0.75em;
|
||||
}
|
||||
|
||||
.theme-toggle {
|
||||
position: absolute;
|
||||
top: 20px;
|
||||
right: 20px;
|
||||
cursor: pointer;
|
||||
font-size: 0.9em;
|
||||
color: var(--color-muted);
|
||||
background: none;
|
||||
border: none;
|
||||
outline: none;
|
||||
transition: color 0.2s ease;
|
||||
}
|
||||
|
||||
.theme-toggle:hover {
|
||||
color: var(--color-secondary);
|
||||
}
|
||||
|
||||
@media (max-width: 480px) {
|
||||
.login-card {
|
||||
width: 280px;
|
||||
padding: 25px;
|
||||
}
|
||||
|
||||
.logo img {
|
||||
width: 100px;
|
||||
}
|
||||
|
||||
.logo h1 {
|
||||
font-size: 1.8em;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div class="logo">
|
||||
<img src="/public/images/logo-white-vertical.svg" alt="DocVA Logo" />
|
||||
<!-- <h1>DocVA</h1>
|
||||
<p>VIRTUAL ASSISTANTS FOR DOCTORS</p> -->
|
||||
</div>
|
||||
|
||||
<div class="login-card">
|
||||
<h2>Log in to your account to continue</h2>
|
||||
|
||||
<form>
|
||||
<input type="email" name="email" placeholder="Enter your email address *" required />
|
||||
<input type="password" name="password" placeholder="Enter your password *" required />
|
||||
<a href="/client/forgot-password" class="forgot">Forgot password?</a>
|
||||
|
||||
<button type="submit" class="btn btn-primary">🔒 Log in using password</button>
|
||||
|
||||
<div class="divider">OR</div>
|
||||
|
||||
<button type="button" class="btn btn-secondary"># Log in with Email Code</button>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
const root = document.documentElement;
|
||||
|
||||
function setTheme(theme) {
|
||||
root.setAttribute("data-theme", theme);
|
||||
}
|
||||
|
||||
function getSystemTheme() {
|
||||
return window.matchMedia("(prefers-color-scheme: dark)").matches
|
||||
? "dark"
|
||||
: "light";
|
||||
}
|
||||
|
||||
setTheme(getSystemTheme());
|
||||
|
||||
document.querySelector("form").addEventListener("submit", async (e) => {
|
||||
e.preventDefault(); // prevent page reload
|
||||
|
||||
const email = e.target.email.value.trim();
|
||||
const password = e.target.password.value.trim();
|
||||
|
||||
if (!email || !password) {
|
||||
alert("Please enter both email and password");
|
||||
return;
|
||||
}
|
||||
const userDetails = {
|
||||
email,
|
||||
password,
|
||||
};
|
||||
try {
|
||||
const res = await fetch("/api/v1/client/login", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify({"userDetails": userDetails}),
|
||||
});
|
||||
|
||||
const data = await res.json();
|
||||
|
||||
if (!res.ok) {
|
||||
throw new Error(data.message || "Login failed");
|
||||
}
|
||||
|
||||
if (data.token) {
|
||||
// 🟢 Save token
|
||||
localStorage.setItem("authToken", data.token);
|
||||
|
||||
// 🟢 Redirect
|
||||
window.location.href = "/client/dashboard";
|
||||
} else {
|
||||
alert("No token received. Please try again.");
|
||||
}
|
||||
} catch (err) {
|
||||
console.error("❌ Login error:", err);
|
||||
alert(err.message || "Something went wrong while logging in");
|
||||
}
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
|
|
@ -0,0 +1,193 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>DocVA | Reset Password</title>
|
||||
|
||||
<style>
|
||||
:root[data-theme="light"] {
|
||||
--bg: #ffffff;
|
||||
--text: #111827;
|
||||
--card-bg: #ffffff;
|
||||
--border: #e5e7eb;
|
||||
--btn-bg: #0a0a8f;
|
||||
--btn-text: #ffffff;
|
||||
}
|
||||
|
||||
:root[data-theme="dark"] {
|
||||
--bg: #121212;
|
||||
--text: #f9fafb;
|
||||
--card-bg: #1e1e1e;
|
||||
--border: #334155;
|
||||
--btn-bg: #3b82f6;
|
||||
--btn-text: #ffffff;
|
||||
}
|
||||
|
||||
body {
|
||||
background-color: var(--bg);
|
||||
color: var(--text);
|
||||
font-family: "Inter", sans-serif;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
height: 100vh;
|
||||
margin: 0;
|
||||
transition: background-color 0.3s, color 0.3s;
|
||||
}
|
||||
|
||||
.container {
|
||||
text-align: center;
|
||||
width: 100%;
|
||||
max-width: 380px;
|
||||
}
|
||||
|
||||
.logo {
|
||||
width: 170px;
|
||||
margin-bottom: 1.5rem;
|
||||
transition: opacity 0.3s;
|
||||
}
|
||||
|
||||
.card {
|
||||
background: var(--card-bg);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 12px;
|
||||
padding: 2rem;
|
||||
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
|
||||
transition: background 0.3s, border-color 0.3s;
|
||||
}
|
||||
|
||||
h2 {
|
||||
font-size: 1rem;
|
||||
font-weight: 500;
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
|
||||
input {
|
||||
box-sizing: border-box;
|
||||
width: 100%;
|
||||
padding: 0.8rem;
|
||||
margin-bottom: 1.2rem;
|
||||
border-radius: 8px;
|
||||
border: 1px solid var(--border);
|
||||
background: #fff;
|
||||
color: #111;
|
||||
font-size: 0.9rem;
|
||||
transition: border 0.3s;
|
||||
}
|
||||
|
||||
:root[data-theme="dark"] input {
|
||||
background: #0f172a;
|
||||
color: #fff;
|
||||
border: 1px solid #475569;
|
||||
}
|
||||
|
||||
button {
|
||||
width: 100%;
|
||||
background: var(--btn-bg);
|
||||
color: var(--btn-text);
|
||||
border: none;
|
||||
padding: 0.8rem;
|
||||
border-radius: 8px;
|
||||
font-size: 0.95rem;
|
||||
cursor: pointer;
|
||||
transition: opacity 0.3s;
|
||||
}
|
||||
|
||||
button:hover {
|
||||
opacity: 0.9;
|
||||
}
|
||||
|
||||
a {
|
||||
display: block;
|
||||
margin-top: 1rem;
|
||||
font-size: 0.85rem;
|
||||
color: var(--text);
|
||||
text-decoration: none;
|
||||
opacity: 0.8;
|
||||
}
|
||||
|
||||
a:hover {
|
||||
opacity: 1;
|
||||
text-decoration: underline;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div class="container">
|
||||
<img id="logo" class="logo" src="/public/images/logo-colored-vertical.svg" alt="DocVA Logo" />
|
||||
<form class="card">
|
||||
<h2>Reset your password</h2>
|
||||
<input type="email" placeholder="Enter your email address*" required />
|
||||
<button type="submit">Send password reset code</button>
|
||||
<a href="#">Go back to login</a>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
(function () {
|
||||
const prefersDark = window.matchMedia("(prefers-color-scheme: dark)");
|
||||
const logo = document.getElementById("logo");
|
||||
|
||||
function applyTheme(isDark) {
|
||||
const theme = isDark ? "dark" : "light";
|
||||
document.documentElement.setAttribute("data-theme", theme);
|
||||
logo.src = isDark ? "/public/images/logo-white-vertical.svg" : "/public/images/logo-colored-vertical.svg";
|
||||
}
|
||||
|
||||
// Initial set
|
||||
applyTheme(prefersDark.matches);
|
||||
|
||||
// Watch for changes
|
||||
prefersDark.addEventListener("change", (e) => applyTheme(e.matches));
|
||||
})();
|
||||
|
||||
|
||||
document.addEventListener("DOMContentLoaded", () => {
|
||||
const form = document.querySelector(".card"); // assuming .card wraps your form elements
|
||||
const emailInput = form.querySelector("input[type='email']");
|
||||
const button = form.querySelector("button");
|
||||
|
||||
form.addEventListener("submit", async (e) => {
|
||||
e.preventDefault();
|
||||
|
||||
const email = emailInput.value.trim();
|
||||
if (!email) {
|
||||
alert("Please enter your email address.");
|
||||
return;
|
||||
}
|
||||
|
||||
button.disabled = true;
|
||||
button.textContent = "Sending...";
|
||||
|
||||
try {
|
||||
const response = await fetch("/api/v1/client/forgot-password", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify({ email }),
|
||||
});
|
||||
|
||||
const data = await response.json();
|
||||
|
||||
if (response.ok) {
|
||||
window.location.href = "/client/login"; // Redirect to reset password page
|
||||
} else {
|
||||
alert("❌ " + (data.message || "Failed to send reset link."));
|
||||
}
|
||||
} catch (err) {
|
||||
console.error("Error:", err);
|
||||
alert("Something went wrong. Please try again later.");
|
||||
} finally {
|
||||
button.disabled = false;
|
||||
button.textContent = "Send password reset code";
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
|
|
@ -0,0 +1,143 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<title>Live Screen Feed</title>
|
||||
<style>
|
||||
* {
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
body {
|
||||
margin: 0;
|
||||
display: flex;
|
||||
height: 100vh;
|
||||
background: #111;
|
||||
color: #fff;
|
||||
font-family: 'Inter', sans-serif;
|
||||
}
|
||||
|
||||
.sidebar {
|
||||
width: 280px;
|
||||
background: #1b1b1b;
|
||||
border-right: 1px solid #333;
|
||||
overflow-y: auto;
|
||||
padding: 10px;
|
||||
}
|
||||
|
||||
.app {
|
||||
background: #222;
|
||||
border: 1px solid #333;
|
||||
border-radius: 8px;
|
||||
padding: 10px 12px;
|
||||
margin-bottom: 8px;
|
||||
cursor: pointer;
|
||||
transition: background 0.3s ease;
|
||||
word-break: break-word;
|
||||
}
|
||||
|
||||
.app:hover {
|
||||
background: #333;
|
||||
}
|
||||
|
||||
.app.active {
|
||||
background: #6C63FF;
|
||||
color: white;
|
||||
}
|
||||
|
||||
.content {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
overflow: hidden;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
h2 {
|
||||
margin-bottom: 12px;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
img {
|
||||
width: 90%;
|
||||
max-width: 900px;
|
||||
border: 2px solid #555;
|
||||
border-radius: 10px;
|
||||
object-fit: contain;
|
||||
}
|
||||
|
||||
.no-image {
|
||||
font-size: 14px;
|
||||
color: #888;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div class="sidebar">
|
||||
<h3>Visible Apps</h3>
|
||||
<div id="appsList"></div>
|
||||
</div>
|
||||
|
||||
<div class="content">
|
||||
<h2 id="selectedAppTitle">Select an app to view</h2>
|
||||
<img id="liveImage" src="" alt="Waiting for image..." class="no-image" />
|
||||
</div>
|
||||
|
||||
<script src="/socket.io/socket.io.js"></script>
|
||||
<script>
|
||||
const clientId = "691311fece83c986eb8a4e89";
|
||||
const socket = io({
|
||||
auth: {
|
||||
token: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjY5MTQ2NTFkODM2NDZhOTAwN2EzNDI4MCIsImVtYWlsIjoiYmhhZ3dhbi5yQGhpY2dsb2JhbHNvbHV0aW9ucy5jb20iLCJuYW1lIjoiYmhhZ3dhbiIsImlhdCI6MTc2Mjk0ODk3NSwiZXhwIjoxNzYzMDM1Mzc1fQ.WvmTvfOf8DvbqKsbvfyzda1ClP8qfllKFeJINtU6mnE",
|
||||
userType: "client",
|
||||
projectId: "<%= projectId %>"
|
||||
},
|
||||
});
|
||||
|
||||
socket.emit("register", { role: "client", id: clientId, projectId: "<%= projectId %>" });
|
||||
|
||||
const appsList = document.getElementById("appsList");
|
||||
const liveImage = document.getElementById("liveImage");
|
||||
const selectedAppTitle = document.getElementById("selectedAppTitle");
|
||||
let currentApp = null;
|
||||
|
||||
// 🟢 Receive visible apps from client
|
||||
socket.on("receiveVisibleApps", (apps) => {
|
||||
appsList.innerHTML = "";
|
||||
if (!apps?.length) {
|
||||
appsList.innerHTML = "<p>No visible apps</p>";
|
||||
return;
|
||||
}
|
||||
|
||||
apps.forEach(app => {
|
||||
const div = document.createElement("div");
|
||||
div.classList.add("app");
|
||||
div.textContent = app.name || "Unnamed App";
|
||||
div.onclick = () => {
|
||||
document.querySelectorAll(".app").forEach(el => el.classList.remove("active"));
|
||||
div.classList.add("active");
|
||||
currentApp = app.name;
|
||||
selectedAppTitle.textContent = app.name;
|
||||
|
||||
// 🟠 Tell server which app VA wants to monitor
|
||||
socket.emit("selectApp", { appTitle: app.name, clientId });
|
||||
};
|
||||
appsList.appendChild(div);
|
||||
});
|
||||
});
|
||||
|
||||
// 🟣 Receive images only for the selected app
|
||||
socket.on("receiveImage", (base64, title) => {
|
||||
if (currentApp && title === currentApp) {
|
||||
liveImage.src = base64;
|
||||
liveImage.classList.remove("no-image");
|
||||
}
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
Loading…
Reference in New Issue