This commit is contained in:
parent
dcda1629ff
commit
599779ee8e
|
|
@ -1,3 +1,4 @@
|
|||
node_modules
|
||||
logs
|
||||
.env
|
||||
.env
|
||||
public/builds
|
||||
|
|
@ -1,17 +1,17 @@
|
|||
import PasswordResetRepository from "../repository/passwordReset.repository.js";
|
||||
import PasswordResetService from "../services/passwordReset.service.js";
|
||||
import EmailService from "../services/email.service.js";
|
||||
// import EmailService from "../services/email.service.js";
|
||||
import logger from "../config/logger.js";
|
||||
|
||||
const passwordResetService = new PasswordResetService(
|
||||
new PasswordResetRepository(),
|
||||
new EmailService({
|
||||
host: process.env.SMTP_HOST,
|
||||
port: process.env.SMTP_PORT,
|
||||
user: process.env.SMTP_USER,
|
||||
pass: process.env.SMTP_PASS,
|
||||
from: process.env.EMAIL_FROM,
|
||||
})
|
||||
// new EmailService({
|
||||
// host: process.env.SMTP_HOST,
|
||||
// port: process.env.SMTP_PORT,
|
||||
// user: process.env.SMTP_USER,
|
||||
// pass: process.env.SMTP_PASS,
|
||||
// from: process.env.EMAIL_FROM,
|
||||
// })
|
||||
);
|
||||
|
||||
// VA: Request password reset
|
||||
|
|
|
|||
|
|
@ -189,47 +189,47 @@ async function va_project_log_callback(req, res) {
|
|||
|
||||
const createdLog = await LoggedModel.create({ loggedType: type, vaId, vaEmail, projectId })
|
||||
// console.log(createdLog)
|
||||
// try {
|
||||
// const salesforceUrl = `${process.env.SF_DOCTRACKER_API_URL}services/apexrest/docva/api/va-project-log`;
|
||||
// const sfData = {
|
||||
// "_id": createdLog._id,
|
||||
// "loggedType": type,
|
||||
// "vaId": vaId,
|
||||
// "vaEmail": vaEmail,
|
||||
// "projectId": projectId,
|
||||
// "time": createdLog.time,
|
||||
// }
|
||||
try {
|
||||
const salesforceUrl = `${process.env.SF_DOCTRACKER_API_URL}services/apexrest/docva/api/va-project-log`;
|
||||
const sfData = {
|
||||
"_id": createdLog._id,
|
||||
"loggedType": type,
|
||||
"vaId": vaId,
|
||||
"vaEmail": vaEmail,
|
||||
"projectId": projectId,
|
||||
"time": createdLog.time,
|
||||
}
|
||||
|
||||
// const response = await fetch(salesforceUrl, {
|
||||
// method: 'POST',
|
||||
// headers: {
|
||||
// 'Content-Type': 'application/json',
|
||||
// // Add any required headers for Salesforce authentication
|
||||
// // 'Authorization': 'Bearer ' + process.env.SF_ACCESS_TOKEN
|
||||
// },
|
||||
// body: JSON.stringify(sfData)
|
||||
// });
|
||||
const response = await fetch(salesforceUrl, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
// Add any required headers for Salesforce authentication
|
||||
// 'Authorization': 'Bearer ' + process.env.SF_ACCESS_TOKEN
|
||||
},
|
||||
body: JSON.stringify(sfData)
|
||||
});
|
||||
|
||||
// if (!response.ok) {
|
||||
// const errorText = await response.text();
|
||||
// throw new Error(`Salesforce API responded with status ${response.status}: ${errorText}`);
|
||||
// }
|
||||
if (!response.ok) {
|
||||
const errorText = await response.text();
|
||||
throw new Error(`Salesforce API responded with status ${response.status}: ${errorText}`);
|
||||
}
|
||||
|
||||
// const result = await response.json();
|
||||
// // console.log("✅ Successfully synced VA data to Salesforce:", result);
|
||||
const result = await response.json();
|
||||
// console.log("✅ Successfully synced VA data to Salesforce:", result);
|
||||
|
||||
// res.status(201).json({ success: true, message: `${type} Successfully`, logId: createdLog._id, SyncSalesforce: result });
|
||||
// } catch (error) {
|
||||
// console.error("Failed to sync with Salesforce:", error.message);
|
||||
// console.log(error)
|
||||
res.status(201).json({ success: true, message: `${type} Successfully`, logId: createdLog._id, SyncSalesforce: result });
|
||||
} catch (error) {
|
||||
console.error("Failed to sync with Salesforce:", error.message);
|
||||
console.log(error)
|
||||
|
||||
// // Create a custom error to distinguish Salesforce errors
|
||||
// const salesforceError = new Error(`Salesforce sync failed: ${error.message}`);
|
||||
// salesforceError.isSalesforceError = true;
|
||||
// throw salesforceError;
|
||||
// }
|
||||
// Create a custom error to distinguish Salesforce errors
|
||||
const salesforceError = new Error(`Salesforce sync failed: ${error.message}`);
|
||||
salesforceError.isSalesforceError = true;
|
||||
throw salesforceError;
|
||||
}
|
||||
|
||||
return res.status(201).send({ success: true, message: `${type} Successfully`, logId: createdLog._id });
|
||||
// return res.status(201).send({ success: true, message: `${type} Successfully`, logId: createdLog._id });
|
||||
|
||||
} catch (error) {
|
||||
return res.status(500).send("Internal Server Error");
|
||||
|
|
|
|||
|
|
@ -2,25 +2,26 @@ import jwt from "jsonwebtoken";
|
|||
import bcrypt from "bcrypt";
|
||||
import { VAModel, ClientModel } from "../models/vaModel.js";
|
||||
import logger from "../config/logger.js";
|
||||
import axios from "axios";
|
||||
|
||||
class PasswordResetService {
|
||||
constructor(passwordResetRepository, emailService) {
|
||||
constructor(passwordResetRepository) {
|
||||
this.passwordResetRepository = passwordResetRepository;
|
||||
this.emailService = emailService;
|
||||
// this.emailService = emailService;
|
||||
}
|
||||
|
||||
async requestPasswordReset(email, userType) {
|
||||
try {
|
||||
// Determine which model to use
|
||||
const userModel = userType === 'va' ? VAModel : ClientModel;
|
||||
|
||||
|
||||
// Check if user exists
|
||||
const user = await userModel.findOne({ "userDetails.email": email.toLowerCase() });
|
||||
if (!user) {
|
||||
logger.info(`Password reset requested for non-existent ${userType}: ${email}`);
|
||||
return {
|
||||
success: false,
|
||||
message: "Email not recognized. Please sign up to continue."
|
||||
return {
|
||||
success: false,
|
||||
message: "Email not recognized. Please sign up to continue."
|
||||
};
|
||||
}
|
||||
|
||||
|
|
@ -29,7 +30,7 @@ class PasswordResetService {
|
|||
|
||||
// Generate JWT token
|
||||
const token = jwt.sign(
|
||||
{
|
||||
{
|
||||
email: email.toLowerCase(),
|
||||
userType: userType,
|
||||
type: 'password_reset'
|
||||
|
|
@ -60,9 +61,9 @@ class PasswordResetService {
|
|||
await this.sendResetEmail(email, resetLink, userType);
|
||||
|
||||
logger.info(`Password reset token created for ${userType}: ${email}`);
|
||||
return {
|
||||
success: true,
|
||||
message: "If the email exists, a reset link has been sent"
|
||||
return {
|
||||
success: true,
|
||||
message: "If the email exists, a reset link has been sent"
|
||||
};
|
||||
|
||||
} catch (error) {
|
||||
|
|
@ -92,10 +93,10 @@ class PasswordResetService {
|
|||
return { valid: false, message: "Invalid or expired token" };
|
||||
}
|
||||
|
||||
return {
|
||||
valid: true,
|
||||
return {
|
||||
valid: true,
|
||||
email: decoded.email,
|
||||
userType: decoded.userType
|
||||
userType: decoded.userType
|
||||
};
|
||||
|
||||
} catch (error) {
|
||||
|
|
@ -129,7 +130,7 @@ class PasswordResetService {
|
|||
const userModel = userType === 'va' ? VAModel : ClientModel;
|
||||
|
||||
// Check if user exists and has matching token
|
||||
const user = await userModel.findOne({
|
||||
const user = await userModel.findOne({
|
||||
"userDetails.email": decoded.email,
|
||||
passwordResetToken: token
|
||||
});
|
||||
|
|
@ -150,12 +151,12 @@ class PasswordResetService {
|
|||
await resetRecord.save();
|
||||
|
||||
// Send confirmation email
|
||||
await this.sendPasswordChangedEmail(decoded.email, userType);
|
||||
// await this.sendPasswordChangedEmail(decoded.email, userType);
|
||||
|
||||
logger.info(`Password successfully reset for ${userType}: ${decoded.email}`);
|
||||
return {
|
||||
success: true,
|
||||
message: "Password has been reset successfully"
|
||||
return {
|
||||
success: true,
|
||||
message: "Password has been reset successfully"
|
||||
};
|
||||
|
||||
} catch (error) {
|
||||
|
|
@ -166,16 +167,15 @@ class PasswordResetService {
|
|||
|
||||
async sendResetEmail(email, resetLink, userType) {
|
||||
try {
|
||||
const userTypeText = userType === 'va' ? 'Virtual Assistant' : 'Client';
|
||||
|
||||
const emailData = {
|
||||
to: email,
|
||||
subject: `${userTypeText} - Password Reset Request`,
|
||||
html: this.generateResetEmailTemplate(resetLink, userTypeText),
|
||||
};
|
||||
const userTypeText = userType === 'va' ? 'VA' : 'CLIENT';
|
||||
|
||||
await this.emailService.sendEmail(emailData);
|
||||
logger.info(`Password reset email sent to ${userType}: ${email}`);
|
||||
await axios.post(`${process.env.SF_DOCTRACKER_API_URL}services/apexrest/docva/api/forgot-password`, {
|
||||
data: {
|
||||
email: email,
|
||||
url: resetLink,
|
||||
userType: userTypeText
|
||||
}
|
||||
});
|
||||
|
||||
} catch (error) {
|
||||
logger.error(`PasswordReset Service - sendResetEmail error for ${userType}: ${error.message}`);
|
||||
|
|
@ -186,7 +186,7 @@ class PasswordResetService {
|
|||
async sendPasswordChangedEmail(email, userType) {
|
||||
try {
|
||||
const userTypeText = userType === 'va' ? 'Virtual Assistant' : 'Client';
|
||||
|
||||
|
||||
const emailData = {
|
||||
to: email,
|
||||
subject: `${userTypeText} - Password Changed Successfully`,
|
||||
|
|
|
|||
|
|
@ -139,7 +139,7 @@
|
|||
<script>
|
||||
const osButtons = document.querySelectorAll(".os-btn");
|
||||
const downloadBtn = document.getElementById("downloadBtn");
|
||||
const version = "<%= version || '3.2.1' %>";
|
||||
const version = "<%= version || '1.1.1' %>";
|
||||
|
||||
let selectedOS = "windows";
|
||||
|
||||
|
|
@ -171,7 +171,13 @@
|
|||
|
||||
// -------- Download --------
|
||||
downloadBtn.addEventListener("click", () => {
|
||||
window.location.href = `/download-file?os=${selectedOS}`;
|
||||
|
||||
const link = document.createElement("a");
|
||||
link.href = `/public/builds/build-1.1.1.1/windows/VA Tracker-Setup-1.1.1.exe`;
|
||||
link.setAttribute("download", "");
|
||||
link.click()
|
||||
|
||||
// window.location.href = ``;
|
||||
});
|
||||
</script>
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue