Bug Resolve

This commit is contained in:
=bhagwanSingh 2025-12-09 19:15:26 +05:30
parent bc98edcb4b
commit 0ef8d60060
22 changed files with 64 additions and 43 deletions

View File

@ -767,7 +767,7 @@ async function submitForm() {
nextStep(6);
setTimeout(() => {
window.location.href = '/client/login';
window.location.href = '/';
}, 1000);
} else {
// Handle server errors

View File

@ -175,7 +175,7 @@ async function update_client(req, res) {
return res.status(500).json({
success: false,
message: "Internal Server Error"
message: error.message
});
}
}

View File

@ -1,6 +1,7 @@
import bcrypt from "bcrypt";
import jwt from "jsonwebtoken";
import { ClientModel } from "../../models/vaModel.js";
import { ClientModel, VAModel } from "../../models/vaModel.js";
import { va_timesheet_adjustment_function } from "../va/vaTimesheetAdjustment/vaTimesheetAdjustment.controller.js";
// Login VA
async function va_login_client(req, res) {
@ -13,8 +14,17 @@ async function va_login_client(req, res) {
return res.status(400).json({ success: false, message: "Please provide email and password" });
}
let isVa = false;
// Find user by email
const user = await ClientModel.findOne({ "userDetails.email": userDetails.email });
let user = await ClientModel.findOne({ "userDetails.email": userDetails.email });
const vaUser = await VAModel.findOne({ "userDetails.email": userDetails.email });
if (vaUser) {
isVa = true
user = vaUser
}
if (!user) {
return res.status(404).json({ success: false, message: "Invalid credentials" });
}
@ -49,6 +59,7 @@ async function va_login_client(req, res) {
id: user._id,
email: user.userDetails.email,
name: user.userDetails.firstName,
userType: isVa ? "VA" : "CLIENT",
},
process.env.JWT_SECRET_REFRESH_TOKEN || "DocTrackerSecretKeyRefreshToken",
{ expiresIn: "30d" }
@ -69,6 +80,7 @@ async function va_login_client(req, res) {
name: user.userDetails.firstName,
email: user.userDetails.email,
},
userType: isVa ? "VA" : "CLIENT",
});
} catch (error) {
console.error("va_client_login_register error:", error);

View File

@ -56,7 +56,7 @@ async function delete_project_sf(req, res) {
// 2. Remove project from all assigned VAs' projectIds arrays
if (vaAssigned.length > 0) {
const vaResult = await VAModel.updateMany(
{ _id: { $in: vaAssigned } },
{ _id: { $in: vaAssigned.vaId } },
{ $pull: { projectIds: projectObjectId } }
);
deletionSummary.vasUpdated = vaResult.modifiedCount;

View File

@ -5,7 +5,7 @@ import { VAModel } from "../../../models/vaModel.js";
// Register a new VA
async function va_profile_update_callback(req, res) {
try {
const sf_token = req.headers.sf_token;
const sf_token = req.headers["x-auth-token"];
const accessToken = req.headers.token;
let vaUser;

View File

@ -11,7 +11,7 @@ function formatHMS(ms) {
async function va_projects_report_function(req, res) {
try {
const sf_token = req.headers.sf_token;
const sf_token = req.headers["x-auth-token"];
let vaId;
let vaUser;
let vaEmail;

View File

@ -3,7 +3,7 @@ import { VAModel, ProjectModel, LoggedModel } from "../../../models/vaModel.js";
async function va_timesheet_summary_function(req, res) {
try {
const sf_token = req.headers.sf_token;
const sf_token = req.headers["x-auth-token"];
let vaId;
let vaUser;
let vaEmail;

View File

@ -28,7 +28,7 @@ async function va_tips_manage_function(req, res) {
const createdTip = await TipsModel.create(newTip);
const salesforceUrl = `${process.env.SF_DOCTRACKER_API_URL}services/apexrest/docva/api/va-tips`;
const sfData = {
"id": createdTip._id.toString(),
"vaId": createdTip.vaId.toString(),

View File

@ -4,7 +4,7 @@ import logger from "../config/logger.js";
async function authValidator(req, res, next) {
try {
const sf_token = req.headers.sf_token;
const sf_token = req.headers["x-auth-token"];
if (sf_token) {
const { vaId } = req.params;
if(vaId) req.body.vaId = vaId;
@ -51,7 +51,7 @@ async function authValidator(req, res, next) {
async function clientAuthValidator(req, res, next) {
try {
const sf_token = req.headers.sf_token;
const sf_token = req.headers["x-auth-token"];
if (sf_token) {
next();

View File

@ -121,6 +121,7 @@ app.get('/health', (req, res) => {
app.get("/client/login", (req, res) => {
res.render("client_login")
})
app.get("/client/forgot-password", (req, res) => {
res.render("forgot_password")
})
@ -498,11 +499,19 @@ io.on("connection", (socket) => {
});
app.get("/", (req, res) => {
res.render("client_login")
})
app.get("/forgot-password", (req, res) => {
res.render("forgot_password")
})
app.get("/heath", () => {
if(Math.round(Math.random()) === 1) {
return res.status(200).json({"success": true, "message": "Server is Healthy"})
if (Math.round(Math.random()) === 1) {
return res.status(200).json({ "success": true, "message": "Server is Healthy" })
} else {
return res.status(403).json({"success": false, "message": "Server is not Healthy"})
return res.status(403).json({ "success": false, "message": "Server is not Healthy" })
}
})

View File

@ -63,7 +63,7 @@ class PasswordResetService {
logger.info(`Password reset token created for ${userType}: ${email}`);
return {
success: true,
message: "If the email exists, a reset link has been sent"
message: "Email sent successfully. Please check your inbox."
};
} catch (error) {

View File

@ -18,7 +18,7 @@
if (userType === 'client') {
forgotPasswordUrl = '/client/forgot-password';
loginUrl = '/client/login';
loginUrl = '/';
}
%>
<a href="<%= forgotPasswordUrl %>" class="btn btn-primary" style="margin-bottom:8px;">Request New Reset Link</a>

View File

@ -36,7 +36,7 @@
<%
let backToLoginUrl = `${process.env.FRONTEND_URL}/login`;
if (userType === 'client') {
backToLoginUrl = '/client/login';
backToLoginUrl = '/';
}
%>
<a href="<%= backToLoginUrl %>" class="small-link">Back to Login</a>

View File

@ -15,7 +15,7 @@
<%
let loginUrl = `${process.env.FRONTEND_URL}/login`;
if (userType === 'client') {
loginUrl = '/client/login';
loginUrl = '/';
}
%>
<a href="<%= loginUrl %>" class="btn btn-primary">Go to Login</a>

View File

@ -252,7 +252,7 @@
async function fetchWithAuth(url, options = {}) {
const token = getAuthToken();
if (!token) {
window.location.href = '/client/login';
window.location.href = '/';
return;
}
@ -268,7 +268,7 @@
if (response.status === 401) {
localStorage.removeItem('knoptpq');
localStorage.removeItem('refreshToken');
window.location.href = '/client/login';
window.location.href = '/';
return;
}
@ -287,7 +287,7 @@
// Clear local storage and redirect
localStorage.removeItem('knoptpq');
localStorage.removeItem('refreshToken');
window.location.href = '/client/login';
window.location.href = '/';
}
}

View File

@ -245,7 +245,7 @@
async function fetchWithAuth(url, options = {}) {
const token = getAuthToken();
if (!token) {
window.location.href = '/client/login';
window.location.href = '/';
return;
}
@ -263,7 +263,7 @@
if (response.status === 401) {
localStorage.removeItem('knoptpq');
localStorage.removeItem('refreshToken');
window.location.href = '/client/login';
window.location.href = '/';
return;
}
@ -282,7 +282,7 @@
// Clear local storage and redirect
localStorage.removeItem('knoptpq');
localStorage.removeItem('refreshToken');
window.location.href = '/client/login';
window.location.href = '/';
}
}

View File

@ -234,7 +234,7 @@
async function fetchWithAuth(url, options = {}) {
const token = getAuthToken();
if (!token) {
window.location.href = '/client/login';
window.location.href = '/';
return;
}
@ -250,7 +250,7 @@
if (response.status === 401) {
localStorage.removeItem('knoptpq');
localStorage.removeItem('refreshToken');
window.location.href = '/client/login';
window.location.href = '/';
return;
}
@ -265,7 +265,7 @@
} finally {
localStorage.removeItem('knoptpq');
localStorage.removeItem('refreshToken');
window.location.href = '/client/login';
window.location.href = '/';
}
}

View File

@ -216,7 +216,7 @@
async function fetchWithAuth(url, options = {}) {
const token = getAuthToken();
if (!token) {
window.location.href = '/client/login';
window.location.href = '/';
return;
}
@ -232,7 +232,7 @@
if (response.status === 401) {
localStorage.removeItem('knoptpq');
localStorage.removeItem('refreshToken');
window.location.href = '/client/login';
window.location.href = '/';
return;
}
@ -251,7 +251,7 @@
// Clear local storage and redirect
localStorage.removeItem('knoptpq');
localStorage.removeItem('refreshToken');
window.location.href = '/client/login';
window.location.href = '/';
}
}

View File

@ -253,7 +253,7 @@
async function fetchWithAuth(url, options = {}) {
const token = getAuthToken();
if (!token) {
window.location.href = '/client/login';
window.location.href = '/';
return;
}
@ -269,7 +269,7 @@
if (response.status === 401) {
localStorage.removeItem('knoptpq');
localStorage.removeItem('refreshToken');
window.location.href = '/client/login';
window.location.href = '/';
return;
}
@ -288,7 +288,7 @@
// Clear local storage and redirect
localStorage.removeItem('knoptpq');
localStorage.removeItem('refreshToken');
window.location.href = '/client/login';
window.location.href = '/';
}
}

View File

@ -222,7 +222,7 @@
<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>
<a href="/forgot-password" class="forgot">Forgot password?</a>
<button type="submit" class="btn btn-primary">Log in using password</button>
@ -282,12 +282,12 @@
}
if (data.success) {
// 🟢 Save token
localStorage.setItem("knoptpq", data.accessToken);
// localStorage.setItem("refreshToken", data.refreshToken);
// 🟢 Redirect
window.location.href = "/client/dashboard";
if(data.userType === "CLIENT") {
localStorage.setItem("knoptpq", data.accessToken);
window.location.href = "/client/dashboard";
} else {
window.location.href = "/download-tracker";
}
} else {
alert("No token received. Please try again.");
}

View File

@ -122,7 +122,7 @@
<h2>Reset your password</h2>
<input type="email" placeholder="Enter your email address*" required />
<button type="submit">Send password reset code</button>
<a href="/client/login">Go back to login</a>
<a href="/">Go back to login</a>
</form>
</div>
@ -181,7 +181,7 @@
if (response.ok) {
if(response.success) {
if(confirm('Please Check your mail inbox for password reset link')) {
window.location.href = "/client/login"; // Redirect to reset password page
window.location.href = "/"; // Redirect to reset password page
// console.log(response)
}
} else {

View File

@ -275,7 +275,7 @@
socket.on("authError", () => {
socket.disconnect();
localStorage.removeItem("knoptpq");
window.location.href = "/client/login";
window.location.href = "/";
});
/* Receive images */